Skip to content

Commit

Permalink
Merge pull request #5145 from msimberg/cuda-cmake-options
Browse files Browse the repository at this point in the history
Adjust handling of CUDA/HIP options in CMake
  • Loading branch information
msimberg authored Feb 8, 2021
2 parents f5e03f6 + 662a570 commit 63a0c16
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 50 deletions.
40 changes: 24 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,31 @@ hpx_option(
set(CUDA_OPTION_STRING "Enable HPX_WITH_ASYNC_CUDA (CUDA or HIP futures) and\
HPX_WITH_CUDA_COMPUTE (CUDA/HIP enabled parallel algorithms) (default: OFF)"
)
set(CUDA_COMPUTE_STRING
"Enable HPX CUDA/HIP compute capability (parallel algorithms) module (default: OFF) -\
note: enabling this also enables CUDA/HIP futures via HPX_WITH_ASYNC_CUDA"
)
set(ASYNC_CUDA_STRING
"Enable HPX CUDA/HIP compute capability (parallel algorithms) module (default: OFF) -\
"Enable HPX CUDA/HIP compute capability (parallel algorithms) module\
(default: ON, dependent on HPX_WITH_CUDA or HPX_WITH_HIP) -\
note: CUDA/HIP futures may be used without CUDA/HIP Compute"
)
set(CUDA_COMPUTE_STRING
"Enable HPX CUDA/HIP compute capability (parallel algorithms) module\
(default: ON, dependent on HPX_WITH_CUDA or HPX_WITH_HIP, and HPX_WITH_ASYNC_CUDA) -\
note: enabling this also enables CUDA/HIP futures via HPX_WITH_ASYNC_CUDA"
)
set(HIP_OPTION_STRING "Enable compilation with HIPCC (default: OFF)")
hpx_option(HPX_WITH_CUDA BOOL "${CUDA_OPTION_STRING}" OFF ADVANCED)

# Those two will be renamed replacing CUDA with GPU
hpx_option(HPX_WITH_CUDA_COMPUTE BOOL "${CUDA_COMPUTE_STRING}" OFF ADVANCED)
hpx_option(HPX_WITH_ASYNC_CUDA BOOL "${ASYNC_CUDA_STRING}" OFF ADVANCED)
hpx_option(HPX_WITH_CUDA_COMPUTE BOOL "${CUDA_COMPUTE_STRING}" ON ADVANCED)
hpx_option(HPX_WITH_ASYNC_CUDA BOOL "${ASYNC_CUDA_STRING}" ON ADVANCED)

# HPX_WITH_CUDA_COMPUTE requires HPX_WITH_ASYNC_CUDA
if(HPX_WITH_CUDA_COMPUTE)
set(HPX_WITH_ASYNC_CUDA
ON
CACHE BOOL "${HPX_WITH_ASYNC_CUDA}" FORCE
)
endif()

# No need for the user to specify the option explicitly
hpx_option(HPX_WITH_HIP BOOL "${HIP_OPTION_STRING}" OFF ADVANCED)
if("${CMAKE_CXX_COMPILER}" MATCHES "hipcc$")
Expand All @@ -543,15 +555,11 @@ if("${CMAKE_CXX_COMPILER}" MATCHES "hipcc$")
CACHE BOOL "${HIP_OPTION_STRING}" FORCE
)
endif()
# if HPX_WITH_CUDA is ON, then enable both (sub) options
if(HPX_WITH_CUDA OR HPX_WITH_HIP)
set(HPX_WITH_CUDA_COMPUTE
ON
CACHE BOOL "${CUDA_COMPUTE_STRING}" FORCE
)
set(HPX_WITH_ASYNC_CUDA
ON
CACHE BOOL "${ASYNC_CUDA_STRING}" FORCE

if(HPX_WITH_CUDA AND HPX_WITH_HIP)
hpx_error(
"HPX_WITH_CUDA=ON and HPX_WITH_HIP=ON. Only one of them can be on at the same time.\
Note: HPX_WITH_HIP is automatically enabled when compiling with hipcc."
)
endif()

Expand Down
5 changes: 1 addition & 4 deletions cmake/HPX_AddComponent.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ function(add_hpx_component name)
endforeach()
endif()

if(HPX_WITH_CUDA_COMPUTE
AND NOT HPX_WITH_CUDA_CLANG
AND NOT HPX_WITH_HIP
)
if(HPX_WITH_CUDA AND NOT HPX_WITH_CUDA_CLANG)
cuda_add_library(
${name}_component ${${name}_lib_linktype} ${exclude_from_all}
${${name}_SOURCES} ${${name}_HEADERS} ${${name}_AUXILIARY}
Expand Down
5 changes: 1 addition & 4 deletions cmake/HPX_AddExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ function(add_hpx_executable name)
endforeach()
endif()

if(HPX_WITH_CUDA
AND (HPX_WITH_CUDA_COMPUTE OR HPX_WITH_ASYNC_CUDA)
AND NOT HPX_WITH_CUDA_CLANG
)
if(HPX_WITH_CUDA AND NOT HPX_WITH_CUDA_CLANG)
cuda_add_executable(
${name} ${${name}_SOURCES} ${${name}_HEADERS} ${${name}_AUXILIARY}
)
Expand Down
7 changes: 2 additions & 5 deletions cmake/HPX_AddLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function(add_hpx_library name)
endif()

# Manage files with .cu extension in case When Cuda Clang is used
if(HPX_WITH_CUDA_CLANG)
if(HPX_WITH_CUDA_CLANG OR HPX_WITH_HIP)
foreach(source ${${name}_SOURCES})
get_filename_component(extension ${source} EXT)
if(${extension} STREQUAL ".cu")
Expand All @@ -213,10 +213,7 @@ function(add_hpx_library name)
endforeach()
endif()

if(HPX_WITH_CUDA_COMPUTE
AND NOT HPX_WITH_CUDA_CLANG
AND NOT HPX_WITH_HIP
)
if(HPX_WITH_CUDA AND NOT HPX_WITH_CUDA_CLANG)
cuda_add_library(
${name} ${${name}_linktype} ${exclude_from_all} ${${name}_SOURCES}
${${name}_HEADERS} ${${name}_AUXILIARY}
Expand Down
4 changes: 2 additions & 2 deletions cmake/HPX_AddModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ function(add_hpx_module libname modulename)

# create library modules
if(${name}_CUDA
AND HPX_WITH_CUDA_COMPUTE
AND NOT HPX_WITH_HIP
AND HPX_WITH_CUDA
AND NOT HPX_WITH_CUDA_CLANG
)
# cmake-format: off
cuda_add_library(
Expand Down
5 changes: 1 addition & 4 deletions cmake/HPX_SetupCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

if((HPX_WITH_CUDA_COMPUTE OR HPX_WITH_ASYNC_CUDA)
AND NOT HPX_WITH_HIP
AND NOT TARGET Cuda::cuda
)
if(HPX_WITH_CUDA AND NOT TARGET Cuda::cuda)

find_package(CUDA REQUIRED)
if(NOT HPX_FIND_PACKAGE)
Expand Down
9 changes: 1 addition & 8 deletions libs/full/async_cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

if(NOT HPX_WITH_ASYNC_CUDA)
if(NOT (HPX_WITH_CUDA OR HPX_WITH_HIP) OR NOT HPX_WITH_ASYNC_CUDA)
return()
endif()

if(NOT TARGET Cuda::cuda AND NOT HPX_WITH_HIP)
message(
FATAL_ERROR
"CUDA/HIP future support has been enabled, but the CUDA or HIP installation is not setup"
)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Default location is $HPX_ROOT/libs/async_cuda/include
Expand Down
5 changes: 4 additions & 1 deletion libs/full/compute_cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

if(NOT HPX_WITH_CUDA_COMPUTE)
if(NOT (HPX_WITH_CUDA OR HPX_WITH_HIP)
OR NOT HPX_WITH_ASYNC_CUDA
OR NOT HPX_WITH_COMPUTE_CUDA
)
return()
endif()

Expand Down
8 changes: 2 additions & 6 deletions tests/performance/local/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <hpx/include/threads.hpp>
#include <hpx/type_support/unused.hpp>
#include <hpx/version.hpp>
#if defined(HPX_HAVE_GPU_SUPPORT)
#if defined(HPX_HAVE_MODULE_ASYNC_CUDA)
#include <hpx/async_cuda/cuda_future.hpp>
#include <hpx/async_cuda/target.hpp>
#endif
Expand Down Expand Up @@ -466,14 +466,13 @@ int hpx_main(hpx::program_options::variables_map& vm)
double time_total = mysecond();
std::vector<std::vector<double>> timing;

#if defined(HPX_HAVE_COMPUTE)
#if defined(HPX_HAVE_MODULE_COMPUTE_CUDA)
bool use_accel = false;
if (vm.count("use-accelerator"))
use_accel = true;

if (use_accel)
{
#if defined(HPX_HAVE_GPU_SUPPORT)
using executor_type = hpx::cuda::experimental::concurrent_executor<>;
using allocator_type = hpx::cuda::experimental::allocator<STREAM_TYPE>;

Expand All @@ -487,9 +486,6 @@ int hpx_main(hpx::program_options::variables_map& vm)
executor_type exec(target, host_targets);
auto policy = hpx::execution::par.on(exec);

#else
#error "The STREAM benchmark currently requires CUDA to run on an accelerator"
#endif
// perform benchmark
timing = run_benchmark<>(
iterations, vector_size, std::move(alloc), std::move(policy));
Expand Down

0 comments on commit 63a0c16

Please sign in to comment.