SIRIUS 7.5.0
Electronic structure library and applications
nvtx_profiler.hpp
1#ifndef __NVTX_PROFILER_HPP__
2#define __NVTX_PROFILER_HPP__
3
4#if defined(SIRIUS_CUDA_NVTX)
5
6#include <unordered_map>
7#include "nvToolsExt.h"
8
9namespace sirius {
10
11namespace acc {
12
13namespace nvtxprofiler {
14
15class Timer {
16public:
17 void start(std::string const &str) {
18 timers_[str] = nvtxRangeStartA(str.c_str());
19 }
20
21 void stop(std::string const &str) {
22 auto result = timers_.find(str);
23 if (result == timers_.end()) return;
24 nvtxRangeEnd(result->second);
25 timers_.erase(result);
26 }
27
28private:
29 std::unordered_map<std::string, nvtxRangeId_t> timers_;
30};
31
32class ScopedTiming {
33public:
34 ScopedTiming(std::string identifier, Timer &timer) :
35 identifier_(identifier), timer_(timer) {
36 timer.start(identifier_);
37 }
38
39 ScopedTiming(const ScopedTiming&) = delete;
40 ScopedTiming(ScopedTiming&&) = delete;
41 auto operator=(const ScopedTiming&) -> ScopedTiming& = delete;
42 auto operator=(ScopedTiming &&) -> ScopedTiming& = delete;
43
44 ~ScopedTiming() {
45 timer_.stop(identifier_);
46 }
47
48private:
49 std::string identifier_;
50 Timer& timer_;
51};
52
53}
54}
55} // namespace sirius
56#endif
57#endif
Namespace of the SIRIUS library.
Definition: sirius.f90:5