Skip to content

Commit

Permalink
Replaced nvtx_manager with NvtxManager
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Feb 21, 2025
1 parent 842603f commit 198fb60
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions cpp/include/kvikio/nvtx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using nvtx_registered_string_type = nvtx3::registered_string_in<libkvikio_domain
} \
}
#define KVIKIO_NVTX_SCOPED_RANGE_IMPL_2(message, payload) \
KVIKIO_NVTX_SCOPED_RANGE_IMPL_3(message, payload, kvikio::nvtx_manager::default_color())
KVIKIO_NVTX_SCOPED_RANGE_IMPL_3(message, payload, kvikio::NvtxManager::default_color())
#define KVIKIO_NVTX_SCOPED_RANGE_SELECTOR(_1, _2, _3, NAME, ...) NAME
#define KVIKIO_NVTX_SCOPED_RANGE_IMPL(...) \
KVIKIO_NVTX_SCOPED_RANGE_SELECTOR( \
Expand All @@ -85,9 +85,9 @@ using nvtx_color_type = int;
/**
* @brief Utility singleton class for NVTX annotation.
*/
class nvtx_manager {
class NvtxManager {
public:
static nvtx_manager& instance() noexcept;
static NvtxManager& instance() noexcept;

/**
* @brief Return the default color.
Expand All @@ -114,13 +114,13 @@ class nvtx_manager {
*/
static void rename_current_thread(std::string_view new_name) noexcept;

nvtx_manager(nvtx_manager const&) = delete;
nvtx_manager& operator=(nvtx_manager const&) = delete;
nvtx_manager(nvtx_manager&&) = delete;
nvtx_manager& operator=(nvtx_manager&&) = delete;
NvtxManager(NvtxManager const&) = delete;
NvtxManager& operator=(NvtxManager const&) = delete;
NvtxManager(NvtxManager&&) = delete;
NvtxManager& operator=(NvtxManager&&) = delete;

private:
nvtx_manager() = default;
NvtxManager() = default;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/kvikio/parallel_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ inline const std::pair<const nvtx_color_type&, std::uint64_t> get_next_color_and
{
static std::atomic_uint64_t call_counter{1ull};
auto call_idx = call_counter.fetch_add(1ull, std::memory_order_relaxed);
auto& nvtx_color = nvtx_manager::get_color_by_index(call_idx);
auto& nvtx_color = NvtxManager::get_color_by_index(call_idx);
return {nvtx_color, call_idx};
}

Expand All @@ -57,7 +57,7 @@ std::future<std::size_t> submit_task(F op,
std::size_t file_offset,
std::size_t devPtr_offset,
std::uint64_t nvtx_payload = 0ull,
nvtx_color_type nvtx_color = nvtx_manager::default_color())
nvtx_color_type nvtx_color = NvtxManager::default_color())
{
return defaults::thread_pool().submit_task([=] {
KVIKIO_NVTX_SCOPED_RANGE("task", nvtx_payload, nvtx_color);
Expand Down Expand Up @@ -87,7 +87,7 @@ std::future<std::size_t> parallel_io(F op,
std::size_t task_size,
std::size_t devPtr_offset,
std::uint64_t call_idx = 0,
nvtx_color_type nvtx_color = nvtx_manager::default_color())
nvtx_color_type nvtx_color = NvtxManager::default_color())
{
if (task_size == 0) { throw std::invalid_argument("`task_size` cannot be zero"); }

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/kvikio/threadpool_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class thread_pool_wrapper : public pool_type {

private:
inline static std::function<void()> worker_thread_init_func{[] {
KVIKIO_NVTX_SCOPED_RANGE("worker thread init", 0, nvtx_manager::default_color());
KVIKIO_NVTX_SCOPED_RANGE("worker thread init", 0, NvtxManager::default_color());
// Rename the worker thread in the thread pool to improve clarity from nsys-ui.
// Note: This NVTX feature is currently not supported by nsys-ui.
nvtx_manager::rename_current_thread("thread pool");
NvtxManager::rename_current_thread("thread pool");
}};
};

Expand Down
10 changes: 5 additions & 5 deletions cpp/src/nvtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

namespace kvikio {

nvtx_manager& nvtx_manager::instance() noexcept
NvtxManager& NvtxManager::instance() noexcept
{
static nvtx_manager _instance;
static NvtxManager _instance;
return _instance;
}

const nvtx_color_type& nvtx_manager::default_color() noexcept
const nvtx_color_type& NvtxManager::default_color() noexcept
{
#ifdef KVIKIO_CUDA_FOUND
static nvtx_color_type default_color{nvtx3::argb{0, 255, 255, 255}};
Expand All @@ -43,7 +43,7 @@ const nvtx_color_type& nvtx_manager::default_color() noexcept
#endif
}

const nvtx_color_type& nvtx_manager::get_color_by_index(std::uint64_t idx) noexcept
const nvtx_color_type& NvtxManager::get_color_by_index(std::uint64_t idx) noexcept
{
#ifdef KVIKIO_CUDA_FOUND
constexpr std::size_t num_color{16};
Expand Down Expand Up @@ -72,7 +72,7 @@ const nvtx_color_type& nvtx_manager::get_color_by_index(std::uint64_t idx) noexc
#endif
}

void nvtx_manager::rename_current_thread(std::string_view new_name) noexcept
void NvtxManager::rename_current_thread(std::string_view new_name) noexcept
{
#ifdef KVIKIO_CUDA_FOUND
auto tid = syscall(SYS_gettid);
Expand Down

0 comments on commit 198fb60

Please sign in to comment.