pytorch
786f9460 - [Profiler] Add glue layer to reduce the use of `#ifdef USE_KINETO` in the profiler code. (#69798)

Commit
2 years ago
[Profiler] Add glue layer to reduce the use of `#ifdef USE_KINETO` in the profiler code. (#69798) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/69798 One of the major sources of complexity in `profiler_kineto.cpp` is that kineto may or may not be available. The code (including the types) follows two related but often distict codepaths, and large sections may or may not be `#ifdef`'d out. Optimizing such code which preserving correctness is quite difficult; at one point I realized that I had broken the non-Kineto case, because moving work into the finalize step runs astray of a very large `#ifdef` around the finalize logic. In order to make optimization more tractable, I gathered all of the calls to Kineto APIs and isolated them in the `kineto_shim.h/.cpp` files: the header allows callers to pretend as though Kineto is always available (mostly), and the cpp file hides most of the horrible `#ifdef`s so they don't pollute the main profiler code. Test Plan: Unit tests. Reviewed By: aaronenyeshi Differential Revision: D32690568 fbshipit-source-id: 9a276654ef0ff9d40817c2f88f95071683f150c5
Author
Taylor Robie
Parents
Loading