Skip to content

Commit

Permalink
Use FindCUDA instead of FindCUDAToolkit for CMake < 3.17
Browse files Browse the repository at this point in the history
  • Loading branch information
psalz committed Mar 27, 2023
1 parent 6de986d commit bf07bd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmake/celerity-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ find_dependency(spdlog REQUIRED)
find_dependency(small_vector REQUIRED)
find_dependency(libenvpp REQUIRED)
if(@CELERITY_ENABLE_CUDA_BACKEND@)
find_dependency(CUDAToolkit REQUIRED)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
find_dependency(CUDAToolkit REQUIRED)
else()
find_dependency(CUDA REQUIRED)
endif()
endif()

if(CELERITY_SYCL_IMPL STREQUAL "hipSYCL")
Expand Down
24 changes: 21 additions & 3 deletions src/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
set(CUDA_OR_CUDA_TOOLKIT_FOUND FALSE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
find_package(CUDAToolkit)
set(CUDA_OR_CUDA_TOOLKIT_FOUND ${CUDAToolkit_FOUND})
else()
find_package(CUDA)
set(CUDA_OR_CUDA_TOOLKIT_FOUND ${CUDA_FOUND})
endif()

find_package(CUDAToolkit QUIET)
# find_package(LevelZero QUIET) # TODO: Need find module?
# find_package(ROCM QUIET) # TODO: Need find module?

# TODO: Make conditional on CELERITY_SYCL_IMPL?
option(CELERITY_ENABLE_CUDA_BACKEND "Enable optimized code paths for CUDA backends" ${CUDAToolkit_FOUND})
option(CELERITY_ENABLE_CUDA_BACKEND "Enable optimized code paths for CUDA backends" ${CUDA_OR_CUDA_TOOLKIT_FOUND})
if(CELERITY_ENABLE_CUDA_BACKEND AND NOT CUDAToolkit_FOUND)
# Run find_package again to emit error message
find_package(CUDAToolkit REQUIRED)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
find_package(CUDAToolkit REQUIRED)
else()
find_package(CUDA REQUIRED)
endif()
endif()

add_library(celerity_backends STATIC backend.cc generic_backend.cc)
Expand All @@ -17,7 +30,12 @@ add_sycl_to_target(TARGET celerity_backends SOURCES)

if(CELERITY_ENABLE_CUDA_BACKEND)
target_sources(celerity_backends PRIVATE cuda_backend.cc)
target_link_libraries(celerity_backends PUBLIC CUDA::cudart)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
target_link_libraries(celerity_backends PUBLIC CUDA::cudart)
else()
target_link_libraries(celerity_backends PUBLIC ${CUDA_LIBRARIES})
target_include_directories(celerity_backends PUBLIC ${CUDA_INCLUDE_DIRS})
endif()
target_compile_definitions(celerity_backends PUBLIC "CELERITY_DETAIL_BACKEND_CUDA_ENABLED=1")
message(STATUS "CUDA backend enabled")
endif()

0 comments on commit bf07bd3

Please sign in to comment.