Repository navigation
Expand file tree
/
Copy pathnvtx.cpp
More file actions
70 lines (51 loc) · 1.75 KB
/
Copy pathnvtx.cpp
File metadata and controls
70 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause
#include <cuda_runtime.h>
#include <ginkgo/config.hpp>
#ifdef GKO_LEGACY_NVTX
#include <nvToolsExt.h>
#else
#include <nvtx3/nvToolsExt.h>
#endif
#include <ginkgo/core/log/profiler_hook.hpp>
namespace gko {
namespace log {
// "GKO" in ASCII to avoid collision with other application's categories
constexpr static uint32 category_magic_offset = 0x676B6FU;
void init_nvtx()
{
#define NAMED_CATEGORY(_name) \
nvtxNameCategory(static_cast<uint32>(profile_event_category::_name) + \
category_magic_offset, \
"gko::" #_name)
NAMED_CATEGORY(memory);
NAMED_CATEGORY(operation);
NAMED_CATEGORY(object);
NAMED_CATEGORY(linop);
NAMED_CATEGORY(factory);
NAMED_CATEGORY(solver);
NAMED_CATEGORY(criterion);
NAMED_CATEGORY(user);
NAMED_CATEGORY(internal);
#undef NAMED_CATEGORY
}
std::function<void(const char*, profile_event_category)> begin_nvtx_fn(
uint32_t color_argb)
{
return [color_argb](const char* name, profile_event_category category) {
nvtxEventAttributes_t attr{};
attr.version = NVTX_VERSION;
attr.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
attr.category = static_cast<uint32>(category) + category_magic_offset;
attr.colorType = NVTX_COLOR_ARGB;
attr.color = color_argb;
attr.payloadType = NVTX_PAYLOAD_UNKNOWN;
attr.messageType = NVTX_MESSAGE_TYPE_ASCII;
attr.message.ascii = name;
nvtxRangePushEx(&attr);
};
}
void end_nvtx(const char* name, profile_event_category) { nvtxRangePop(); }
} // namespace log
} // namespace gko