ATen
ATen copied to clipboard
Generate _out functions from native function specifications
Here's a sketch of how this could work for a new native function foo with a Tensor arg self:
-
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 anoutput: True
argument. -
In base Type, we generate
foo(self)
andfoo_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 tofoo_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. -
In Function, we generate
foo
andfoo_out
that call the corresponding Type variants after inferring the type. -
In Method, we only generate
foo
that calls the Type variant foofoo
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.