pytorch/tools/code_analyzer
Jiakai Liu 3c042a6ab9 [pytorch][mobile] support for custom mobile build with dynamic dispatch (#34055)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/34055

Enable custom mobile build with dynamic dispatch for OSS build.

It calls a python util script to calculate transitive dependencies from
the op dependency graph and the list of used root ops, then pass the
result as the op registration whitelist to aten codegen, so that only
these used ops are registered and kept at link time.

For custom build with dynamic dispatch to work correctly, it's critical
to have the accurate list of used ops. Current assumption is that only
those ops referenced by TorchScript model are used. It works well if
client code doesn't call libtorch API (e.g.  tensor methods) directly;
otherwise the extra used ops need to be added to the whitelist manually,
as shown by the HACK in prepare_model.py.

Also, if JIT starts calling extra ops independent of specific model,
then the extra ops need to be added to the whitelist as well.

Verified the correctness of the whole process with MobileNetV2:
```
TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh
```

Test Plan: Imported from OSS

Reviewed By: bhosmer

Differential Revision: D20193327

Pulled By: ljk53

fbshipit-source-id: 9d369b8864856b098342aea79e0ac8eec04149aa
2020-03-03 19:25:16 -08:00
..
analyzer.cpp [pytorch] convert code analyzer to a binary (#33102) 2020-02-10 14:46:29 -08:00
build.sh [pytorch] convert code analyzer to a binary (#33102) 2020-02-10 14:46:29 -08:00
CMakeLists.txt [pytorch] convert code analyzer to a binary (#33102) 2020-02-10 14:46:29 -08:00
gen_transitive_deps.py [pytorch][mobile] support for custom mobile build with dynamic dispatch (#34055) 2020-03-03 19:25:16 -08:00
op_dependency.cpp [pytorch] change op dependency output to use double-quoted strings (#32464) 2020-01-24 15:27:28 -08:00
run_analyzer.sh [pytorch] update code analyzer script to cover new c10::Module::def API (#33975) 2020-02-29 10:29:45 -08:00