mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-25 22:28:17 +08:00
Sync v13.4-public from internal repo
This commit is contained in:
1
cmake/CudaSampleArchs.cmake
Normal file
1
cmake/CudaSampleArchs.cmake
Normal file
@@ -0,0 +1 @@
|
||||
set(CUDA_SAMPLES_MASTER_ARCHS 75 80 86 87 89 90 100 103 107 110 120)
|
||||
19
cmake/CudaSampleCommon.cmake
Normal file
19
cmake/CudaSampleCommon.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
get_filename_component(_cuda_sample_cmake_dir "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${_cuda_sample_cmake_dir}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${_cuda_sample_cmake_dir}/Modules")
|
||||
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
||||
if(ENABLE_CUDA_DEBUG)
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G")
|
||||
else()
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/Zc:preprocessor>)
|
||||
endif()
|
||||
|
||||
unset(_cuda_sample_cmake_dir)
|
||||
66
cmake/DetectCudaArch.cmake
Normal file
66
cmake/DetectCudaArch.cmake
Normal file
@@ -0,0 +1,66 @@
|
||||
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
|
||||
message(FATAL_ERROR
|
||||
"CMAKE_CUDA_ARCHITECTURES is not set.\n"
|
||||
"For standalone sample builds, specify a target architecture explicitly:\n"
|
||||
" cmake -DCMAKE_CUDA_ARCHITECTURES=<arch> <path-to-sample>\n"
|
||||
"Example: cmake -DCMAKE_CUDA_ARCHITECTURES=90 .")
|
||||
endif()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/CudaSampleArchs.cmake")
|
||||
|
||||
# Master list of all CUDA architectures supported by this repo and CUDA 13.x.
|
||||
# Each sample may define SAMPLE_DISALLOW_ARCHS to exclude architectures it does not support.
|
||||
set(_master_archs ${CUDA_SAMPLES_MASTER_ARCHS})
|
||||
|
||||
# Compute this sample's effective arch list: master minus any disallowed archs.
|
||||
set(_effective_archs ${_master_archs})
|
||||
if(DEFINED SAMPLE_DISALLOW_ARCHS)
|
||||
foreach(_arch ${SAMPLE_DISALLOW_ARCHS})
|
||||
list(REMOVE_ITEM _effective_archs "${_arch}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
get_filename_component(_sample_dir "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
|
||||
|
||||
# CMAKE_CUDA_ARCHITECTURES is set by the top-level CMakeLists.txt (defaulting to the
|
||||
# full master list if the user did not specify). Build only for the intersection with
|
||||
# the effective list; skip the sample if no requested arch is supported.
|
||||
# CMake special keywords (all, all-major, native) are passed through as-is.
|
||||
set(_passthrough_values "all" "all-major" "native")
|
||||
if(CMAKE_CUDA_ARCHITECTURES IN_LIST _passthrough_values)
|
||||
set(_passthrough TRUE)
|
||||
else()
|
||||
set(_passthrough FALSE)
|
||||
endif()
|
||||
|
||||
if(NOT _passthrough)
|
||||
set(_build_archs)
|
||||
foreach(_arch ${CMAKE_CUDA_ARCHITECTURES})
|
||||
if(_arch IN_LIST _effective_archs)
|
||||
list(APPEND _build_archs "${_arch}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT _build_archs)
|
||||
if(NOT CUDA_SAMPLES_ARCHS_DEFAULTED)
|
||||
message(WARNING
|
||||
"Sample in directory '${_sample_dir}' skipped: "
|
||||
"user specified '${CMAKE_CUDA_ARCHITECTURES}' but this sample only supports '${_effective_archs}'")
|
||||
endif()
|
||||
set(SAMPLE_SKIP_BUILD TRUE)
|
||||
elseif(NOT "${_build_archs}" STREQUAL "${CMAKE_CUDA_ARCHITECTURES}" AND NOT CUDA_SAMPLES_ARCHS_DEFAULTED)
|
||||
message(WARNING
|
||||
"Sample in directory '${_sample_dir}': user requested some architecture(s) that are not supported. "
|
||||
"Only building for '${_build_archs}'")
|
||||
set(CMAKE_CUDA_ARCHITECTURES "${_build_archs}")
|
||||
else()
|
||||
set(CMAKE_CUDA_ARCHITECTURES "${_build_archs}")
|
||||
endif()
|
||||
unset(_build_archs)
|
||||
endif()
|
||||
|
||||
unset(_master_archs)
|
||||
unset(_effective_archs)
|
||||
unset(_sample_dir)
|
||||
unset(_passthrough)
|
||||
unset(_passthrough_values)
|
||||
@@ -1,17 +0,0 @@
|
||||
find_path(FreeImage_INCLUDE_DIR
|
||||
NAMES freeimage.h FreeImage.h
|
||||
PATHS /usr/include /usr/local/include
|
||||
)
|
||||
|
||||
find_library(FreeImage_LIBRARY
|
||||
NAMES freeimage FreeImage
|
||||
PATHS /usr/lib /usr/local/lib
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(FreeImage DEFAULT_MSG FreeImage_LIBRARY FreeImage_INCLUDE_DIR)
|
||||
|
||||
if(FreeImage_FOUND)
|
||||
set(FreeImage_LIBRARIES ${FreeImage_LIBRARY})
|
||||
set(FreeImage_INCLUDE_DIRS ${FreeImage_INCLUDE_DIR})
|
||||
endif()
|
||||
136
cmake/toolchains/toolchain-aarch64-qnx-safe.cmake
Normal file
136
cmake/toolchains/toolchain-aarch64-qnx-safe.cmake
Normal file
@@ -0,0 +1,136 @@
|
||||
# Toolchain for QNX Safety builds with the CUDA Safe toolkit (QNX SAFE stack).
|
||||
# Use this file instead of toolchain-aarch64-qnx.cmake for safe-toolkit installs.
|
||||
|
||||
set(CMAKE_SYSTEM_NAME QNX)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(QNX_HOST $ENV{QNX_HOST})
|
||||
set(QNX_TARGET $ENV{QNX_TARGET})
|
||||
|
||||
message(STATUS "QNX_HOST = ${QNX_HOST}")
|
||||
message(STATUS "QNX_TARGET = ${QNX_TARGET}")
|
||||
|
||||
find_program(QNX_QCC NAMES qcc PATHS "${QNX_HOST}/usr/bin")
|
||||
find_program(QNX_QPLUS NAMES q++ PATHS "${QNX_HOST}/usr/bin")
|
||||
|
||||
if(NOT QNX_QCC OR NOT QNX_QPLUS)
|
||||
message(FATAL_ERROR "Could not find qcc or q++ in QNX_HOST=${QNX_HOST}/usr/bin")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_COMPILER ${QNX_QCC})
|
||||
set(CMAKE_CXX_COMPILER ${QNX_QPLUS})
|
||||
|
||||
set(CMAKE_C_COMPILER_TARGET aarch64)
|
||||
set(CMAKE_CXX_COMPILER_TARGET aarch64)
|
||||
|
||||
# Toolkit root: required so CUDA compiler ID test does not expand empty CUDA_ROOT into -I/include, etc.
|
||||
if(CMAKE_CUDA_COMPILER)
|
||||
get_filename_component(_cuda_nvcc_dir "${CMAKE_CUDA_COMPILER}" DIRECTORY)
|
||||
get_filename_component(CUDA_TOOLKIT_ROOT "${_cuda_nvcc_dir}" DIRECTORY)
|
||||
elseif(DEFINED ENV{CUDA_PATH})
|
||||
set(CUDA_TOOLKIT_ROOT "$ENV{CUDA_PATH}")
|
||||
endif()
|
||||
if(CUDA_TOOLKIT_ROOT)
|
||||
set(CUDA_TOOLKIT_ROOT "${CUDA_TOOLKIT_ROOT}" CACHE PATH "CUDA Toolkit root")
|
||||
set(CUDA_ROOT "${CUDA_TOOLKIT_ROOT}" CACHE PATH "CUDA Toolkit root (nvcc / legacy CMake)" FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT __qnx_gcc_ver)
|
||||
set(__qnx_gcc_ver "12.2.0" CACHE STRING "QNX qcc/q++ toolchain version for -V / --qpp-config (match your SDP)")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING "" FORCE)
|
||||
|
||||
set(_cuda_safe_target "aarch64-qnx")
|
||||
|
||||
# CUDA Safe toolkit flags: -safety-compat keeps the kernel-launch ABI consistent; the safe toolkit
|
||||
# ships only a shared cudart (no static/cudadevrt); -I/-L point at its headers/libs;
|
||||
# --unresolved-symbols defers libcudart's rootfs-resident deps (nvdvms_*, NvOs*) to runtime.
|
||||
if(CUDA_TOOLKIT_ROOT)
|
||||
set(_cuda_safe_inc "${CUDA_TOOLKIT_ROOT}/targets/${_cuda_safe_target}/include")
|
||||
set(_cuda_safe_lib "${CUDA_TOOLKIT_ROOT}/targets/${_cuda_safe_target}/lib")
|
||||
set(_cuda_safe_stubs "${CUDA_TOOLKIT_ROOT}/targets/${_cuda_safe_target}/lib/stubs")
|
||||
endif()
|
||||
|
||||
set(_cuda_safe_flags "-safety-compat --cudart=shared --cudadevrt=none -target-dir ${_cuda_safe_target} --qpp-config=${__qnx_gcc_ver},gcc_ntoaarch64le")
|
||||
if(CUDA_TOOLKIT_ROOT)
|
||||
string(APPEND _cuda_safe_flags " -I${_cuda_safe_inc} -L${_cuda_safe_lib} -L${_cuda_safe_stubs}")
|
||||
endif()
|
||||
string(APPEND _cuda_safe_flags " -Xlinker --unresolved-symbols=ignore-in-shared-libs")
|
||||
|
||||
set(CMAKE_C_FLAGS " \"-V${__qnx_gcc_ver},gcc_ntoaarch64le\"")
|
||||
set(CMAKE_CXX_FLAGS " \"-V${__qnx_gcc_ver},gcc_ntoaarch64le\"")
|
||||
# Host .cpp TUs are built by q++ directly, so give them the CUDA include too.
|
||||
if(CUDA_TOOLKIT_ROOT)
|
||||
string(APPEND CMAKE_C_FLAGS " -I${_cuda_safe_inc}")
|
||||
string(APPEND CMAKE_CXX_FLAGS " -I${_cuda_safe_inc}")
|
||||
endif()
|
||||
set(CMAKE_CUDA_FLAGS " ${_cuda_safe_flags}")
|
||||
separate_arguments(_automagic_nvcc_flags UNIX_COMMAND "${_cuda_safe_flags}")
|
||||
set(AUTOMAGIC_NVCC_FLAGS ${_automagic_nvcc_flags}
|
||||
CACHE STRING "automagic feature detection flags for QNX Safe cross build")
|
||||
|
||||
# Safe toolkit has no cudadevrt/static cudart, so disable CMake's implicit runtime libs and link the
|
||||
# shared cudart ourselves. Also link the driver (-lcuda): the shared libcudart.so references safety-
|
||||
# stack symbols (nvdvms_*, NvOs*) that are transitive deps of libcuda.so.1, so the exe must pull in
|
||||
# libcuda for them to resolve/load on the target. STANDARD_LIBRARIES_INIT covers ABI checks; the
|
||||
# HOST_LINK options cover real targets.
|
||||
set(CMAKE_CUDA_RUNTIME_LIBRARY "None" CACHE STRING "CUDA runtime library (safe toolkit: linked manually)")
|
||||
set(CMAKE_CUDA_STANDARD_LIBRARIES_INIT "-lcudart -lcuda")
|
||||
if(CUDA_TOOLKIT_ROOT)
|
||||
add_link_options("$<HOST_LINK:-L${_cuda_safe_lib}>" "$<HOST_LINK:-L${_cuda_safe_stubs}>"
|
||||
"$<HOST_LINK:-lcudart>" "$<HOST_LINK:-lcuda>")
|
||||
endif()
|
||||
|
||||
# -V on the host link only; nvcc would comma-split it at the device link (which uses --qpp-config).
|
||||
add_link_options("$<HOST_LINK:-V${__qnx_gcc_ver}$<COMMA>gcc_ntoaarch64le>")
|
||||
# Defer libcudart's rootfs-resident deps to runtime.
|
||||
add_link_options("-Wl,--unresolved-symbols=ignore-in-shared-libs")
|
||||
|
||||
set(CROSS_COMPILE_FOR_QNX ON CACHE BOOL "Cross compiling for QNX platforms")
|
||||
string(APPEND CMAKE_CXX_FLAGS " -D_QNX_SOURCE")
|
||||
string(APPEND CMAKE_CUDA_FLAGS " -D_QNX_SOURCE")
|
||||
|
||||
# cudaNvSci needs NvSci headers/libs from the QNX safety rootfs; point TARGET_FS at it. This
|
||||
# pre-seeds FindNVSCI's cache vars and auto-detects the header/lib dirs across rootfs layouts.
|
||||
if(DEFINED TARGET_FS)
|
||||
# Expand a leading ~ so paths reach the linker absolute.
|
||||
if(TARGET_FS MATCHES "^~")
|
||||
string(REGEX REPLACE "^~" "$ENV{HOME}" TARGET_FS "${TARGET_FS}")
|
||||
endif()
|
||||
get_filename_component(_nvsci_sdk_root "${TARGET_FS}" DIRECTORY)
|
||||
|
||||
# Header dir varies by rootfs layout.
|
||||
foreach(_inc "${TARGET_FS}/include" "${_nvsci_sdk_root}/include" "${TARGET_FS}/usr/include")
|
||||
if(NOT _nvsci_inc AND EXISTS "${_inc}/nvscibuf.h")
|
||||
set(_nvsci_inc "${_inc}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Lib dir varies by rootfs layout.
|
||||
foreach(_lib "${TARGET_FS}/lib-target" "${TARGET_FS}/usr/libnvidia" "${TARGET_FS}/usr/lib")
|
||||
if(NOT _nvsci_lib AND EXISTS "${_lib}/libnvscibuf.so")
|
||||
set(_nvsci_lib "${_lib}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT _nvsci_inc OR NOT _nvsci_lib)
|
||||
message(FATAL_ERROR
|
||||
"Could not locate NvSci headers/libs from TARGET_FS='${TARGET_FS}'. "
|
||||
"Checked include roots for nvscibuf.h and lib roots for libnvscibuf.so. "
|
||||
"Please set TARGET_FS (or NVSCIBUF/NVSCISYNC cache vars) to a valid QNX safety rootfs.")
|
||||
endif()
|
||||
|
||||
set(NVSCIBUF_INCLUDE_DIR "${_nvsci_inc}" CACHE PATH "NvSciBuf headers (QNX safe)")
|
||||
set(NVSCISYNC_INCLUDE_DIR "${_nvsci_inc}" CACHE PATH "NvSciSync headers (QNX safe)")
|
||||
set(NVSCIBUF_LIBRARY "${_nvsci_lib}/libnvscibuf.so" CACHE FILEPATH "NvSciBuf library (QNX safe)")
|
||||
set(NVSCISYNC_LIBRARY "${_nvsci_lib}/libnvscisync.so" CACHE FILEPATH "NvSciSync library (QNX safe)")
|
||||
|
||||
# rpath-link the rootfs lib dirs so NvSci's transitive deps resolve at link time.
|
||||
foreach(_dir "${_nvsci_lib}" "${TARGET_FS}/lib-target" "${TARGET_FS}/usr/libnvidia" "${TARGET_FS}/usr/lib")
|
||||
if(IS_DIRECTORY "${_dir}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${_dir}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath-link,${_dir}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
@@ -35,3 +35,50 @@ add_link_options("-V${__qnx_gcc_ver},gcc_ntoaarch64le")
|
||||
set(CROSS_COMPILE_FOR_QNX ON CACHE BOOL "Cross compiling for QNX platforms")
|
||||
string(APPEND CMAKE_CXX_FLAGS " -D_QNX_SOURCE")
|
||||
string(APPEND CMAKE_CUDA_FLAGS " -D_QNX_SOURCE")
|
||||
|
||||
# cudaNvSci needs NvSci headers/libs from the QNX rootfs; point TARGET_FS at it. This pre-seeds
|
||||
# FindNVSCI's cache vars and auto-detects the header/lib dirs across rootfs layouts.
|
||||
if(DEFINED TARGET_FS)
|
||||
# Expand a leading ~ so paths reach the linker absolute.
|
||||
if(TARGET_FS MATCHES "^~")
|
||||
string(REGEX REPLACE "^~" "$ENV{HOME}" TARGET_FS "${TARGET_FS}")
|
||||
endif()
|
||||
get_filename_component(_nvsci_sdk_root "${TARGET_FS}" DIRECTORY)
|
||||
|
||||
# Header dir varies by rootfs layout. Both headers are required, so accept a dir only if it
|
||||
# holds both.
|
||||
foreach(_inc "${TARGET_FS}/include" "${_nvsci_sdk_root}/include" "${TARGET_FS}/usr/include")
|
||||
if(NOT _nvsci_inc AND EXISTS "${_inc}/nvscibuf.h" AND EXISTS "${_inc}/nvscisync.h")
|
||||
set(_nvsci_inc "${_inc}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Lib dir varies by rootfs layout. FindNVSCI needs both libraries, so accept a dir only if it
|
||||
# holds both.
|
||||
foreach(_lib "${TARGET_FS}/lib-target" "${TARGET_FS}/usr/libnvidia" "${TARGET_FS}/usr/lib")
|
||||
if(NOT _nvsci_lib AND EXISTS "${_lib}/libnvscibuf.so" AND EXISTS "${_lib}/libnvscisync.so")
|
||||
set(_nvsci_lib "${_lib}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# A rootfs without NvSci is not an error: FindNVSCI then reports NvSci as missing and only the
|
||||
# NvSci samples are skipped.
|
||||
if(_nvsci_inc AND _nvsci_lib)
|
||||
set(NVSCIBUF_INCLUDE_DIR "${_nvsci_inc}" CACHE PATH "NvSciBuf headers")
|
||||
set(NVSCISYNC_INCLUDE_DIR "${_nvsci_inc}" CACHE PATH "NvSciSync headers")
|
||||
set(NVSCIBUF_LIBRARY "${_nvsci_lib}/libnvscibuf.so" CACHE FILEPATH "NvSciBuf library")
|
||||
set(NVSCISYNC_LIBRARY "${_nvsci_lib}/libnvscisync.so" CACHE FILEPATH "NvSciSync library")
|
||||
|
||||
# rpath-link the rootfs lib dirs so NvSci's transitive deps resolve at link time.
|
||||
# NvSci pulls in NvRm/NvOs/NvSciIpc, which can sit in a lib dir of their own.
|
||||
foreach(_dir "${_nvsci_lib}" "${TARGET_FS}/lib-target" "${_nvsci_sdk_root}/lib-target"
|
||||
"${TARGET_FS}/usr/libnvidia" "${TARGET_FS}/usr/lib")
|
||||
if(IS_DIRECTORY "${_dir}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${_dir}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath-link,${_dir}")
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
message(STATUS "NvSci headers/libs not found in TARGET_FS='${TARGET_FS}'")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user