Skip to content

Commit

Permalink
Test combined internal/user-side use of NVTX (#1690)
Browse files Browse the repository at this point in the history
Co-authored-by: Allison Piper <[email protected]>
  • Loading branch information
bernhardmgruber and alliepiper authored May 3, 2024
1 parent db61c65 commit c910b16
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cub/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ option(METAL_BUILD_EXAMPLES OFF)
option(METAL_BUILD_TESTS OFF)
CPMAddPackage("gh:brunocodutra/[email protected]")

CPMAddPackage(
NAME NVTX
GITHUB_REPOSITORY NVIDIA/NVTX
GIT_TAG release-v3
DOWNLOAD_ONLY
SYSTEM
)
include("${NVTX_SOURCE_DIR}/c/nvtxImportedTargets.cmake")

find_package(CUDAToolkit)

set(curand_default OFF)
Expand Down Expand Up @@ -280,6 +289,10 @@ function(cub_add_test target_name_var test_name test_src cub_target launcher_id)
target_include_directories(${test_target} PRIVATE "${CUB_SOURCE_DIR}/test")
target_compile_definitions(${test_target} PRIVATE CUB_DETAIL_DEBUG_ENABLE_SYNC)

if ("${test_target}" MATCHES "nvtx_in_usercode")
target_link_libraries(${test_target} nvtx3-cpp)
endif()

if (CUB_IN_THRUST)
thrust_fix_clang_nvcc_build_for(${test_target})
endif()
Expand Down
22 changes: 22 additions & 0 deletions cub/test/test_nvtx_in_usercode.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <cub/device/device_for.cuh> // internal include of NVTX

#include <thrust/iterator/counting_iterator.h>

#include <nvtx3/nvtx3.hpp> // user-side include of NVTX, retrieved elsewhere

struct Op
{
_CCCL_HOST_DEVICE void operator()(int i) const
{
printf("%d\n", i);
}
};

int main()
{
nvtx3::scoped_range range("user-range"); // user-side use of NVTX

thrust::counting_iterator<int> it{0};
cub::DeviceFor::ForEach(it, it + 16, Op{}); // internal use of NVTX
cudaDeviceSynchronize();
}

0 comments on commit c910b16

Please sign in to comment.