Skip to content
Open
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
2 changes: 2 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions cmake/BLTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 0 additions & 5 deletions cmake/BLTOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 0 additions & 7 deletions cmake/BLTPrivateMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions cmake/BLTSetupTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
15 changes: 2 additions & 13 deletions cmake/BLTThirdPartyConfigFlags.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
146 changes: 53 additions & 93 deletions cmake/thirdparty/BLTSetupCUDA.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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} <CMAKE_CUDA_LINK_FLAGS> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
# 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 <TARGET>.cu ; ${CMAKE_CUDA_COMPILER} <CMAKE_CUDA_LINK_FLAGS> -std=c++${CMAKE_CUDA_STANDARD} -dc <TARGET>.cu -o <TARGET>")
set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE "touch <TARGET>.cu ; ${CMAKE_CUDA_COMPILER} <CMAKE_CUDA_LINK_FLAGS> -std=c++${CMAKE_CUDA_STANDARD} -dc <TARGET>.cu -o <TARGET>")
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)
Expand All @@ -146,36 +103,39 @@ 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
# leaving it to the default source file language.
# 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)
7 changes: 1 addition & 6 deletions docs/api/target_properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <directory>``.
CMake from de-duplicating grouped flags.


.. _blt_print_target_properties:
Expand Down Expand Up @@ -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.

2 changes: 1 addition & 1 deletion docs/tutorial/calc_pi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorial/common_hpc_dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial/object_libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Loading