1 | #include <sstream> |
---|---|
2 | |
3 | #include <c10/util/irange.h> |
4 | #include <torch/csrc/itt_wrapper.h> |
5 | #include <torch/csrc/profiler/stubs/base.h> |
6 | |
7 | namespace torch { |
8 | namespace profiler { |
9 | namespace impl { |
10 | namespace { |
11 | |
12 | struct ITTMethods : public ProfilerStubs { |
13 | void record(int* device, ProfilerEventStub* event, int64_t* cpu_ns) |
14 | const override {} |
15 | |
16 | float elapsed(const ProfilerEventStub* event, const ProfilerEventStub* event2) |
17 | const override { |
18 | return 0; |
19 | } |
20 | |
21 | void mark(const char* name) const override { |
22 | // NOLINTNEXTLINE(cppcoreguidelines-init-variables) |
23 | torch::profiler::itt_mark(name); |
24 | } |
25 | |
26 | void rangePush(const char* name) const override { |
27 | // NOLINTNEXTLINE(cppcoreguidelines-init-variables) |
28 | torch::profiler::itt_range_push(name); |
29 | } |
30 | |
31 | void rangePop() const override { |
32 | torch::profiler::itt_range_pop(); |
33 | } |
34 | |
35 | void onEachDevice(std::function<void(int)> op) const override {} |
36 | |
37 | void synchronize() const override {} |
38 | |
39 | bool enabled() const override { |
40 | return true; |
41 | } |
42 | }; |
43 | |
44 | struct RegisterITTMethods { |
45 | RegisterITTMethods() { |
46 | static ITTMethods methods; |
47 | registerITTMethods(&methods); |
48 | } |
49 | }; |
50 | RegisterITTMethods reg; |
51 | |
52 | } // namespace |
53 | } // namespace impl |
54 | } // namespace profiler |
55 | } // namespace torch |
56 |