forked from neka-nat/cupoch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve CMAKE_CUDA_ARCHITECTURES handling
- Loading branch information
Showing
4 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||
|
||
function(get_available_cuda_architectures CUDA_ARCHITECTURES) | ||
if (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") | ||
message(FATAL_ERROR "Unsupported CUDA compiler ${CMAKE_CUDA_COMPILER_ID}.") | ||
endif() | ||
if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.1") | ||
execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --list-gpu-code | ||
RESULT_VARIABLE EXIT_CODE | ||
OUTPUT_VARIABLE OUTPUT_VAL | ||
) | ||
if(EXIT_CODE EQUAL 0) | ||
string(STRIP ${OUTPUT_VAL} OUTPUT_VAL) | ||
string(REPLACE "sm_" "" OUTPUT_VAL ${OUTPUT_VAL}) | ||
string(REPLACE "\n" ";" ARCHITECTURES ${OUTPUT_VAL}) | ||
else() | ||
message(FATAL_ERROR "Failed to run nvcc --list-gpu-code: ${EXIT_CODE}") | ||
endif() | ||
elseif(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0") | ||
set(ARCHITECTURES "35;37;50;52;53;60;61;62;70;72;75;80") | ||
elseif(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0") | ||
set(ARCHITECTURES "30;32;35;37;50;52;53;60;61;62;70;72;75") | ||
elseif(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "9.1") | ||
set(ARCHITECTURES "30;32;35;37;50;52;53;60;61;62;70;72") | ||
else() | ||
set(ARCHITECTURES "30;32;35;37;50;52;53;60;61;62;70") | ||
endif() | ||
set(${CUDA_ARCHITECTURES} "${ARCHITECTURES}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Sets the default value of CMAKE_CUDA_ARCHITECTURES effectively to "all": | ||
# compile for all supported real (minor) architecture versions, and the highest virtual architecture version. | ||
function(init_cmake_cuda_architectures) | ||
get_available_cuda_architectures(ALL_ARCHITECTURES) | ||
set(CMAKE_CUDA_ARCHITECTURES "") | ||
foreach(arch ${ALL_ARCHITECTURES}) | ||
list(APPEND CMAKE_CUDA_ARCHITECTURES "${arch}-real") | ||
endforeach() | ||
list(GET ALL_ARCHITECTURES -1 latest) | ||
list(APPEND CMAKE_CUDA_ARCHITECTURES "${latest}-virtual") | ||
set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") | ||
set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}" PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
# central location for specifying the Cupoch version | ||
file(STRINGS "${CMAKE_SOURCE_DIR}/src/cupoch/version.txt" CUPOCH_VERSION_READ) | ||
|
||
foreach (ver ${CUPOCH_VERSION_READ}) | ||
if (ver MATCHES "CUPOCH_VERSION_(MAJOR|MINOR|PATCH|TWEAK) +([^ ]+)$") | ||
set(CUPOCH_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") | ||
endif () | ||
endforeach () | ||
|
||
string(CONCAT CUPOCH_VERSION "${CUPOCH_VERSION_MAJOR}" | ||
".${CUPOCH_VERSION_MINOR}" | ||
".${CUPOCH_VERSION_PATCH}" | ||
".${CUPOCH_VERSION_TWEAK}") | ||
|
||
# npm version has to be MAJOR.MINOR.PATCH | ||
string(CONCAT PROJECT_VERSION_THREE_NUMBER "${CUPOCH_VERSION_MAJOR}" | ||
".${CUPOCH_VERSION_MINOR}" | ||
".${CUPOCH_VERSION_PATCH}") | ||
|
||
message(STATUS "cupoch ${CUPOCH_VERSION}") |