From 0a219e89966c2e93a8d585e56487118b6db274eb Mon Sep 17 00:00:00 2001 From: Andre Mueller Date: Wed, 7 Jun 2023 12:09:23 +0200 Subject: [PATCH] CMake: disabled NVCC-specific flags in non-NVCC CUDA builds --- core/CMake/CompilerFlags.cmake | 15 +++++++++++++++ core/CMakeLists.txt | 27 ++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/core/CMake/CompilerFlags.cmake b/core/CMake/CompilerFlags.cmake index b6be0d1f4..5bc525125 100644 --- a/core/CMake/CompilerFlags.cmake +++ b/core/CMake/CompilerFlags.cmake @@ -62,6 +62,21 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") endif() ###################################################################### +######## NVIDIA NVC++ ################################################ +elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "NVHPC") + ### Message + MESSAGE( STATUS ">> Chose compiler: NVC++" ) + ### Compiler Flags + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdpar=multicore" ) + # set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdpar=gpu" ) + # set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdpar=gpu -cuda" ) + # set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -cuda") + # set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -cuda") + # set( CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -cuda") + ### Linker Flags + # set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -cuda" ) +###################################################################### + ######## The End ##################################################### endif() ######## Print flags info diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 34ef0613e..7ee64909d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -143,25 +143,34 @@ if( SPIRIT_USE_CUDA ) # --std=c++17 flag may be necessary, but it is propagated from global flags... # if it appears twice, for some reason the compilation breaks - set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo -arch=${SPIRIT_CUDA_ARCH} --expt-relaxed-constexpr --expt-extended-lambda" ) set( SPIRIT_CUDA_LIBS "${CUDA_LIBRARIES};${CUDA_CUFFT_LIBRARIES};${CUDA_curand_LIBRARY}" ) set( FFT_LIB ${CUDA_CUFFT_LIBRARIES} ) - ### Deactivate CUDA warning inside Eigen such as "warning: __host__ annotation is ignored on a function("Quaternion") that is explicitly defaulted on its first declaration" - set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe=\"--diag_suppress=esa_on_defaulted_function_ignored\"") - ### Display warning number when writing a warning - set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--display_error_number\"" ) + if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "NVHPC" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "NVCC" ) + set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo -arch=${SPIRIT_CUDA_ARCH} --expt-relaxed-constexpr --expt-extended-lambda" ) + ### Deactivate CUDA warning inside Eigen such as "warning: __host__ annotation is ignored on a function("Quaternion") that is explicitly defaulted on its first declaration" + set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe=\"--diag_suppress=esa_on_defaulted_function_ignored\"") + ### Display warning number when writing a warning + set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--display_error_number\"" ) - set( META_COMPILER "${META_COMPILER} and nvcc" ) - set( META_COMPILER_VERSION "${META_COMPILER_VERSION} and ${CUDA_VERSION}" ) - set( META_COMPILER_FULL "${META_COMPILER_FULL} and nvcc (${CUDA_VERSION}) for cuda arch \\\"${SPIRIT_CUDA_ARCH}\\\"" ) + set( META_COMPILER "${META_COMPILER} and nvcc" ) + set( META_COMPILER_VERSION "${META_COMPILER_VERSION} and ${CUDA_VERSION}" ) + set( META_COMPILER_FULL "${META_COMPILER_FULL} and nvcc (${CUDA_VERSION}) for cuda arch \\\"${SPIRIT_CUDA_ARCH}\\\"" ) + else() + # set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -D__STRICT_ANSI__" ) + # set( SPIRIT_COMPILE_DEFINITIONS "${SPIRIT_COMPILE_DEFINITIONS} -D__STRICT_ANSI__" ) + + set( META_COMPILER "${META_COMPILER}" ) + set( META_COMPILER_VERSION "${META_COMPILER_VERSION} and CUDA ${CUDA_VERSION}" ) + set( META_COMPILER_FULL "${META_COMPILER_FULL} and (CUDA ${CUDA_VERSION}) for cuda arch \\\"${SPIRIT_CUDA_ARCH}\\\"" ) + endif() if( NOT DEFINED CMAKE_CUDA_STANDARD ) set( CMAKE_CUDA_STANDARD 17 ) set( CMAKE_CUDA_STANDARD_REQUIRED ON ) endif() - message( STATUS ">> Using CUDA. Flags: ${CUDA_NVCC_FLAGS}" ) + message( STATUS ">> Using CUDA. Flags: ${CMAKE_CUDA_FLAGS}" ) message( STATUS ">> CUDA toolkit path: ${CUDA_TOOLKIT_ROOT_DIR}" ) message( STATUS ">> CUDA libraries: ${SPIRIT_CUDA_LIBS}" ) endif()