Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion ports/cuda/CONTROL
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: cuda
Version: 10.1
Port-Version: 2
Port-Version: 3
Description: A parallel computing platform and programming model
Homepage: https://developer.nvidia.com/cuda-toolkit
81 changes: 4 additions & 77 deletions ports/cuda/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,11 @@
# If this package is installed, we assume that CUDA is properly installed.

#note: this port must be kept in sync with CUDNN port: every time one is upgraded, the other must be too
set(CUDA_REQUIRED_VERSION "10.1.0")

set(CUDA_PATHS
ENV CUDA_PATH
ENV CUDA_BIN_PATH
ENV CUDA_PATH_V11_0
ENV CUDA_PATH_V10_2
ENV CUDA_PATH_V10_1)
include(${CMAKE_CURRENT_LIST_DIR}/vcpkg_find_cuda.cmake)

if (VCPKG_TARGET_IS_WINDOWS)
find_program(NVCC
NAMES nvcc.exe
PATHS
${CUDA_PATHS}
PATH_SUFFIXES bin bin64
DOC "Toolkit location."
NO_DEFAULT_PATH
)
else()
if (VCPKG_TARGET_IS_LINUX)
set(platform_base "/usr/local/cuda-")
else()
set(platform_base "/Developer/NVIDIA/CUDA-")
endif()

file(GLOB possible_paths "${platform_base}*")
set(FOUND_PATH )
foreach (p ${possible_paths})
# Extract version number from end of string
string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p})
if (IS_DIRECTORY ${p} AND p_version)
if (p_version VERSION_GREATER_EQUAL CUDA_REQUIRED_VERSION)
set(FOUND_PATH ${p})
break()
endif()
endif()
endforeach()

find_program(NVCC
NAMES nvcc
PATHS
${CUDA_PATHS}
PATHS ${FOUND_PATH}
PATH_SUFFIXES bin bin64
DOC "Toolkit location."
NO_DEFAULT_PATH
)
endif()
vcpkg_find_cuda(OUT_CUDA_TOOLKIT_ROOT CUDA_TOOLKIT_ROOT)

set(error_code 1)
if (NVCC)
execute_process(
COMMAND ${NVCC} --version
OUTPUT_VARIABLE NVCC_OUTPUT
RESULT_VARIABLE error_code)
endif()
file(COPY ${CMAKE_CURRENT_LIST_DIR}/vcpkg_find_cuda.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/vcpkg_find_cuda)


if (error_code)
message(STATUS "Executing ${NVCC} --version resulted in error: ${error_code}")
message(FATAL_ERROR "Could not find CUDA. Before continuing, please download and install CUDA (v${CUDA_REQUIRED_VERSION} or higher) from:"
"\n https://developer.nvidia.com/cuda-downloads\n")
endif()

# Sample output:
# NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2016 NVIDIA Corporation
# Built on Sat_Sep__3_19:05:48_CDT_2016
# Cuda compilation tools, release 8.0, V8.0.44
string(REGEX MATCH "V([0-9]+)\\.([0-9]+)\\.([0-9]+)" CUDA_VERSION ${NVCC_OUTPUT})
message(STATUS "Found CUDA ${CUDA_VERSION}")
set(CUDA_VERSION_MAJOR ${CMAKE_MATCH_1})
set(CUDA_VERSION_MINOR ${CMAKE_MATCH_2})
set(CUDA_VERSION_PATCH ${CMAKE_MATCH_3})

if (CUDA_VERSION_MAJOR LESS 10 AND CUDA_VERSION_MINOR LESS 1)
message(FATAL_ERROR "CUDA ${CUDA_VERSION} found, but v${CUDA_REQUIRED_VERSION} is required. Please download and install a more recent version of CUDA from:"
"\n https://developer.nvidia.com/cuda-downloads\n")
endif()

SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
91 changes: 91 additions & 0 deletions ports/cuda/vcpkg_find_cuda.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
function(vcpkg_find_cuda)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to go full vcpkg_find_fortran and use CMakeDetermineCUDACompiler.cmake ? Just trick it to ingore the FATAL_ERROR by setting CMAKE_GENERATOR to Ninja

