Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed May 21, 2023
1 parent 3977910 commit 3354fda
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions cuvec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
if("${CUVEC_BUILD_VERSION}" STREQUAL "")
set(CUVEC_BUILD_VERSION 2 CACHE STRING "version" FORCE)
endif()
if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
set(CMAKE_CUDA_ARCHITECTURES native CACHE STRING "CUDA architectures" FORCE)
endif()
project(cuvec LANGUAGES C CXX VERSION "${CUVEC_BUILD_VERSION}")

option(CUVEC_CUDA_OPTIONAL "Make CUDA optional rather than forced" ON)
Expand All @@ -29,6 +26,39 @@ else()
endif()
endif()
endif()
if(CUDAToolkit_FOUND)
# work-around for https://gitlab.kitware.com/cmake/cmake/-/issues/24921 to
# detect local GPU architectures#
# (inspired by ${CMAKE_ROOT}/Modules/CMakeTestCUDACompiler.cmake)
message(WARNING "overriding CMAKE_CUDA_ARCHITECTURES")
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu)
if(CMAKE_CUDA_ABI_COMPILED)
# Run the test binary to detect the native architectures.
execute_process(COMMAND "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_CUDA.bin"
RESULT_VARIABLE _CUDA_ARCHS_RESULT
OUTPUT_VARIABLE _CUDA_ARCHS_OUTPUT
ERROR_VARIABLE _CUDA_ARCHS_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_CUDA_ARCHS_RESULT EQUAL 0)
set(_CUDA_ARCHS "")
foreach(_CUDA_ARCH IN LISTS _CUDA_ARCHS_OUTPUT)
if(${_CUDA_ARCH}-real IN_LIST CMAKE_CUDA_ARCHITECTURES_ALL OR ${_CUDA_ARCH} IN_LIST CMAKE_CUDA_ARCHITECTURES_ALL)
list(APPEND _CUDA_ARCHS ${_CUDA_ARCH})
endif()
endforeach()
unset(_CUDA_ARCH)
list(REMOVE_DUPLICATES _CUDA_ARCHS)
list(TRANSFORM _CUDA_ARCHS APPEND "-real")
set(CMAKE_CUDA_ARCHITECTURES "${_CUDA_ARCHS}" CACHE STRING "CUDA architectures" FORCE)
unset(_CUDA_ARCHS)
endif()
unset(_CUDA_ARCHS_RESULT)
unset(_CUDA_ARCHS_OUTPUT)
else()
set(CMAKE_CUDA_ARCHITECTURES native CACHE STRING "CUDA architectures" FORCE)
endif()
endif()
if(SKBUILD)
find_package(PythonExtensions REQUIRED)
set(LIB_TYPE "MODULE")
Expand Down

0 comments on commit 3354fda

Please sign in to comment.