Build native arch by default, update rapids-cmake. (#280)

* Build native arch by default, update rapids-cmake.
* Add check that CXX and CUDA_HOST compiler match.
  Similar to CCCL, we need these to match to ensure that our warning flag detection functions properly.
* GCC only recognizes `unused-local-typedefs`.
  Clang recognizes both. Ensure that we set this for both compilers.
This commit is contained in:
Allison Piper
2025-10-21 10:41:36 -04:00
committed by GitHub
parent 98d701c054
commit e6283df79c
4 changed files with 51 additions and 18 deletions

View File

@@ -11,8 +11,13 @@ else()
set(NVBench_TOPLEVEL_PROJECT OFF)
endif()
# Default to native if no cuda arches are specified:
if (NOT (DEFINED CMAKE_CUDA_ARCHITECTURES OR DEFINED ENV{CUDAARCHS}))
set(CMAKE_CUDA_ARCHITECTURES "native")
endif()
include(cmake/NVBenchRapidsCMake.cmake)
nvbench_load_rapids_cmake()
nvbench_load_rapids_cmake(25.12)
project(NVBench
LANGUAGES CUDA CXX

View File

@@ -33,13 +33,46 @@ function(nvbench_add_cxx_flag target_name type flag)
endif()
endfunction()
# We test to see if C++ compiler options exist using try-compiles in the CXX lang, and then reuse those flags as
# -Xcompiler flags for CUDA targets. This requires that the CXX compiler and CUDA_HOST compilers are the same when
# using nvcc.
if (NVBench_TOPLEVEL_PROJECT AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
set(cuda_host_matches_cxx_compiler FALSE)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.31)
set(host_info "${CMAKE_CUDA_HOST_COMPILER} (${CMAKE_CUDA_HOST_COMPILER_ID} ${CMAKE_CUDA_HOST_COMPILER_VERSION})")
set(cxx_info "${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION})")
if (CMAKE_CUDA_HOST_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID AND
CMAKE_CUDA_HOST_COMPILER_VERSION VERSION_EQUAL CMAKE_CXX_COMPILER_VERSION)
set(cuda_host_matches_cxx_compiler TRUE)
endif()
else() # CMake < 3.31 doesn't have the CMAKE_CUDA_HOST_COMPILER_ID/VERSION variables
set(host_info "${CMAKE_CUDA_HOST_COMPILER}")
set(cxx_info "${CMAKE_CXX_COMPILER}")
if (CMAKE_CUDA_HOST_COMPILER STREQUAL CMAKE_CXX_COMPILER)
set(cuda_host_matches_cxx_compiler TRUE)
endif()
endif()
if (NOT cuda_host_matches_cxx_compiler)
message(FATAL_ERROR
"NVBench developer builds require that CMAKE_CUDA_HOST_COMPILER matches "
"CMAKE_CXX_COMPILER when using nvcc:\n"
"CMAKE_CUDA_COMPILER: ${CMAKE_CUDA_COMPILER}\n"
"CMAKE_CUDA_HOST_COMPILER: ${host_info}\n"
"CMAKE_CXX_COMPILER: ${cxx_info}\n"
"Rerun cmake with \"-DCMAKE_CUDA_HOST_COMPILER=${CMAKE_CXX_COMPILER}\".\n"
"Alternatively, configure the CUDAHOSTCXX and CXX environment variables to match.\n"
)
endif()
endif()
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wall")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wextra")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wconversion")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Woverloaded-virtual")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wcast-qual")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wpointer-arith")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wunused-local-typedef")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wunused-local-typedefs")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wunused-parameter")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wvla")
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wgnu")

View File

@@ -1,5 +1,5 @@
# Called before project(...)
macro(nvbench_load_rapids_cmake)
macro(nvbench_load_rapids_cmake version)
# - Including directly, see https://github.com/rapidsai/rmm/pull/1886
# - Versioned download URL:
# https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-XX.YY/RAPIDS.cmake
@@ -7,6 +7,7 @@ macro(nvbench_load_rapids_cmake)
# - we can't just use NVBench_SOURCE_DIR, it's not defined yet.
# - We can't rely on CMAKE_CURRENT_LIST_DIR because of macro expansion.
# - We can fallback to CURRENT_SOURCE_DIR because we know this will be expanded in the root:
set(rapids-cmake-version ${version})
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/RAPIDS.cmake")
include(rapids-cmake)

View File

@@ -16,11 +16,13 @@
#
# This is the preferred entry point for projects using rapids-cmake
#
# Enforce the minimum required CMake version for all users
cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR)
# Allow users to control which version is used
if(NOT rapids-cmake-version)
# Define a default version if the user doesn't set one
set(rapids-cmake-version 25.04)
if(NOT (rapids-cmake-branch OR rapids-cmake-version))
message(FATAL_ERROR "The CMake variable `rapids-cmake-branch` or `rapids-cmake-version` must be defined"
)
endif()
# Allow users to control which GitHub repo is fetched
@@ -66,26 +68,18 @@ if(NOT rapids-cmake-url)
endif()
endif()
if(POLICY CMP0135)
cmake_policy(PUSH)
cmake_policy(SET CMP0135 NEW)
endif()
include(FetchContent)
if(rapids-cmake-fetch-via-git)
FetchContent_Declare(rapids-cmake
GIT_REPOSITORY "${rapids-cmake-url}"
GIT_TAG "${rapids-cmake-value-to-clone}")
FetchContent_Declare(rapids-cmake GIT_REPOSITORY "${rapids-cmake-url}"
GIT_TAG "${rapids-cmake-value-to-clone}")
else()
string(APPEND rapids-cmake-url "${rapids-cmake-value-to-clone}")
FetchContent_Declare(rapids-cmake URL "${rapids-cmake-url}")
endif()
if(POLICY CMP0135)
cmake_policy(POP)
endif()
FetchContent_GetProperties(rapids-cmake)
if(rapids-cmake_POPULATED)
# Something else has already populated rapids-cmake, only thing
# we need to do is setup the CMAKE_MODULE_PATH
# Something else has already populated rapids-cmake, only thing we need to do is setup the
# CMAKE_MODULE_PATH
if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
list(APPEND CMAKE_MODULE_PATH "${rapids-cmake-dir}")
endif()