Skip to content
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
25 changes: 24 additions & 1 deletion CMakeModules/AFcuda_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,37 @@
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause


find_program(NVPRUNE NAMES nvprune)
# The following macro uses a macro defined by
# FindCUDA module from cmake.
function(af_find_static_cuda_libs libname)
cmake_parse_arguments(fscl "PRUNE" "" "" ${ARGN})

set(search_name
"${CMAKE_STATIC_LIBRARY_PREFIX}${libname}${CMAKE_STATIC_LIBRARY_SUFFIX}")
cuda_find_library_local_first(CUDA_${libname}_LIBRARY
${search_name} "${libname} static library")

if(fscl_PRUNE)
get_filename_component(af_${libname} ${CUDA_${libname}_LIBRARY} NAME)

set(liboutput ${CMAKE_CURRENT_BINARY_DIR}/${af_${libname}})
add_custom_command(OUTPUT ${liboutput}.depend
COMMAND ${NVPRUNE} ${cuda_architecture_flags} ${CUDA_${libname}_LIBRARY} -o ${liboutput}
COMMAND ${CMAKE_COMMAND} -E touch ${liboutput}.depend
BYPRODUCTS ${liboutput}
MAIN_DEPENDENCY ${CUDA_${libname}_LIBRARY}
COMMENT "Pruning ${CUDA_${libname}_LIBRARY} for ${cuda_build_targets}"
VERBATIM)
add_custom_target(AF_CUDA_${libname}_LIBRARY_TARGET
DEPENDS ${liboutput}.depend)
list(APPEND cuda_pruned_libraries AF_CUDA_${libname}_LIBRARY_TARGET PARENT_SCOPE)

set(AF_CUDA_${libname}_LIBRARY ${liboutput} PARENT_SCOPE)
mark_as_advanced(AF_CUDA_${libname}_LIBRARY)
else()
set(AF_CUDA_${libname}_LIBRARY ${CUDA_${libname}_LIBRARY} PARENT_SCOPE)
endif()
mark_as_advanced(CUDA_${libname}_LIBRARY)
endfunction()

Expand Down
49 changes: 26 additions & 23 deletions src/backend/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,27 @@ else()
set(use_static_cuda_lapack OFF)
endif()

set(CUDA_architecture_build_targets "Auto" CACHE
STRING "The compute architectures targeted by this build. (Options: Auto;3.0;Maxwell;All;Common)")

cuda_select_nvcc_arch_flags(cuda_architecture_flags ${CUDA_architecture_build_targets})

string(REGEX REPLACE "-gencodearch=compute_[0-9]+,code=sm_([0-9]+)" "\\1|" cuda_build_targets ${cuda_architecture_flags})
string(REGEX REPLACE "-gencodearch=compute_[0-9]+,code=compute_([0-9]+)" "\\1+PTX|" cuda_build_targets ${cuda_build_targets})
string(REGEX REPLACE "([0-9]+)([0-9])\\|" "\\1.\\2 " cuda_build_targets ${cuda_build_targets})
string(REGEX REPLACE "([0-9]+)([0-9]\\+PTX)\\|" "\\1.\\2 " cuda_build_targets ${cuda_build_targets})
message(STATUS "CUDA_architecture_build_targets: ${CUDA_architecture_build_targets} ( ${cuda_build_targets} )")

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};${cuda_architecture_flags})

find_cuda_helper_libs(nvrtc)
find_cuda_helper_libs(nvrtc-builtins)
if(UNIX AND AF_WITH_STATIC_CUDA_NUMERIC_LIBS)
af_find_static_cuda_libs(culibos)
af_find_static_cuda_libs(cublas_static)
af_find_static_cuda_libs(cublasLt_static)
af_find_static_cuda_libs(cublas_static PRUNE)
af_find_static_cuda_libs(cublasLt_static PRUNE)
af_find_static_cuda_libs(cufft_static)
af_find_static_cuda_libs(cusparse_static)
af_find_static_cuda_libs(cusparse_static PRUNE)

