-
Notifications
You must be signed in to change notification settings - Fork 123
Update Thrust to CCCL #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
|
||
register_flag_optional(THRUST_IMPL | ||
"Which Thrust implementation to use, supported options include: | ||
- CUDA (via https://github.com/NVIDIA/thrust) | ||
- CUDA (via https://github.com/NVIDIA/thrust or https://github.com/NVIDIA/CCCL) | ||
- ROCM (via https://github.com/ROCmSoftwarePlatform/rocThrust) | ||
" | ||
"CUDA") | ||
|
||
register_flag_optional(SDK_DIR | ||
"Path to the selected Thrust implementation (e.g `/opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/include` for NVHPC, `/opt/rocm` for ROCm)" | ||
"Path to the installation prefix for CCCL or Thrust (e.g `/opt/nvidia/hpc_sdk/Linux_x86_64/24.5/cuda/12.4/lib64/cmake` for NVHPC, or `/usr/local/cuda-12.5/lib64/cmake` for nvcc, or `/usr/local/cuda-11.4/include` for older nvcc, or `/opt/rocm` for ROCm)" | ||
"") | ||
|
||
register_flag_optional(BACKEND | ||
|
@@ -18,7 +18,7 @@ register_flag_optional(BACKEND | |
" | ||
"CUDA") | ||
|
||
register_flag_optional(MANAGED "Enabled managed memory mode." | ||
register_flag_optional(MANAGED "Enabled managed memory mode." | ||
"OFF") | ||
|
||
register_flag_optional(CMAKE_CUDA_COMPILER | ||
|
@@ -34,6 +34,9 @@ register_flag_optional(CUDA_EXTRA_FLAGS | |
"[THRUST_IMPL==CUDA] Additional CUDA flags passed to nvcc, this is appended after `CUDA_ARCH`" | ||
"") | ||
|
||
option(FETCH_CCCL "Fetch (download) the CCCL library. This uses CMake's FetchContent feature. | ||
Specify version by setting FETCH_CCCL_VERSION" OFF) | ||
set(FETCH_CCCL_VERSION "v2.4.0" CACHE STRING "Specify version of CCCL to use if FETCH_CCCL is ON") | ||
|
||
macro(setup) | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
@@ -42,44 +45,48 @@ macro(setup) | |
endif () | ||
|
||
if (${THRUST_IMPL} STREQUAL "CUDA") | ||
|
||
# see CUDA.cmake, we're only adding a few Thrust related libraries here | ||
|
||
if (POLICY CMP0104) | ||
cmake_policy(SET CMP0104 NEW) | ||
endif () | ||
|
||
set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH}) | ||
# add -forward-unknown-to-host-compiler for compatibility reasons | ||
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "--expt-extended-lambda " ${CUDA_EXTRA_FLAGS}) | ||
enable_language(CUDA) | ||
# CMake defaults to -O2 for CUDA at Release, let's wipe that and use the global RELEASE_FLAG | ||
# appended later | ||
# CMake defaults to -O2 for CUDA at Release, let's wipe that and use the global RELEASE_FLAG appended later | ||
wipe_gcc_style_optimisation_flags(CMAKE_CUDA_FLAGS_${BUILD_TYPE}) | ||
|
||
message(STATUS "NVCC flags: ${CMAKE_CUDA_FLAGS} ${CMAKE_CUDA_FLAGS_${BUILD_TYPE}}") | ||
|
||
|
||
# XXX NVHPC <= 21.9 has cub-config in `Linux_x86_64/21.9/cuda/11.4/include/cub/cmake` | ||
# XXX NVHPC >= 22.3 has cub-config in `Linux_x86_64/22.3/cuda/11.6/lib64/cmake/cub/` | ||
# same thing for thrust | ||
if (SDK_DIR) | ||
# CMake tries several subdirectories below SDK_DIR, see documentation: | ||
# https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure | ||
list(APPEND CMAKE_PREFIX_PATH ${SDK_DIR}) | ||
find_package(CUB REQUIRED CONFIG PATHS ${SDK_DIR}/cub) | ||
find_package(Thrust REQUIRED CONFIG PATHS ${SDK_DIR}/thrust) | ||
else () | ||
find_package(CUB REQUIRED CONFIG) | ||
find_package(Thrust REQUIRED CONFIG) | ||
endif () | ||
|
||
message(STATUS "Using Thrust backend: ${BACKEND}") | ||
|
||
# this creates the interface that we can link to | ||
thrust_create_target(Thrust${BACKEND} | ||
HOST CPP | ||
DEVICE ${BACKEND}) | ||
Comment on lines
-78
to
-80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines switch between the different Thrust backends, and this feature is lost in the new version. By default, CCCL uses the CUDA backend for Thrust, but it looks like BabelStream may want to use TBB or OMP. To keep this functionality, force-set the cache variable Force setting that variable tells the CCCL CMake package to use the desired device backend for the Also, using paths based off of The Finally, rather than manually checking
All together, you're looking at something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the review! I set As for handling CPM, I decided now to revert to FetchContent to just make the CMake setup simpler. Let me know if anything is still missing, thx! |
||
|
||
register_link_library(Thrust${BACKEND}) | ||
set(CCCL_THRUST_DEVICE_SYSTEM ${BACKEND} CACHE STRING "" FORCE) | ||
|
||
# fetch CCCL if user wants to | ||
if (FETCH_CCCL) | ||
FetchContent_Declare( | ||
CCCL | ||
GIT_REPOSITORY https://github.com/nvidia/cccl.git | ||
GIT_TAG "${FETCH_CCCL_VERSION}" | ||
) | ||
FetchContent_MakeAvailable(CCCL) | ||
register_link_library(CCCL::CCCL) | ||
else() | ||
# try to find CCCL locally | ||
find_package(CCCL CONFIG) | ||
if (CCCL_FOUND) | ||
register_link_library(CCCL::CCCL) | ||
else() | ||
# backup: find legacy projects separately | ||
message(WARNING "No CCCL found on your system. Trying Thrust and CUB legacy targets.") | ||
find_package(CUB REQUIRED CONFIG) | ||
find_package(Thrust REQUIRED CONFIG) | ||
thrust_create_target(Thrust${BACKEND} HOST CPP DEVICE ${BACKEND}) | ||
register_link_library(Thrust${BACKEND}) | ||
endif() | ||
endif() | ||
elseif (${THRUST_IMPL} STREQUAL "ROCM") | ||
if (SDK_DIR) | ||
find_package(rocprim REQUIRED CONFIG PATHS ${SDK_DIR}/rocprim) | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the motivation for pImpl? I don't think we've done this for any of the other models.
Implementations for each model should be representative of "best practice" in those models. Is this best practice for all Thrust codes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained in the header file,
thrust::device_vector
andthrust::universal_vector
cannot be used in a translation unit that is not compiled by a CUDA compiler, so they cannot be named inThrustStream.h
, since this is included byStreamModels.h
, which is included bymain.cpp
, which is not compiled bynvcc
.