Skip to content

Commit

Permalink
Clean up nvtx macros (#15038)
Browse files Browse the repository at this point in the history
This PR includes several cleanups for the cudf nvtx wrappers:

- Removed the unused `NVTX3_FUNC_RANGE` macro
- Fixed a typo in the doc
- Added an example in the `cudf::thread_range` doc
- Updated the `NVTX` section in the developer guide doc

Authors:
  - Yunsong Wang (https://github.com/PointKernel)

Approvers:
  - Karthikeyan (https://github.com/karthikeyann)
  - Nghia Truong (https://github.com/ttnghia)

URL: #15038
  • Loading branch information
PointKernel authored Feb 21, 2024
1 parent 8a226eb commit 63e9040
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
12 changes: 8 additions & 4 deletions cpp/doxygen/developer_guide/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,14 @@ defaults.
## NVTX Ranges

In order to aid in performance optimization and debugging, all compute intensive libcudf functions
should have a corresponding NVTX range. libcudf has a convenience macro `CUDF_FUNC_RANGE()` that
automatically annotates the lifetime of the enclosing function and uses the function's name as
the name of the NVTX range. For more information about NVTX, see
[here](https://github.com/NVIDIA/NVTX/tree/dev/c).
should have a corresponding NVTX range. Choose between `CUDF_FUNC_RANGE` or `cudf::thread_range`
for declaring NVTX ranges in the current scope:
- Use the `CUDF_FUNC_RANGE()` macro if you want to use the name of the function as the name of the
NVTX range
- Use `cudf::thread_range rng{"custom_name"};` to provide a custom name for the current scope's
NVTX range

For more information about NVTX, see [here](https://github.com/NVIDIA/NVTX/tree/dev/c).

## Input/Output Style

Expand Down
28 changes: 2 additions & 26 deletions cpp/include/cudf/detail/nvtx/nvtx3.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1901,33 +1901,9 @@ inline void mark(event_attributes const& attr) noexcept
*
* @param[in] D Type containing `name` member used to identify the
* `domain` to which the `registered_message` belongs. Else,
* `domain::global` to indicate that the global NVTX domain should be used.
* `domain::global` to indicate that the global NVTX domain should be used.
*/
#define NVTX3_FUNC_RANGE_IN(D) \
static ::nvtx3::registered_message<D> const nvtx3_func_name__{__func__}; \
static ::nvtx3::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \
[[maybe_unused]] ::nvtx3::domain_thread_range<D> const nvtx3_range__{nvtx3_func_attr__};

/**
* @brief Convenience macro for generating a range in the global domain from the
* lifetime of a function.
*
* This macro is useful for generating an NVTX range in the global domain from
* the entry point of a function to its exit. It is intended to be the first
* line of the function.
*
* Constructs a static `registered_message` using the name of the immediately
* enclosing function returned by `__func__` and constructs a
* `nvtx3::thread_range` using the registered function name as the range's
* message.
*
* Example:
* ```
* void foo(...){
* NVTX3_FUNC_RANGE(); // Range begins on entry to foo()
* // do stuff
* ...
* } // Range ends on return from foo()
* ```
*/
#define NVTX3_FUNC_RANGE() NVTX3_FUNC_RANGE_IN(::nvtx3::domain::global)
12 changes: 11 additions & 1 deletion cpp/include/cudf/detail/nvtx/ranges.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,16 @@ struct libcudf_domain {

/**
* @brief Alias for an NVTX range in the libcudf domain.
*
* Customizes an NVTX range with the given input.
*
* Example:
* ```
* void some_function(){
* cudf::thread_range rng{"custom_name"}; // Customizes range name
* ...
* }
* ```
*/
using thread_range = ::nvtx3::domain_thread_range<libcudf_domain>;

Expand Down

0 comments on commit 63e9040

Please sign in to comment.