-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NVTX ranges to all CUB algorithms
Fixes: #719 Co-authored-by: Michael Schellenberger Costa <[email protected]>
- Loading branch information
1 parent
ac49021
commit f9de904
Showing
17 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of the NVIDIA CORPORATION nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <cub/config.cuh> | ||
|
||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
# pragma GCC system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
# pragma clang system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
# pragma system_header | ||
#endif // no system header | ||
|
||
#if __has_include(<source_location> ) | ||
# include <source_location> | ||
#endif // __has_include(<source_location>) | ||
|
||
// NVTX documentation: https://nvidia.github.io/NVTX/ | ||
#include <cuda/std/optional> | ||
|
||
#include <nvtx3/nvToolsExt.h> | ||
|
||
CUB_NAMESPACE_BEGIN | ||
|
||
namespace detail | ||
{ | ||
struct NVTXGlobal | ||
{ | ||
nvtxDomainHandle_t domain; | ||
|
||
NVTXGlobal() | ||
{ | ||
domain = nvtxDomainCreate("CUB"); | ||
} | ||
|
||
~NVTXGlobal() | ||
{ | ||
nvtxDomainDestroy(domain); | ||
} | ||
}; | ||
|
||
// Triggers global setup of the NVTX domain for CUB. | ||
// TODO(bgruber): replace by an inline variable in C++17 | ||
auto& nvtxGlobal() { | ||
static NVTXGlobal g; | ||
return g; | ||
} | ||
|
||
// A scope guard to create an named NVTX range inside the CUB domain. | ||
struct NVTXGuard | ||
{ | ||
// FIXME(bgruber): _CCCL_DEVICE is only needed to make cuda::std::optional happy. | ||
|
||
CUB_RUNTIME_FUNCTION _CCCL_DEVICE NVTXGuard(const char* name) | ||
{ | ||
NV_IF_TARGET( | ||
NV_IS_HOST, | ||
// TODO(bgruber): documentation mentions a nvtxDomainRangePushA, but it does not exist | ||
nvtxEventAttributes_t eventAttrib{}; | ||
eventAttrib.version = NVTX_VERSION; | ||
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; | ||
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; | ||
eventAttrib.message.ascii = name; | ||
nvtxDomainRangePushEx(nvtxGlobal().domain, &eventAttrib);); | ||
} | ||
|
||
#ifdef __cpp_lib_source_location | ||
_CCCL_DEVICE NVTXGuard(const std::source_location& loc = std::source_location::current()) | ||
: NVTXGuard(loc.function_name()) | ||
{} | ||
#endif // __cpp_lib_source_location | ||
|
||
CUB_RUNTIME_FUNCTION _CCCL_DEVICE ~NVTXGuard() | ||
{ | ||
NV_IF_TARGET(NV_IS_HOST, nvtxDomainRangePop(nvtxGlobal().domain);); | ||
} | ||
}; | ||
} // namespace detail | ||
|
||
// Inserts a NVTX range starting here until the end of the current function scope | ||
// TODO(bgruber): replace this by NVTX3_FUNC_RANGE from <nvtx3/nvtx3.hpp>, when available. Wasn't available in CTK 12.4. | ||
#define CUB_NVTX_RANGE_SCOPE [[maybe_unused]] ::cub::detail::NVTXGuard youShallNotGuessThisVariableName(__func__) | ||
#define CUB_NVTX_RANGE_SCOPE_IF(condition) \ | ||
::cuda::std::optional<::cub::detail::NVTXGuard> youShallNotGuessThisVariableName; \ | ||
if (condition) \ | ||
youShallNotGuessThisVariableName.emplace(__func__); | ||
|
||
CUB_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.