torch-mlir/frontends/pytorch/csrc/builder
Sean Silva c837dbb077 Properly import the entire torch::jit::CompilationUnit
This primarily unlocks proper handling of free functions (that is,
functions that are not methods of any torch.nn.Module).

Recommended review order:
- `ivalue_importer.cpp` + `ivalue_import/functions*.py`
- `GlobalizeObjectGraph.cpp` + test case
- misc other stuff

The `torch::jit::CompilationUnit` is basically a backing store or
"context" holding all the possible functions in the program. The
previous code was not explicitly accessing this data structure, since it
just imported the `torch::jit::Function`'s that it saw attached to
methods.

Subtly, any time a TorchScript module called into a free function, the
free function gets incorporated into the torch::jit::CompilationUnit,
but doesn't show up anywhere when dumping the module, except in the
curious pattern:

```
%5 : Function = prim::Constant[name="adaptive_avg_pool2d"]()
%6 : Tensor = prim::CallFunction(%5, %input.1, %4)
```

That is, calls are indirect calls, and are accessed via `prim::Constant`
materializing a function object. Even stranger, the `name` attribute here
doesn't really even tell the full story -- it doesn't correspond to
anything. It turns out that the c10::FunctionType itself actually holds
a pointer to the `torch::jit::Function` in the compilation unit
directly (so there is actually no indirection in prim::CallMethod,
because any two values of the same FunctionType call the same
function!). E.g. when converting the IR to bytecode, the "name" is
ignored [code link](1d6bd15790/torch/csrc/jit/runtime/interpreter.cpp (L937)).
We do import `prim::CallFunction` as a `std.call_indirect` though
because it's more braindead to do it that way (it gets canonicalized to
a direct call easily).
2021-03-01 12:08:01 -08:00
..
acap_dispatch.cpp adapt acap_dispatch to latest pytorch nightly ("1.9.0.dev20210215+cpu") 2021-02-18 11:13:29 -08:00
acap_dispatch.h Make torch_mlir compatible with binary PyTorch installations. 2020-12-14 09:51:00 -08:00
class_annotator.cpp Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
class_annotator.h Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
debug.cpp Delete old PyTorch 1.3 type dispatch oriented code paths. 2020-11-12 22:27:05 -08:00
debug.h Delete old PyTorch 1.3 type dispatch oriented code paths. 2020-11-12 22:27:05 -08:00
func_builder.cpp Add support for prim::GetAttr/SetAttr/CallMethod/If 2021-02-04 17:01:47 -08:00
func_builder.h Add initial TorchScript module importer 2021-01-28 11:55:17 -08:00
graph_importer.cpp Properly import the entire torch::jit::CompilationUnit 2021-03-01 12:08:01 -08:00
graph_importer.h Add support for prim::GetAttr/SetAttr/CallMethod/If 2021-02-04 17:01:47 -08:00
ivalue_importer.cpp Properly import the entire torch::jit::CompilationUnit 2021-03-01 12:08:01 -08:00
ivalue_importer.h Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
mlir_utils.h Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
module_builder.cpp Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
module_builder.h Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
node_importer.cpp Properly import the entire torch::jit::CompilationUnit 2021-03-01 12:08:01 -08:00
node_importer.h Add support for prim::GetAttr/SetAttr/CallMethod/If 2021-02-04 17:01:47 -08:00
op_builder.cpp Add prim::Print and fix prim::CallMethod 2021-02-10 15:15:56 -08:00
op_builder.h Add prim::Print and fix prim::CallMethod 2021-02-10 15:15:56 -08:00
python_bindings.cpp Add ability to annotate TorchScript classes. 2021-02-25 11:28:34 -08:00
torch_to_mlir_utils.cpp Properly import the entire torch::jit::CompilationUnit 2021-03-01 12:08:01 -08:00
torch_to_mlir_utils.h Properly import the entire torch::jit::CompilationUnit 2021-03-01 12:08:01 -08:00