Skip to content

Commit

Permalink
Add Thrust changes from BabelStream
Browse files Browse the repository at this point in the history
Fix Thrust model compatibility with nvcc
  • Loading branch information
tom91136 committed Nov 27, 2023
1 parent 7b26b03 commit 3d93e15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/thrust/fasten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ template <size_t PPWI> class IMPL_CLS final : public Bude<PPWI> {
transforms_0 = transforms_0.data(), transforms_1 = transforms_1.data(), transforms_2 = transforms_2.data(), //
transforms_3 = transforms_3.data(), transforms_4 = transforms_4.data(), transforms_5 = transforms_5.data(), //
forcefield = forcefield.data(), //
energies = energies.data()] __device__ __host__(const int group) {
energies = energies.data()] __device__
#ifndef __NVCC__
// otherwise, we get "init-captures are not allowed for extended __host__ __device__"
__host__
#endif
(const int group) {
std::array<std::array<Vec4<float>, 3>, PPWI> transform = {};
std::array<float, PPWI> etot = {};

Expand Down
17 changes: 11 additions & 6 deletions src/thrust/model.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ macro(setup)
# see CUDA.cmake, we're only adding a few Thrust related libraries here

if (POLICY CMP0104)
cmake_policy(SET CMP0104 OLD)
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 --expt-relaxed-constexpr -forward-unknown-to-host-compiler -arch=${CUDA_ARCH}" ${CUDA_EXTRA_FLAGS})
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "--expt-extended-lambda --expt-relaxed-constexpr" ${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
Expand All @@ -52,7 +53,11 @@ macro(setup)
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)
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 ()
Expand All @@ -63,12 +68,12 @@ macro(setup)
message(STATUS "Using Thrust backend: ${BACKEND}")

# this creates the interface that we can link to
thrust_create_target(Thrust HOST CPP DEVICE ${BACKEND})
thrust_create_target(Thrust${BACKEND}
HOST CPP
DEVICE ${BACKEND})
set_source_files_properties(${IMPL_SOURCES} PROPERTIES LANGUAGE CUDA)
message(WARNING ${IMPL_SOURCES})
register_link_library(Thrust${BACKEND})


register_link_library(Thrust)
elseif (${THRUST_IMPL} STREQUAL "ROCM")
if (SDK_DIR)
find_package(rocprim REQUIRED CONFIG PATHS ${SDK_DIR}/rocprim)
Expand Down

0 comments on commit 3d93e15

Please sign in to comment.