# FIXME When NVCC resolves this particular issue.
# NVCC doesn't like -l<full_path_static_lib>, hence we cannot
Expand All @@ -67,8 +80,8 @@ if(UNIX AND AF_WITH_STATIC_CUDA_NUMERIC_LIBS)
set(af_cuda_static_flags "${af_cuda_static_flags};-lcusparse_static")

if(${use_static_cuda_lapack})
af_find_static_cuda_libs(cusolver_static)
set(cusolver_static_lib "${CUDA_cusolver_static_LIBRARY}")
af_find_static_cuda_libs(cusolver_static PRUNE)
set(cusolver_static_lib "${AF_CUDA_cusolver_static_LIBRARY}")

# NVIDIA LAPACK library liblapack_static.a is a subset of LAPACK and only
# contains GPU accelerated stedc and bdsqr. The user has to link
Expand All @@ -84,19 +97,6 @@ endif()

get_filename_component(CUDA_LIBRARIES_PATH ${CUDA_cudart_static_LIBRARY} DIRECTORY CACHE)

set(CUDA_architecture_build_targets "Auto" CACHE
STRING "The compute architectures targeted by this build. (Options: Auto;3.0;Maxwell;All;Common)")

cuda_select_nvcc_arch_flags(cuda_architecture_flags ${CUDA_architecture_build_targets})

string(REGEX REPLACE "-gencodearch=compute_[0-9]+,code=sm_([0-9]+)" "\\1|" cuda_build_targets ${cuda_architecture_flags})
string(REGEX REPLACE "-gencodearch=compute_[0-9]+,code=compute_([0-9]+)" "\\1+PTX|" cuda_build_targets ${cuda_build_targets})
string(REGEX REPLACE "([0-9]+)([0-9])\\|" "\\1.\\2 " cuda_build_targets ${cuda_build_targets})
string(REGEX REPLACE "([0-9]+)([0-9]\\+PTX)\\|" "\\1.\\2 " cuda_build_targets ${cuda_build_targets})
message(STATUS "CUDA_architecture_build_targets: ${CUDA_architecture_build_targets} ( ${cuda_build_targets} )")

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};${cuda_architecture_flags})

mark_as_advanced(
CUDA_LIBRARIES_PATH
CUDA_architecture_build_targets)
Expand Down Expand Up @@ -327,17 +327,18 @@ if(UNIX AND AF_WITH_STATIC_CUDA_NUMERIC_LIBS)
${cusolver_lib}
${START_GROUP}
${CUDA_culibos_LIBRARY} #also a static libary
${CUDA_cublas_static_LIBRARY}
${CUDA_cufft_static_LIBRARY}
${CUDA_cusparse_static_LIBRARY}
${AF_CUDA_cublas_static_LIBRARY}
${AF_CUDA_cufft_static_LIBRARY}
${AF_CUDA_cusparse_static_LIBRARY}
${AF_CUDA_cublasLt_static_LIBRARY}
${cusolver_static_lib}
${END_GROUP}
)

if(CUDA_VERSION VERSION_GREATER 10.0)
target_link_libraries(af_cuda_static_cuda_library
PRIVATE
${CUDA_cublasLt_static_LIBRARY})
${AF_CUDA_cublasLt_static_LIBRARY})
endif()
if(CUDA_VERSION VERSION_GREATER 9.5)
target_link_libraries(af_cuda_static_cuda_library
Expand Down Expand Up @@ -687,7 +688,9 @@ add_library(ArrayFire::afcuda ALIAS afcuda)

add_dependencies(afcuda ${jit_kernel_targets} ${nvrtc_kernel_targets})
add_dependencies(af_cuda_static_cuda_library ${nvrtc_kernel_targets})
add_dependencies(afcuda af_cuda_static_cuda_library)
if(cuda_pruned_libraries)
add_dependencies(afcuda ${cuda_pruned_libraries})
endif()

target_include_directories (afcuda
PUBLIC
Expand Down