Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Support cmake configure when system exists multiple cuda versions. #1740

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmake/cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ if (MSVC OR (NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY))
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
endif ()

if (MSVC)
# no plugin in BuildCustomizations and no specify cuda toolset
if (NOT CMAKE_VS_PLATFORM_TOOLSET_CUDA)
message(FATAL_ERROR "Please install CUDA MSBuildExtensions")
endif ()

if (CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR)
# find_package(CUDA) required ENV{CUDA_PATH}
lvhan028 marked this conversation as resolved.
Show resolved Hide resolved
set(ENV{CUDA_PATH} ${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR})
else ()
# we use CUDA_PATH and ignore nvcc.exe
# cmake will import highest cuda props version, which may not equal to CUDA_PATH
if (NOT (DEFINED ENV{CUDA_PATH}))
message(FATAL_ERROR "Please set CUDA_PATH environment variable")
endif ()

string(REGEX REPLACE ".*v([0-9]+)\\..*" "\\1" _MAJOR $ENV{CUDA_PATH})
string(REGEX REPLACE ".*v[0-9]+\\.([0-9]+).*" "\\1" _MINOR $ENV{CUDA_PATH})
if (NOT (${CMAKE_VS_PLATFORM_TOOLSET_CUDA} STREQUAL "${_MAJOR}.${_MINOR}"))
message(FATAL_ERROR "Auto detected cuda version ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}"
" is mismatch with ENV{CUDA_PATH} $ENV{CUDA_PATH}. Please modify CUDA_PATH"
" to match ${CMAKE_VS_PLATFORM_TOOLSET_CUDA} or specify cuda toolset by"
" cmake -T cuda=/path/to/cuda ..")
endif ()

if (NOT (DEFINED ENV{CUDA_PATH_V${_MAJOR}_${_MINOR}}))
message(FATAL_ERROR "Please set CUDA_PATH_V${_MAJOR}_${_MINOR} environment variable")
endif ()
endif ()
endif ()

# nvcc compiler settings
find_package(CUDA REQUIRED)

Expand Down
1 change: 1 addition & 0 deletions cmake/tensorrt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ else ()
message(FATAL_ERROR "Cannot find TensorRT libs")
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TENSORRT DEFAULT_MSG TENSORRT_INCLUDE_DIR
TENSORRT_LIBRARY)
if (NOT TENSORRT_FOUND)
Expand Down