ATen icon indicating copy to clipboard operation
ATen copied to clipboard

Generate _out functions from native function specifications

Open gchanan opened this issue 6 years ago • 2 comments

gchanan avatar Nov 01 '17 21:11 gchanan

Here's a sketch of how this could work for a new native function foo with a Tensor arg self:

  1. User writes the "foo_out" variant as a native function, e.g.: at::native::foo_out(Tensor &result, const Tensor &self); and marks result as an output: True argument.

  2. In base Type, we generate foo(self) and foo_out(result, self). foo_out just calls the native function, e.g. at::native::foo_out(result, self). foo generates a result Tensor of the correct type and passes it on to foo_out. I'm not sure if this result Tensor generation works today in the base type or we have to do the generation in the derived type; the current _out variants are generated in the derived type, but it's unclear to me if that's necessary or just because the non-out variants are also generated in the derived type (and they share code) so it's the most straightforward.

  3. In Function, we generate foo and foo_out that call the corresponding Type variants after inferring the type.

  4. In Method, we only generate foo that calls the Type variant foo foo

gchanan avatar Nov 02 '17 15:11 gchanan

BTW, I'm not sure we want to implement this fully yet; Variables don't currently work with the _out variants (none of ATen-backed, C++ pure, python pure autograd functions), so we probably want to figure out a story there before implementing this fully.

gchanan avatar Nov 02 '17 15:11 gchanan