From e81f6c28895b590ba807d4c28d6d5e5c22702c19 Mon Sep 17 00:00:00 2001 From: Tom Lin Date: Tue, 13 Jun 2023 22:18:48 +0100 Subject: [PATCH 1/2] Fix RAJA > v0.14.1 compatibility --- src/raja/model.cmake | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/raja/model.cmake b/src/raja/model.cmake index b1e7750..eb4788c 100644 --- a/src/raja/model.cmake +++ b/src/raja/model.cmake @@ -8,6 +8,8 @@ register_flag_optional(RAJA_IN_TREE Make sure to use the release version of RAJA or clone RAJA recursively with submodules. Remember to append RAJA specific flags as well, for example: -DRAJA_IN_TREE=... -DENABLE_OPENMP=ON -DENABLE_CUDA=ON ... + For RAJA >= v2022.03.0, remember to use the RAJA prefixed CMake options: + -DRAJA_IN_TREE=... -DRAJA_ENABLE_OPENMP=ON -DRAJA_ENABLE_CUDA=ON ... See https://github.com/LLNL/RAJA/blob/08cbbafd2d21589ebf341f7275c229412d0fe903/CMakeLists.txt#L44 for all available options " "") @@ -20,7 +22,7 @@ register_flag_optional(TARGET CPU) register_flag_optional(CUDA_TOOLKIT_ROOT_DIR - "[TARGET==NVIDIA only] Path to the CUDA toolkit directory (e.g `/opt/cuda-11.2`) if the ENABLE_CUDA flag is specified for RAJA" "") + "[TARGET==NVIDIA only] Path to the CUDA toolkit directory (e.g `/opt/cuda-11.2`) if the RAJA_ENABLE_CUDA or ENABLE_CUDA flag is specified for RAJA" "") # XXX CMake 3.18 supports CMAKE_CUDA_ARCHITECTURES/CUDA_ARCHITECTURES but we support older CMakes register_flag_optional(CUDA_ARCH @@ -58,7 +60,20 @@ macro(setup) set(ENABLE_BENCHMARKS OFF CACHE BOOL "") set(ENABLE_CUDA ${ENABLE_CUDA} CACHE BOOL "" FORCE) - if (ENABLE_CUDA) + # RAJA >= v2022.03.0 switched to prefixed variables, we keep the legacy ones for backwards compatibiity + set(RAJA_ENABLE_TESTS OFF CACHE BOOL "") + set(RAJA_ENABLE_EXAMPLES OFF CACHE BOOL "") + set(RAJA_ENABLE_REPRODUCERS OFF CACHE BOOL "") + set(RAJA_ENABLE_EXERCISES OFF CACHE BOOL "") + set(RAJA_ENABLE_DOCUMENTATION OFF CACHE BOOL "") + set(RAJA_ENABLE_BENCHMARKS OFF CACHE BOOL "") + set(RAJA_ENABLE_CUDA ${RAJA_ENABLE_CUDA} CACHE BOOL "" FORCE) + + if (ENABLE_CUDA OR RAJA_ENABLE_CUDA) + + # RAJA still needs ENABLE_CUDA for internal use, so if either is on, assert both. + set(RAJA_ENABLE_CUDA ON) + set(ENABLE_CUDA ON) # XXX CMake 3.18 supports CMAKE_CUDA_ARCHITECTURES/CUDA_ARCHITECTURES but we support older CMakes if(POLICY CMP0104) @@ -70,6 +85,10 @@ macro(setup) set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "-forward-unknown-to-host-compiler -extended-lambda -arch=${CUDA_ARCH}" ${CUDA_EXTRA_FLAGS}) list(APPEND CMAKE_CUDA_FLAGS) + # See https://github.com/LLNL/RAJA/pull/1302 + # And https://github.com/LLNL/RAJA/pull/1339 + set(RAJA_ENABLE_VECTORIZATION OFF CACHE BOOL "") + message(STATUS "NVCC flags: ${CMAKE_CUDA_FLAGS}") endif () From 6d11c723826ae94b3de1fb346ee787c56f6fba4b Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Thu, 27 Jul 2023 13:46:23 +0100 Subject: [PATCH 2/2] Add support for Thrust managed memory Closes #143 --- CHANGELOG.md | 1 + src/thrust/ThrustStream.h | 10 ++++++++++ src/thrust/model.cmake | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b8aa1b..371e241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## Unreleased ### Added - Ability to build Kokkos and RAJA versions against existing packages. +- Thrust managed memory. ### Changed - RAJA CUDA CMake build issues resolved. diff --git a/src/thrust/ThrustStream.h b/src/thrust/ThrustStream.h index f87ace7..a2a4b72 100644 --- a/src/thrust/ThrustStream.h +++ b/src/thrust/ThrustStream.h @@ -8,7 +8,11 @@ #include #include +#if defined(MANAGED) +#include +#else #include +#endif #include "Stream.h" @@ -21,9 +25,15 @@ class ThrustStream : public Stream // Size of arrays int array_size; + #if defined(MANAGED) + thrust::universtal_vector a; + thrust::universtal_vector b; + thrust::universtal_vector c; + #else thrust::device_vector a; thrust::device_vector b; thrust::device_vector c; + #endif public: ThrustStream(const int, int); diff --git a/src/thrust/model.cmake b/src/thrust/model.cmake index 2d687c7..91821ef 100644 --- a/src/thrust/model.cmake +++ b/src/thrust/model.cmake @@ -18,6 +18,9 @@ register_flag_optional(BACKEND " "CUDA") + register_flag_optional(MANAGED "Enabled managed memory mode." + "OFF") + register_flag_optional(CMAKE_CUDA_COMPILER "[THRUST_IMPL==CUDA] Path to the CUDA nvcc compiler" "") @@ -34,6 +37,9 @@ register_flag_optional(CUDA_EXTRA_FLAGS macro(setup) set(CMAKE_CXX_STANDARD 14) + if (MANAGED) + register_definitions(MANAGED) + endif () if (${THRUST_IMPL} STREQUAL "CUDA") @@ -91,4 +97,4 @@ macro(setup) endmacro() - \ No newline at end of file +