Skip to content

Commit

Permalink
CUDA setup for llvm toolchain.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neumann-A committed Jan 1, 2024
1 parent c615fef commit 46aac22
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
34 changes: 32 additions & 2 deletions x64-win-llvm/extra_setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if(DEFINED CURRENT_PORT_DIR AND
get_filename_component(LLVM_BIN_DIR "${CLANG-CL_EXECUTBALE}" DIRECTORY)
set(LLVM_PATH_BACKUP "$ENV{PATH}")
set(ENV{PATH} "${LLVM_BIN_DIR};$ENV{PATH}")
if(CMAKE_PARENT_LIST_FILE MATCHES "-san(\\\.|-)" AND NOT PORT MATCHES "(icu)") # icu is building and executable calling the linker with hardcoded linker flags -> so no sanitizer
if(CMAKE_PARENT_LIST_FILE MATCHES "-san(\\\.|-)")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DVCPKG_USE_SANITIZERS:BOOL=TRUE"
)
Expand All @@ -56,10 +56,40 @@ if(DEFINED CURRENT_PORT_DIR AND
set(ENV{LINK} "/LIBPATH:\"${clang_ver_path}/lib/windows\"")
#set(ENV{PATH} "$ENV{VCToolsInstallDir}/bin/Hostx64/${VCPKG_TARGET_ARCHITECTURE};$ENV{PATH}") # Probably need to remove the VS sanitizer libs so they won't get picked up by accident!
endif()

### Setup to make CUDA work with custom LLVM
# if(NOT LLVM_BIN_DIR MATCHES "/VC/")
# # NVCC tries to look for vcvarsall.bat within a parent folder of the compiler within VC/Auxiliary/Build
# # So the compiler needs to be within the folder /VC/, so we need to do a little folder dance to achieve that
# # Additionally the compiler needs to be the first to be found on PATH
# file(MAKE_DIRECTORY "${DOWNLOADS}/llvm-toolchain/VC/Auxiliary/Build")
# file(WRITE "${DOWNLOADS}/llvm-toolchain/VC/Auxiliary/Build/vcvarsall.bat" "")
# cmake_path(GET CLANG-CL_EXECUTBALE FILENAME cxx_compiler_filename)
# set(cuda_cxx_compiler_path "${DOWNLOADS}/llvm-toolchain/VC/bin")
# set(CUDA_C_COMPILER "${cuda_cxx_compiler_path}/${cxx_compiler_filename}")

# if(NOT EXISTS "${cuda_cxx_compiler_path}")
# cmake_path(NATIVE_PATH cuda_cxx_compiler_path cuda_cxx_compiler_path_native)
# cmake_path(NATIVE_PATH LLVM_BIN_DIR llvm_bin_dir_native)
# execute_process(COMMAND cmd /d /c mklink /J "${cuda_cxx_compiler_path_native}" "${llvm_bin_dir_native}" COMMAND_ECHO STDOUT RESULT_VARIABLE var)
# message(STATUS "var:${var}")
# endif()

# set(ENV{PATH} "${cuda_cxx_compiler_path};$ENV{PATH}")
# list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
# "-DCUDA_C_COMPILER=${CUDA_C_COMPILER}"
# )
# unset(cxx_compiler_filename)
# unset(cuda_cxx_compiler_path)
# unset(CUDA_C_COMPILER)
# endif()

# Due to nvcc error : 'cudafe++' died with status 0xC0000409 clang-cl cannot currently be used to compile cu files.

else()
# This is just the detect compiler run!
if(CMAKE_PARENT_LIST_FILE MATCHES "-san(\\\.|-)")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DVCPKG_USE_SANITIZERS:BOOL=TRUE"
"-DVCPKG_USE_COMPILER_FOR_LINKAGE:BOOL=TRUE"
)
Expand Down
9 changes: 1 addition & 8 deletions x64-win-llvm/port_specialization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ if(PORT MATCHES "^(arrow|akali|arb|cello|chakracore|flint|folly|glog|zydis|graph
unset(VCPKG_VS_CMAKE_GENERATOR)
set(ENV{PATH} "${LLVM_PATH_BACKUP}")
endif()
if(PORT MATCHES "^itk$" AND "rtk" IN_LIST FEATURES)
# itk/rtk needs an update to correctly support cuda with clang-cl
message(STATUS "Falling back to cl!")
unset(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
unset(VCPKG_PLATFORM_TOOLSET)
unset(VCPKG_VS_CMAKE_GENERATOR)
set(ENV{PATH} "${LLVM_PATH_BACKUP}")
endif()

if(PORT MATCHES "^gettext$" AND "tools" IN_LIST FEATURES) # uses /EXTRACT unsupported by llvm-lib
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DCMAKE_AR=llvm-ar.exe")
set(ENV{AR} "llvm-ar.exe")
Expand Down
16 changes: 16 additions & 0 deletions x64-win-llvm/x64-win-llvm.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ set(CMAKE_ASM_MASM_COMPILER "ml64.exe" CACHE STRING "")
set(CMAKE_RC_COMPILER "rc.exe" CACHE STRING "")
set(CMAKE_MT "mt.exe" CACHE STRING "")


### CUDA section nvcc

if(NOT CUDA_C_COMPILER)
# Due to nvcc error : 'cudafe++' died with status 0xC0000409 | clang-cl cannot currently be used to compile cu files.
# The CUDA frontend probably has problems parsing preprocessed files from clang-cl
find_program(CL_COMPILER NAMES cl)
set(CUDA_C_COMPILER "${CL_COMPILER}")
endif()

string(APPEND CMAKE_CUDA_FLAGS " --keep --use-local-env --allow-unsupported-compiler -ccbin \"${CUDA_C_COMPILER}\"")

### CUDA section clang (requires cmake changes)

###

# Set compiler flags.
#set(CLANG_FLAGS "/clang:-fasm -fmacro-backtrace-limit=0") #/clang:-fopenmp-simd -openmp

Expand Down

0 comments on commit 46aac22

Please sign in to comment.