cmake_parse_arguments(PARSE_ARGV 0 vfc "" "OUT_CUDA_TOOLKIT_ROOT" "")

if(NOT vfc_OUT_CUDA_TOOLKIT_ROOT)
message(FATAL_ERROR "vcpkg_find_cuda() requres an OUT_CUDA_TOOLKIT_ROOT argument")
endif()

set(CUDA_REQUIRED_VERSION "10.1.0")

set(CUDA_PATHS
ENV CUDA_PATH
ENV CUDA_BIN_PATH
ENV CUDA_PATH_V11_0
ENV CUDA_PATH_V10_2
ENV CUDA_PATH_V10_1)
Comment on lines +10 to +15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of search in all those dirs env CUDA_PATH is actually required by CMake. As such setting up CUDA_PATH if one of the other env variables exist is the way to go since it mitigates the env removal some VS updates seem to do.


if (VCPKG_TARGET_IS_WINDOWS)
find_program(NVCC
NAMES nvcc.exe
PATHS
${CUDA_PATHS}
PATH_SUFFIXES bin bin64
DOC "Toolkit location."
NO_DEFAULT_PATH
)
else()
if (VCPKG_TARGET_IS_LINUX)
set(platform_base "/usr/local/cuda-")
else()
set(platform_base "/Developer/NVIDIA/CUDA-")
endif()

file(GLOB possible_paths "${platform_base}*")
set(FOUND_PATH )
foreach (p ${possible_paths})
# Extract version number from end of string
string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p})
if (IS_DIRECTORY ${p} AND p_version)
if (p_version VERSION_GREATER_EQUAL CUDA_REQUIRED_VERSION)
set(FOUND_PATH ${p})
break()
endif()
endif()
endforeach()

find_program(NVCC
NAMES nvcc
PATHS
${CUDA_PATHS}
PATHS ${FOUND_PATH}
PATH_SUFFIXES bin bin64
DOC "Toolkit location."
NO_DEFAULT_PATH
)
endif()

set(error_code 1)
if (NVCC)
execute_process(
COMMAND ${NVCC} --version
OUTPUT_VARIABLE NVCC_OUTPUT
RESULT_VARIABLE error_code)
endif()


if (error_code)
message(STATUS "Executing ${NVCC} --version resulted in error: ${error_code}")
message(FATAL_ERROR "Could not find CUDA. Before continuing, please download and install CUDA (v${CUDA_REQUIRED_VERSION} or higher) from:"
"\n https://developer.nvidia.com/cuda-downloads\n")
endif()

# Sample output:
# NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2016 NVIDIA Corporation
# Built on Sat_Sep__3_19:05:48_CDT_2016
# Cuda compilation tools, release 8.0, V8.0.44
string(REGEX MATCH "V([0-9]+)\\.([0-9]+)\\.([0-9]+)" CUDA_VERSION ${NVCC_OUTPUT})
message(STATUS "Found CUDA ${CUDA_VERSION}")
set(CUDA_VERSION_MAJOR ${CMAKE_MATCH_1})
set(CUDA_VERSION_MINOR ${CMAKE_MATCH_2})
set(CUDA_VERSION_PATCH ${CMAKE_MATCH_3})

if (CUDA_VERSION_MAJOR LESS 10 AND CUDA_VERSION_MINOR LESS 1)
message(FATAL_ERROR "CUDA ${CUDA_VERSION} found, but v${CUDA_REQUIRED_VERSION} is required. Please download and install a more recent version of CUDA from:"
"\n https://developer.nvidia.com/cuda-downloads\n")
endif()

get_filename_component(CUDA_TOOLKIT_ROOT "${NVCC}" DIRECTORY)
get_filename_component(CUDA_TOOLKIT_ROOT "${CUDA_TOOLKIT_ROOT}" DIRECTORY)
set(${vfc_OUT_CUDA_TOOLKIT_ROOT} "${CUDA_TOOLKIT_ROOT}" PARENT_SCOPE)
endfunction()