diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 286265f07..38b953011 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -12,6 +12,8 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ### Changed - Modified `blt_add_sphinx_target` to allow setting sphinx source and configure directories. - Modified `blt_add_sphinx_target` and `blt_add_doxygen_target` requiring the first argument preceed with TARGET. +- Updated CUDA support to use CMake's native CUDA language and `CUDAToolkit`/`CUDA::cudart` + targets instead of deprecated `FindCUDA`; removed Clang CUDA support. ## [Version 0.7.2] - Release date 2026-05-01 diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 3f06c49e4..d2ed7d4d9 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -198,7 +198,7 @@ macro(blt_add_library) add_library( ${arg_NAME} ${_lib_type} ${arg_SOURCES} ${arg_HEADERS} ) - if (BLT_ENABLE_CUDA AND NOT BLT_ENABLE_CLANG_CUDA) + if (BLT_ENABLE_CUDA) blt_setup_cuda_target( NAME ${arg_NAME} SOURCES ${arg_SOURCES} @@ -320,7 +320,7 @@ macro(blt_add_executable) add_executable( ${arg_NAME} ${arg_SOURCES} ${arg_HEADERS}) - if (BLT_ENABLE_CUDA AND NOT BLT_ENABLE_CLANG_CUDA) + if (BLT_ENABLE_CUDA) blt_setup_cuda_target( NAME ${arg_NAME} SOURCES ${arg_SOURCES} diff --git a/cmake/BLTOptions.cmake b/cmake/BLTOptions.cmake index f0f33f0f3..c03ee8ad0 100644 --- a/cmake/BLTOptions.cmake +++ b/cmake/BLTOptions.cmake @@ -55,11 +55,6 @@ option(ENABLE_FORTRAN "Enables Fortran compiler support" ${_fortran_already option(ENABLE_MPI "Enables MPI support" OFF) option(ENABLE_OPENMP "Enables OpenMP compiler support" OFF) option(ENABLE_CUDA "Enable CUDA support" OFF) -cmake_dependent_option(ENABLE_CLANG_CUDA "Enable Clang's native CUDA support" OFF - "ENABLE_CUDA" OFF) -mark_as_advanced(ENABLE_CLANG_CUDA) -set(BLT_CLANG_CUDA_ARCH "sm_30" CACHE STRING "Compute architecture to use when generating CUDA code with Clang") -mark_as_advanced(BLT_CLANG_CUDA_ARCH) option(ENABLE_HIP "Enable HIP support" OFF) set(CMAKE_HIP_ARCHITECTURES "gfx900" CACHE STRING "gfx architecture to use when generating HIP/ROCm code") diff --git a/cmake/BLTPrivateMacros.cmake b/cmake/BLTPrivateMacros.cmake index 3df3addf2..68aa8a5e9 100644 --- a/cmake/BLTPrivateMacros.cmake +++ b/cmake/BLTPrivateMacros.cmake @@ -328,13 +328,6 @@ macro(blt_setup_cuda_target) set_source_files_properties( ${_cuda_sources} PROPERTIES LANGUAGE CUDA) - if (CUDA_SEPARABLE_COMPILATION) - set_source_files_properties( ${_cuda_sources} PROPERTIES - CUDA_SEPARABLE_COMPILATION ON) - set_target_properties( ${arg_NAME} PROPERTIES - CUDA_SEPARABLE_COMPILATION ON) - endif() - if (DEFINED arg_LIBRARY_TYPE) if (${arg_LIBRARY_TYPE} STREQUAL "static") set_target_properties( ${arg_NAME} PROPERTIES diff --git a/cmake/BLTSetupTargets.cmake b/cmake/BLTSetupTargets.cmake index c0c82c21f..59e095705 100644 --- a/cmake/BLTSetupTargets.cmake +++ b/cmake/BLTSetupTargets.cmake @@ -50,9 +50,6 @@ else() if(NOT BLT_ENABLE_FIND_MPI) set(BLT_ENABLE_FIND_MPI ${ENABLE_FIND_MPI}) endif() - if(NOT BLT_ENABLE_CLANG_CUDA) - set(BLT_ENABLE_CLANG_CUDA ${ENABLE_CLANG_CUDA}) - endif() message(STATUS "BLT MPI support is ${BLT_ENABLE_MPI}") message(STATUS "BLT OpenMP support is ${BLT_ENABLE_OPENMP}") diff --git a/cmake/BLTThirdPartyConfigFlags.cmake.in b/cmake/BLTThirdPartyConfigFlags.cmake.in index d91b73cb9..4f59ca557 100644 --- a/cmake/BLTThirdPartyConfigFlags.cmake.in +++ b/cmake/BLTThirdPartyConfigFlags.cmake.in @@ -15,19 +15,8 @@ if(NOT BLT_ENABLE_FIND_MPI) set(BLT_ENABLE_FIND_MPI @ENABLE_FIND_MPI@) endif() -# Always prefer the current project if they turned it on -if(ENABLE_CLANG_CUDA) - set(BLT_ENABLE_CLANG_CUDA ${ENABLE_CLANG_CUDA}) -else() - set(BLT_ENABLE_CLANG_CUDA @ENABLE_CLANG_CUDA@) -endif() - -if (NOT DEFINED BLT_CLANG_CUDA_ARCH) - set(BLT_CLANG_CUDA_ARCH "@BLT_CLANG_CUDA_ARCH@") -endif() - -if (NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) - set(CUDA_TOOLKIT_ROOT_DIR "@CUDA_TOOLKIT_ROOT_DIR@") +if (NOT CUDAToolkit_ROOT) + set(CUDAToolkit_ROOT "@CUDAToolkit_ROOT@") endif() if (NOT DEFINED ROCM_PATH) diff --git a/cmake/thirdparty/BLTSetupCUDA.cmake b/cmake/thirdparty/BLTSetupCUDA.cmake index e7ac6bf6d..4a0f149e1 100644 --- a/cmake/thirdparty/BLTSetupCUDA.cmake +++ b/cmake/thirdparty/BLTSetupCUDA.cmake @@ -1,28 +1,15 @@ # Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and # other BLT Project Developers. See the top-level LICENSE file for details -# +# # SPDX-License-Identifier: (BSD-3-Clause) -# Use legacy FindCUDA. This was deprecated in 3.10 and removed in 3.27. -# TODO: Do not rely on this setting and use the new CUDA finding mechanism instead: -# https://cmake.org/cmake/help/latest/module/FindCUDA.html -if(POLICY CMP0146) - cmake_policy(SET CMP0146 OLD) -endif() - ################################ # Sanity Checks ################################ -# Rare case of two flags being incompatible -if (DEFINED CMAKE_SKIP_BUILD_RPATH AND DEFINED CUDA_LINK_WITH_NVCC) - if (NOT CMAKE_SKIP_BUILD_RPATH AND CUDA_LINK_WITH_NVCC) - message( FATAL_ERROR - "CMAKE_SKIP_BUILD_RPATH (FALSE) and CUDA_LINK_WITH_NVCC (TRUE) " - "are incompatible when linking explicit shared libraries. Set " - "CMAKE_SKIP_BUILD_RPATH to TRUE.") - endif() -endif() +if( ${CMAKE_VERSION} VERSION_LESS "3.17.0" ) + message(FATAL_ERROR "CUDA support requires CMake >= 3.17.0") +endif () # CMAKE_CUDA_HOST_COMPILER needs to be set prior to enabling the CUDA language get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) @@ -42,102 +29,72 @@ if ( NOT CMAKE_CUDA_HOST_COMPILER ) endif() endif() -# Override rpath link flags for nvcc -if (CUDA_LINK_WITH_NVCC) - set(CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG "-Xlinker -rpath -Xlinker " CACHE STRING "") - set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG "-Xlinker -rpath -Xlinker " CACHE STRING "") +if(CUDA_TOOLKIT_ROOT_DIR AND NOT CUDAToolkit_ROOT) + set(CUDAToolkit_ROOT "${CUDA_TOOLKIT_ROOT_DIR}" CACHE PATH + "Root directory of the CUDA Toolkit" FORCE) endif() - -############################################################ -# Basics -############################################################ -# language check fails when using clang-cuda -if (NOT BLT_ENABLE_CLANG_CUDA) - enable_language(CUDA) +if(DEFINED CUDA_SEPARABLE_COMPILATION AND NOT DEFINED CMAKE_CUDA_SEPARABLE_COMPILATION) + set(CMAKE_CUDA_SEPARABLE_COMPILATION "${CUDA_SEPARABLE_COMPILATION}" CACHE BOOL + "Build CUDA objects with separable compilation enabled" FORCE) endif() + ############################################################ -# Map Legacy FindCUDA variables to native cmake variables +# Basics ############################################################ -# if we are linking with NVCC, define the link rule here -# Note that some mpi wrappers might have things like -Wl,-rpath defined, which when using -# FindMPI can break nvcc. In that case, you should set ENABLE_FIND_MPI to Off and control -# the link using CMAKE_CUDA_LINK_FLAGS. -Wl,-rpath, equivalent would be -Xlinker -rpath -Xlinker -if (CUDA_LINK_WITH_NVCC) - set(CMAKE_CUDA_LINK_EXECUTABLE - "${CMAKE_CUDA_COMPILER} -o ") - # do a no-op for the device links - for some reason the device link library dependencies are only a subset of the - # executable link dependencies so the device link fails if there are any missing CUDA library dependencies. Since - # we are doing a link with the nvcc compiler, the device link step is unnecessary . - # Frustratingly, nvcc-link errors out if you pass it an empty file, so we have to first compile the empty file. - set(CMAKE_CUDA_DEVICE_LINK_LIBRARY "touch .cu ; ${CMAKE_CUDA_COMPILER} -std=c++${CMAKE_CUDA_STANDARD} -dc .cu -o ") - set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE "touch .cu ; ${CMAKE_CUDA_COMPILER} -std=c++${CMAKE_CUDA_STANDARD} -dc .cu -o ") -endif() +enable_language(CUDA) ############################################################ # Find CUDA ############################################################ -# If CUDA_TOOLKIT_ROOT_DIR is not set, it should be set by find_package(CUDA) -find_package(CUDA REQUIRED) -blt_assert_exists( DIRECTORIES ${CUDA_TOOLKIT_ROOT_DIR} ) +find_package(CUDAToolkit REQUIRED) +blt_assert_exists( TARGETS CUDA::cudart ) -############################################################ -# Append the path to the NVIDIA SDK to the link flags -############################################################ -if ( IS_DIRECTORY "${CUDA_TOOLKIT_ROOT_DIR}/lib64" ) - list(APPEND CMAKE_CUDA_LINK_FLAGS "-L${CUDA_TOOLKIT_ROOT_DIR}/lib64" ) +if(NOT CUDAToolkit_ROOT AND CUDAToolkit_BIN_DIR) + get_filename_component(CUDAToolkit_ROOT "${CUDAToolkit_BIN_DIR}" DIRECTORY) endif() -if ( IS_DIRECTORY "${CUDA_TOOLKIT_ROOT_DIR}/lib}" ) - list(APPEND CMAKE_CUDA_LINK_FLAGS "-L${CUDA_TOOLKIT_ROOT_DIR}/lib" ) -endif() +# Provide compatibility variables for projects that still query the old names. +set(CUDA_FOUND ${CUDAToolkit_FOUND}) +set(CUDA_VERSION_STRING ${CUDAToolkit_VERSION}) +set(CUDA_INCLUDE_DIRS ${CUDAToolkit_INCLUDE_DIRS}) +set(CUDA_LIBRARIES CUDA::cudart) ############################################################ # Output information about CUDA ############################################################ -message(STATUS "CUDA Version: ${CUDA_VERSION_STRING}") -message(STATUS "CUDA Toolkit Root Dir: ${CUDA_TOOLKIT_ROOT_DIR}") +message(STATUS "CUDA Version: ${CUDAToolkit_VERSION}") +message(STATUS "CUDA Toolkit Root Dir: ${CUDAToolkit_ROOT}") message(STATUS "CUDA Compiler: ${CMAKE_CUDA_COMPILER}") message(STATUS "CUDA Host Compiler: ${CMAKE_CUDA_HOST_COMPILER}") message(STATUS "CUDA Standard: ${CMAKE_CUDA_STANDARD}") if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18" ) message(STATUS "CUDA Architectures: ${CMAKE_CUDA_ARCHITECTURES}") endif() -message(STATUS "CUDA Include Path: ${CUDA_INCLUDE_DIRS}") -message(STATUS "CUDA Libraries: ${CUDA_LIBRARIES}") +message(STATUS "CUDA Include Path: ${CUDAToolkit_INCLUDE_DIRS}") +message(STATUS "CUDA Runtime Target: CUDA::cudart") message(STATUS "CUDA Compile Flags: ${CMAKE_CUDA_FLAGS}") message(STATUS "CUDA Link Flags: ${CMAKE_CUDA_LINK_FLAGS}") -message(STATUS "BLT CUDA Separable Compilation: ${CUDA_SEPARABLE_COMPILATION}") message(STATUS "CUDA Separable Compilation: ${CMAKE_CUDA_SEPARABLE_COMPILATION}") -message(STATUS "CUDA Link with NVCC: ${CUDA_LINK_WITH_NVCC}") message(STATUS "CUDA Implicit Link Libraries: ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES}") message(STATUS "CUDA Implicit Link Directories: ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}") ############################################################ # Check CUDA language standard is supported ############################################################ -# Note: change to use CUDAToolkit_VERSION after moving away from find_package(CUDA) if(CMAKE_CUDA_STANDARD STREQUAL "17") if(NOT DEFINED CMAKE_CUDA_COMPILE_FEATURES OR (NOT "cuda_std_17" IN_LIST CMAKE_CUDA_COMPILE_FEATURES)) - message(FATAL_ERROR "CUDA ${CUDA_VERSION_STRING} does not support C++17.") + message(FATAL_ERROR "CUDA ${CUDAToolkit_VERSION} does not support C++17.") endif() endif() if(CMAKE_CUDA_STANDARD STREQUAL "20") if(NOT DEFINED CMAKE_CUDA_COMPILE_FEATURES OR (NOT "cuda_std_20" IN_LIST CMAKE_CUDA_COMPILE_FEATURES)) - message(FATAL_ERROR "CUDA ${CUDA_VERSION_STRING} does not support C++20.") + message(FATAL_ERROR "CUDA ${CUDAToolkit_VERSION} does not support C++20.") endif() endif() -# don't propagate host flags - too easy to break stuff! -set (CUDA_PROPAGATE_HOST_FLAGS Off) -if (CMAKE_CXX_COMPILER) - set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER}) -else() - set(CUDA_HOST_COMPILER ${CMAKE_C_COMPILER}) -endif() - # Set PIE options to empty for PGI since it doesn't understand -fPIE This # option is set in the CUDA toolchain file so must be unset after # enable_language(CUDA) @@ -146,12 +103,30 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI") endif() -set(_cuda_compile_flags " ") -if (BLT_ENABLE_CLANG_CUDA) - set (_cuda_compile_flags -x cuda --cuda-gpu-arch=${BLT_CLANG_CUDA_ARCH} --cuda-path=${CUDA_TOOLKIT_ROOT_DIR}) - message(STATUS "Clang CUDA Enabled. CUDA compile flags added: ${_cuda_compile_flags}") +# CUDA targets must be global for aliases when created as imported targets. +set(_blt_cuda_is_global On) +if(${BLT_EXPORT_THIRDPARTY}) + set(_blt_cuda_is_global Off) endif() +# Use DEPENDS_ON to keep the CUDA::cudart imported library target in the link +# interface. blt_inherit_target_info() only copies interface usage properties. + +# Use the CUDA runtime without flagging source files as +# CUDA language. This causes your source files to use +# the regular C/CXX compiler. This is separate from +# linking with nvcc. +# This logic is handled in the blt_add_library/executable +# macros +blt_import_library(NAME cuda_runtime + INCLUDES ${CUDAToolkit_INCLUDE_DIRS} + TREAT_INCLUDES_AS_SYSTEM ON + DEPENDS_ON CUDA::cudart + EXPORTABLE ${BLT_EXPORT_THIRDPARTY} + GLOBAL ${_blt_cuda_is_global}) + +add_library(blt::cuda_runtime ALIAS cuda_runtime) + # depend on 'cuda', if you need to use cuda # headers, link to cuda libs, and need to compile your # source files with the cuda compiler (nvcc) instead of @@ -159,23 +134,8 @@ endif() # This logic is handled in the blt_add_library/executable # macros blt_import_library(NAME cuda - COMPILE_FLAGS ${_cuda_compile_flags} - INCLUDES ${CUDA_INCLUDE_DIRS} - LIBRARIES ${CUDA_LIBRARIES} - LINK_FLAGS "${CMAKE_CUDA_LINK_FLAGS}" - EXPORTABLE ${BLT_EXPORT_THIRDPARTY}) + DEPENDS_ON cuda_runtime + EXPORTABLE ${BLT_EXPORT_THIRDPARTY} + GLOBAL ${_blt_cuda_is_global}) add_library(blt::cuda ALIAS cuda) - -# same as 'cuda' but we don't flag your source files as -# CUDA language. This causes your source files to use -# the regular C/CXX compiler. This is separate from -# linking with nvcc. -# This logic is handled in the blt_add_library/executable -# macros -blt_import_library(NAME cuda_runtime - INCLUDES ${CUDA_INCLUDE_DIRS} - LIBRARIES ${CUDA_LIBRARIES} - EXPORTABLE ${BLT_EXPORT_THIRDPARTY}) - -add_library(blt::cuda_runtime ALIAS cuda_runtime) diff --git a/docs/api/target_properties.rst b/docs/api/target_properties.rst index c0e2febe2..fc41d0f9f 100644 --- a/docs/api/target_properties.rst +++ b/docs/api/target_properties.rst @@ -128,9 +128,6 @@ or with the corresponding :ref:`blt_add_executable` and :ref:`blt_add_library` m ``PRIVATE`` flags are used for the given target. ``INTERFACE`` flags are inherited by any target that depends on this target. ``PUBLIC`` flags are both ``INTERFACE`` and ``PRIVATE``. -If ``CUDA_LINK_WITH_NVCC`` is set to ``ON``, this macro will automatically -convert ``-Wl,-rpath,`` to :literal:`-Xlinker -rpath -Xlinker\ `. - .. note:: This macro also handles the various changes that CMake made in 3.13. For example, the target property ``LINK_FLAGS`` was changes to ``LINK_OPTIONS`` and was changed from a @@ -144,8 +141,7 @@ convert ``-Wl,-rpath,`` to :literal:`-Xlinker -rpath -Xlinker\ `. .. note:: In CMake versions 3.13 and above, this list is prepended with ``SHELL:`` which stops - CMake from de-duplicating flags. This is especially bad when linking with NVCC when - you have groups of flags like ``-Xlinker -rpath -Xlinker ``. + CMake from de-duplicating grouped flags. .. _blt_print_target_properties: @@ -255,4 +251,3 @@ of the generator or value of ``ENABLE_FOLDERS``). .. note:: Do not use this macro on header-only, ``INTERFACE`` library targets, since this will generate a CMake configuration error. - diff --git a/docs/tutorial/calc_pi/CMakeLists.txt b/docs/tutorial/calc_pi/CMakeLists.txt index 7f3cfe6e1..7d1096009 100644 --- a/docs/tutorial/calc_pi/CMakeLists.txt +++ b/docs/tutorial/calc_pi/CMakeLists.txt @@ -95,7 +95,7 @@ if(ENABLE_GTEST) # Test 3: Add cuda version of calc_pi, and expand test 1 to also test # the cuda version. #------------------------------------------------------------------------------ - if(CUDA_FOUND) + if(ENABLE_CUDA) # _blt_tutorial_calcpi_cuda_start blt_add_library( NAME calc_pi_cuda diff --git a/docs/tutorial/common_hpc_dependencies.rst b/docs/tutorial/common_hpc_dependencies.rst index 0ad520827..a4ac7c70a 100644 --- a/docs/tutorial/common_hpc_dependencies.rst +++ b/docs/tutorial/common_hpc_dependencies.rst @@ -95,8 +95,8 @@ CUDA Finally, ``test_3`` builds and tests the ``calc_pi_cuda`` library, which uses CUDA to parallelize the calculation over the integration intervals. -To enable CUDA, we set ``ENABLE_CUDA``, ``CMAKE_CUDA_COMPILER``, -``CMAKE_CUDA_ARCHITECTURES``, and ``CUDA_TOOLKIT_ROOT_DIR`` in our host config file. +To enable CUDA, we set ``ENABLE_CUDA``, ``CMAKE_CUDA_COMPILER``, +``CMAKE_CUDA_ARCHITECTURES``, and ``CUDAToolkit_ROOT`` in our host config file. Also before enabling the CUDA language in CMake, you need to set ``CMAKE_CUDA_HOST_COMPILER`` in CMake 3.9+ or ``CUDA_HOST_COMPILER`` in previous versions. If you do not call ``enable_language(CUDA)``, BLT will set the appropriate host @@ -122,10 +122,10 @@ Here, you can see how ``calc_pi_cuda`` and ``test_3`` use ``DEPENDS_ON``: The ``blt::cuda`` dependency for ``calc_pi_cuda`` is a little special, along with adding the normal CUDA library and headers to your library or executable, -it also tells BLT that this target's C/C++/CUDA source files need to be compiled via -``nvcc`` or ``cuda-clang``. If this is not a requirement, you can use the dependency -``blt::cuda_runtime`` which also adds the CUDA runtime library and headers but will not -compile each source file with ``nvcc``. +it also tells BLT that this target's C/C++/CUDA source files need to be compiled as +CUDA language sources. If this is not a requirement, you can use the dependency +``blt::cuda_runtime`` which adds the CUDA runtime library and headers but will not +change the language of your source files. .. note:: If you are using GoogleTest and ``nvcc``, you will need to set diff --git a/docs/tutorial/object_libraries.rst b/docs/tutorial/object_libraries.rst index 793a9f980..05be4d90e 100644 --- a/docs/tutorial/object_libraries.rst +++ b/docs/tutorial/object_libraries.rst @@ -32,10 +32,9 @@ the linker removing unused symbols in the larger library. if you need their inheritable information to be correct. If you are using separable CUDA compilation (relocatable device code) in your -object library, users of that library will be required to use NVCC to link their -executables - in general, only NVCC can perform the "device link" step. To remove -this restriction, you can enable the ``CUDA_RESOLVE_DEVICE_SYMBOLS`` property on -an object library: +object library, users of that library will need a final CUDA device link step. +To perform that step while building the library, you can enable the +``CUDA_RESOLVE_DEVICE_SYMBOLS`` property on an object library: .. code-block:: cmake @@ -52,7 +51,8 @@ You can read more about this property in the These options only apply when an object library in your project is linked later into a shared or static library, in which case a separate object file containing device symbols is created and added to the "final" library. Object libraries - provided directly to users of your project will still require a device link step. + provided directly to users of your project will still require a device link step + in the consuming target. The ``CUDA_RESOLVE_DEVICE_SYMBOLS`` property is also supported for static and shared libraries. By default, it is enabled for shared libraries but disabled for static libraries. diff --git a/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake b/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake index 4846ffcf0..89dffcfc5 100644 --- a/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake +++ b/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake @@ -38,8 +38,8 @@ set(MPIEXEC "${MPI_BASE_DIR}/mpiexec" CACHE PATH "") ######################################################################## set(ENABLE_CUDA ON CACHE BOOL "") -set(CUDA_TOOLKIT_ROOT_DIR "/Developer/NVIDIA/CUDA-8.0/" CACHE PATH "") -set(CUDA_BIN_DIR "/Developer/NVIDIA/CUDA-8.0/bin/" CACHE PATH "") +set(CUDAToolkit_ROOT "/Developer/NVIDIA/CUDA-8.0/" CACHE PATH "") +set(CUDA_BIN_DIR "${CUDAToolkit_ROOT}/bin/" CACHE PATH "") ######################################################################## # sphinx from spack @@ -50,5 +50,3 @@ set(SPHINX_EXECUTABLE "/Users/harrison37/Work/blt_tutorial/tpls/spack/opt/spack/ # doxygen from spack ######################################################################## set(DOXYGEN_EXECUTABLE "/Users/harrison37/Work/blt_tutorial/tpls/spack/opt/spack/darwin-elcapitan-x86_64/clang-7.3.0-apple/doxygen-1.8.12-mji43fu4hxuu6js5irshpihkwwucn7rv/bin/doxygen" CACHE PATH "") - - diff --git a/host-configs/llnl/toss_4_x86_64_ib/gcc@10.3.1_nvcc.cmake b/host-configs/llnl/toss_4_x86_64_ib/gcc@10.3.1_nvcc.cmake index 2a2f93c27..6b7b7a40b 100644 --- a/host-configs/llnl/toss_4_x86_64_ib/gcc@10.3.1_nvcc.cmake +++ b/host-configs/llnl/toss_4_x86_64_ib/gcc@10.3.1_nvcc.cmake @@ -48,12 +48,12 @@ set(MPIEXEC_NUMPROC_FLAG "-n" CACHE PATH "") #_blt_tutorial_cuda_config_start set(ENABLE_CUDA ON CACHE BOOL "") -set(CUDA_TOOLKIT_ROOT_DIR "/usr/tce/packages/cuda/cuda-12.2.2" CACHE PATH "") -set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CUDAToolkit_ROOT "/usr/tce/packages/cuda/cuda-12.2.2" CACHE PATH "") +set(CMAKE_CUDA_COMPILER "${CUDAToolkit_ROOT}/bin/nvcc" CACHE PATH "") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") set(CMAKE_CUDA_FLAGS "-restrict --expt-extended-lambda -G" CACHE STRING "") -set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "" ) +set(CMAKE_CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "" ) #_blt_tutorial_cuda_config_end diff --git a/host-configs/llnl/toss_4_x86_64_ib/llvm@19.1.3_nvcc.cmake b/host-configs/llnl/toss_4_x86_64_ib/llvm@19.1.3_nvcc.cmake new file mode 100644 index 000000000..2cfcad346 --- /dev/null +++ b/host-configs/llnl/toss_4_x86_64_ib/llvm@19.1.3_nvcc.cmake @@ -0,0 +1,74 @@ +# Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for a cluster on a TOSS4 NVidia platform (e.g. matrix) at LLNL +#------------------------------------------------------------------------------ +# +# This file provides CMake with paths / details for: +# C,C++, & Fortran compilers + MPI + CUDA + OpenMP +# +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +set(CMAKE_C_COMPILER "/usr/tce/packages/clang/clang-19.1.3-magic/bin/clang" CACHE PATH "") +set(CMAKE_CXX_COMPILER "/usr/tce/packages/clang/clang-19.1.3-magic/bin/clang++" CACHE PATH "") +set(CMAKE_Fortran_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gfortran" CACHE PATH "") + +set(CMAKE_C_FLAGS "-fPIC" CACHE STRING "") +set(CMAKE_CXX_FLAGS "-fPIC" CACHE STRING "") +set(CMAKE_Fortran_FLAGS "-fPIC" CACHE STRING "") + +set(ENABLE_FORTRAN ON CACHE BOOL "") + +set(BLT_EXE_LINKER_FLAGS " -Xlinker -rpath -Xlinker /usr/tce/packages/clang/clang-19.1.3-magic/lib" CACHE STRING "Adds a missing libstdc++ rpath") + +#------------------------------------------------------------------------------ +# MPI +#------------------------------------------------------------------------------ + +set(MPI_C_COMPILER "/usr/tce/packages/mvapich2/mvapich2-2.3.7-clang-19.1.3/bin/mpicc" CACHE PATH "") + +set(MPI_CXX_COMPILER "/usr/tce/packages/mvapich2/mvapich2-2.3.7-clang-19.1.3/bin/mpicxx" CACHE PATH "") + +set(MPI_Fortran_COMPILER "/usr/tce/packages/mvapich2/mvapich2-2.3.7-clang-19.1.3/bin/mpif90" CACHE PATH "") + +set(MPIEXEC_EXECUTABLE "/usr/bin/srun" CACHE PATH "") + +set(MPIEXEC_NUMPROC_FLAG "-n" CACHE STRING "") + +set(ENABLE_MPI ON CACHE BOOL "") + +#------------------------------------------------ +# Cuda +#------------------------------------------------ + +set(CUDAToolkit_ROOT "/usr/tce/packages/cuda/cuda-12.9.1" CACHE PATH "") + +set(CMAKE_CUDA_COMPILER "${CUDAToolkit_ROOT}/bin/nvcc" CACHE PATH "") + +set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") + +set(CMAKE_CUDA_ARCHITECTURES "90" CACHE STRING "") + +set(CMAKE_CUDA_FLAGS "" CACHE STRING "") + +set(ENABLE_CUDA ON CACHE BOOL "") + +set(CMAKE_CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "") + +set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -restrict --expt-extended-lambda --expt-relaxed-constexpr -Xcompiler=-fPIC " CACHE STRING "" FORCE) + +# nvcc does not like gtest's 'pthreads' flag + +set(gtest_disable_pthreads ON CACHE BOOL "") + +#------------------------------------------------ +# OpenMP +#------------------------------------------------ + +set(ENABLE_OPENMP ON CACHE BOOL "") diff --git a/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake b/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake index 8eb08961a..d03c9f0fc 100644 --- a/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake +++ b/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake @@ -47,12 +47,12 @@ set(MPIEXEC_EXECUTABLE "/sw/summit/xalt/1.2.1/bin/jsrun" CACHE PATH "") #------------------------------------------------------------------------------ set(ENABLE_CUDA ON CACHE BOOL "") -set(CUDA_TOOLKIT_ROOT_DIR "/sw/summit/cuda/10.1.243/" CACHE PATH "") -set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CUDAToolkit_ROOT "/sw/summit/cuda/10.1.243/" CACHE PATH "") +set(CMAKE_CUDA_COMPILER "${CUDAToolkit_ROOT}/bin/nvcc" CACHE PATH "") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") set(CMAKE_CUDA_FLAGS "-restrict --expt-extended-lambda -G" CACHE STRING "") -set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "") +set(CMAKE_CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "") diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 1e6c3ec96..d33680b85 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -159,7 +159,19 @@ if(ENABLE_GTEST) #------------------------------------------------------ # CUDA tests #------------------------------------------------------ - if (ENABLE_CUDA AND CUDA_SEPARABLE_COMPILATION) + if (ENABLE_CUDA) + blt_add_executable( + NAME t_cuda_runtime_compile + SOURCES src/t_cuda_runtime_compile.cpp + DEPENDS_ON blt::cuda_runtime) + + blt_add_executable( + NAME t_cuda_language_compile + SOURCES src/t_cuda_language_compile.cpp + DEPENDS_ON blt::cuda) + endif() + + if (ENABLE_CUDA AND CMAKE_CUDA_SEPARABLE_COMPILATION) add_subdirectory(src/test_cuda_device_call_from_kernel) endif() @@ -356,6 +368,8 @@ if(CLANGFORMAT_FOUND) src/object_library_test/object.hpp src/static_analysis/well_analyzed_source.cpp + src/t_cuda_language_compile.cpp + src/t_cuda_runtime_compile.cpp src/t_example_compile_definitions.cpp src/t_example_smoke.cpp src/t_header_only_smoke.cpp diff --git a/tests/internal/src/t_cuda_language_compile.cpp b/tests/internal/src/t_cuda_language_compile.cpp new file mode 100644 index 000000000..4c9b6e8e8 --- /dev/null +++ b/tests/internal/src/t_cuda_language_compile.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +#include + +#ifndef __CUDACC__ +#error blt::cuda should change C++ sources to CUDA language sources. +#endif + +__global__ void t_cuda_language_compile_kernel(int *value) +{ + *value = 1; +} + +int main() +{ + int *value = nullptr; + cudaError_t result = cudaMalloc(&value, sizeof(int)); + if (result != cudaSuccess) + { + return result == cudaErrorNoDevice ? 0 : 1; + } + + t_cuda_language_compile_kernel<<<1, 1>>>(value); + result = cudaDeviceSynchronize(); + cudaFree(value); + + return result == cudaSuccess ? 0 : 1; +} diff --git a/tests/internal/src/t_cuda_runtime_compile.cpp b/tests/internal/src/t_cuda_runtime_compile.cpp new file mode 100644 index 000000000..06355348a --- /dev/null +++ b/tests/internal/src/t_cuda_runtime_compile.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +#include + +#ifdef __CUDACC__ +#error blt::cuda_runtime should not change C++ sources to CUDA language sources. +#endif + +int main() +{ + int device_count = 0; + cudaError_t result = cudaGetDeviceCount(&device_count); + return result == cudaSuccess || result == cudaErrorNoDevice ? 0 : 1; +} diff --git a/tests/internal/src/test_cuda_mpi.cpp b/tests/internal/src/test_cuda_mpi.cpp index ef639c97e..7aaa3ad48 100644 --- a/tests/internal/src/test_cuda_mpi.cpp +++ b/tests/internal/src/test_cuda_mpi.cpp @@ -104,7 +104,11 @@ int main(int argc, char **argv) hwloc_topology_init(&topology); // Creates a hwloc topology // Gets the topology of the system, including attached devices + #if HWLOC_API_VERSION >= 0x00020000 + hwloc_topology_set_io_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_ALL); + #else hwloc_topology_set_flags(topology, HWLOC_TOPOLOGY_FLAG_WHOLE_IO); + #endif hwloc_topology_load(topology); int cuDevCount = 0; @@ -261,8 +265,8 @@ int main(int argc, char **argv) // No CUDA streams, no party! - cudaStream_t cuStreams[cudaStreams]; - cuChk(cudaStreamCreate(&cuStreams[rank])); + cudaStream_t cuStream; + cuChk(cudaStreamCreate(&cuStream)); // This is needed for pinned memory access cuChk(cudaHostAlloc(&h_buf, bufsize * sizeof(float), cudaHostAllocPortable)); @@ -299,10 +303,10 @@ int main(int argc, char **argv) } cuChk(cudaMemcpy(d_buf, h_buf, bufsize*sizeof(float), cudaMemcpyHostToDevice)); std::cout << "Rank " << rank << ": launching CUDA kernels ... "; - addOne<<>>(d_buf, bufsize); + addOne<<>>(d_buf, bufsize); cudaError_t cuErr = cudaGetLastError(); std::cout << cudaGetErrorString(cuErr) <>>(d_buf, bufsize); + addOne<<>>(d_buf, bufsize); cudaError_t cuErr = cudaGetLastError(); std::cout << cudaGetErrorString(cuErr) < -#include -#include -#include "cuda-clang-cpp.cuh" - -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) - -__global__ void kernel() { - const char arch[] = STR(__CUDA_ARCH__); - printf("Current arch = %s", arch); -} - -void run_kernel() { - kernel<<<1, 1>>>(); - cudaDeviceSynchronize(); -} diff --git a/tests/projects/cuda-arch/base/cuda-clang-cpp.cuh b/tests/projects/cuda-arch/base/cuda-clang-cpp.cuh deleted file mode 100644 index 9d84ece09..000000000 --- a/tests/projects/cuda-arch/base/cuda-clang-cpp.cuh +++ /dev/null @@ -1 +0,0 @@ -void run_kernel(); diff --git a/tests/projects/cuda-arch/downstream/CMakeLists.txt b/tests/projects/cuda-arch/downstream/CMakeLists.txt deleted file mode 100644 index f86ca95dd..000000000 --- a/tests/projects/cuda-arch/downstream/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Clear variables set in the host-config so we can test that they are inherited -# from the upstream project -foreach(_option MPI CUDA HIP OPENMP) - unset(ENABLE_${_option} CACHE) - unset(ENABLE_${_option}) -endforeach() - -cmake_minimum_required(VERSION 3.14) - -project(cuda-clang-cpp-user LANGUAGES CXX) - -# Load BLT -include(${BLT_SOURCE_DIR}/SetupBLT.cmake) - -# Calling find_package sets up the TPL targets needed by the project -# in its argument. -find_package(cuda-clang-cpp REQUIRED - NO_DEFAULT_PATH - PATHS ${base_install_dir}/lib/cmake/cuda-clang-cpp - ${base_install_dir}) - -if (NOT TARGET blt::cuda) - message(FATAL_ERROR "Target cuda was not configured successfully during" - "downstream project configuration.") -endif() - -# Compile a basic example to test correctness of link and compile flags. -blt_add_executable( - NAME hello-cuda - SOURCES cuda-clang-cpp-user.cpp - DEPENDS_ON cuda-clang-cpp blt::cuda -) - -target_include_directories(hello-cuda PUBLIC ${base_install_dir}/include) diff --git a/tests/projects/cuda-arch/downstream/cuda-clang-cpp-user.cpp b/tests/projects/cuda-arch/downstream/cuda-clang-cpp-user.cpp deleted file mode 100644 index 8224e034f..000000000 --- a/tests/projects/cuda-arch/downstream/cuda-clang-cpp-user.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "cuda-clang-cpp.cuh" - -int main() { - // The call below will print out the architecture the upstream project was compiled with, which we - // can verify is different from the architecture used by this project. - std::cout << "Hello from downstream project. Getting cuda arch from upstream: " << std::endl; - run_kernel(); - - return 0; -}