Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
nvtx.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NVTX_H
19#define NVTX_H
20
21#include "realm/realm_config.h"
22
23#if __has_include(<nvtx3/nvtx3.hpp>)
24#include <nvtx3/nvtx3.hpp>
25#elif __has_include(<nvtx3/nvToolsExt.h>)
26#include <nvtx3/nvToolsExt.h>
27#else
28#error "Configuration failed to find suitable NVTX headers"
29#endif
30
31#include <map>
32#include <string>
33#include <vector>
34
35namespace Realm {
36
37 struct NvtxARGB {
38 constexpr NvtxARGB(uint8_t red_, uint8_t green_, uint8_t blue_,
39 uint8_t alpha_ = 0xFF) noexcept
40 : red{red_}
41 , green{green_}
42 , blue{blue_}
43 , alpha{alpha_}
44 {}
45 constexpr uint32_t to_uint(void) const
46 {
47 return uint32_t{alpha} << 24 | uint32_t{red} << 16 | uint32_t{green} << 8 |
48 uint32_t{blue};
49 }
50 uint8_t const red{};
51 uint8_t const green{};
52 uint8_t const blue{};
53 uint8_t const alpha{};
54 };
55
56 enum nvtx_color : uint32_t
57 {
58 white = NvtxARGB(255, 255, 255).to_uint(),
59 red = NvtxARGB(255, 0, 0).to_uint(),
60 green = NvtxARGB(0, 255, 0).to_uint(),
61 blue = NvtxARGB(0, 0, 255).to_uint(),
62 purple = NvtxARGB(128, 0, 128).to_uint(),
63 lawn_green = NvtxARGB(124, 252, 0).to_uint(),
64 cyan = NvtxARGB(0, 255, 255).to_uint(),
65 maroon = NvtxARGB(128, 0, 0).to_uint(),
66 navy = NvtxARGB(0, 0, 128).to_uint(),
67 magenta = NvtxARGB(255, 0, 255).to_uint(),
68 yellow = NvtxARGB(255, 255, 0).to_uint(),
69 gray = NvtxARGB(128, 128, 128).to_uint(),
70 teal = NvtxARGB(0, 128, 128).to_uint(),
71 olive = NvtxARGB(128, 128, 0).to_uint(),
72 };
73
74 struct NvtxCategory {
75 NvtxCategory(const std::string &category_name, uint32_t category_id, uint32_t color);
76 const std::string name;
77 nvtxEventAttributes_t nvtx_event;
78 };
79
81 nvtxScopedRange(NvtxCategory *category, char const *message, int32_t payload);
82 nvtxScopedRange(const std::string &name, char const *message, int32_t payload);
84 };
85
86 static constexpr uint32_t nvtx_proc_starting_category_id = 1000;
87
88 // called by each kernel thread to init thread local variables.
89 void init_nvtx_thread(const char *thread_name);
90
91 // called by RuntimeImpl::configure_from_command_line from the main thread to init nvtx
92 // and its thread local variables.
93 void init_nvtx(std::vector<std::string> &nvtx_modules);
94
95 // called by each kernel thread to delete thread local variables.
97
98 // called by RuntimeImpl::wait_for_shutdown from the main thread to finalize nvtx
99 // and delete its thread local variables.
100 void finalize_nvtx(void);
101
102 // TODO(@Wei Wu): template it wih type T for payload
103 void nvtx_range_push(NvtxCategory *category, const char *message,
104 uint32_t color = nvtx_color::white, int32_t payload = 0);
105
106 void nvtx_range_push(const std::string &name, const char *message,
107 uint32_t color = nvtx_color::white, int32_t payload = 0);
108
109 void nvtx_range_pop(void);
110
111 // TODO(@Wei Wu): template it wih type T for payload
112 nvtxRangeId_t nvtx_range_start(NvtxCategory *category, const char *message,
113 uint32_t color = nvtx_color::white, int32_t payload = 0);
114 nvtxRangeId_t nvtx_range_start(const std::string &name, const char *message,
115 uint32_t color = nvtx_color::white, int32_t payload = 0);
116
117 void nvtx_range_end(nvtxRangeId_t id);
118
119 // TODO(@Wei Wu): template it wih type T for payload
120 void nvtx_mark(NvtxCategory *category, const char *message,
121 uint32_t color = nvtx_color::white, int32_t payload = 0);
122 void nvtx_mark(const std::string &name, const char *message,
123 uint32_t color = nvtx_color::white, int32_t payload = 0);
124
125}; // namespace Realm
126
127#endif // NVTX_H
Definition activemsg.h:38
nvtxRangeId_t nvtx_range_start(NvtxCategory *category, const char *message, uint32_t color=nvtx_color::white, int32_t payload=0)
void finalize_nvtx(void)
nvtx_color
Definition nvtx.h:57
@ magenta
Definition nvtx.h:67
@ red
Definition nvtx.h:59
@ navy
Definition nvtx.h:66
@ lawn_green
Definition nvtx.h:63
@ green
Definition nvtx.h:60
@ white
Definition nvtx.h:58
@ yellow
Definition nvtx.h:68
@ cyan
Definition nvtx.h:64
@ gray
Definition nvtx.h:69
@ olive
Definition nvtx.h:71
@ blue
Definition nvtx.h:61
@ maroon
Definition nvtx.h:65
@ purple
Definition nvtx.h:62
@ teal
Definition nvtx.h:70
void nvtx_mark(NvtxCategory *category, const char *message, uint32_t color=nvtx_color::white, int32_t payload=0)
void finalize_nvtx_thread(void)
void init_nvtx(std::vector< std::string > &nvtx_modules)
void nvtx_range_pop(void)
void nvtx_range_end(nvtxRangeId_t id)
void nvtx_range_push(NvtxCategory *category, const char *message, uint32_t color=nvtx_color::white, int32_t payload=0)
void init_nvtx_thread(const char *thread_name)
Definition nvtx.h:37
uint8_t const blue
Definition nvtx.h:52
uint8_t const alpha
Definition nvtx.h:53
constexpr uint32_t to_uint(void) const
Definition nvtx.h:45
uint8_t const red
Definition nvtx.h:50
constexpr NvtxARGB(uint8_t red_, uint8_t green_, uint8_t blue_, uint8_t alpha_=0xFF) noexcept
Definition nvtx.h:38
uint8_t const green
Definition nvtx.h:51
Definition nvtx.h:74
nvtxEventAttributes_t nvtx_event
Definition nvtx.h:77
NvtxCategory(const std::string &category_name, uint32_t category_id, uint32_t color)
const std::string name
Definition nvtx.h:76
Definition nvtx.h:80
nvtxScopedRange(NvtxCategory *category, char const *message, int32_t payload)
nvtxScopedRange(const std::string &name, char const *message, int32_t payload)