Using CMakes CHECK_CXX_COMPILER_FLAG with nvcc/cuda

Flamefire

I'm trying to compile some coda using CUDA with MakeFiles generated by CMake.

I'd like to use CHECK_CXX_COMPILER_FLAG or something similar to check if the used nvcc version supports a given flag. In my case it is "--expt-relaxed-constexpr" (Cuda 7.5) and "--relaxed-constexpr" (Cuda 7?)

Of course I could compare the CUDA version but I find the compile-flag check more fail-safe.

Is there any CMake command similar to CHECK_CXX_COMPILER_FLAG that invokes the nvcc compiler and not the host compiler?

m.s.

I am not aware of an official way to check for a specific nvcc flag, but you can write a macro yourself rather simply:

CheckNvccCompilerFlag.cmake

MACRO(CHECK_NVCC_COMPILER_FLAG _FLAG _RESULT)
    EXECUTE_PROCESS(COMMAND ${CUDA_NVCC_EXECUTABLE} "${_FLAG}" ERROR_VARIABLE NVCC_OUT)
    IF("${NVCC_OUT}" MATCHES "Unknown option")
        SET(${_RESULT} 0)
    ELSE()
        SET(${_RESULT} 1)
    ENDIF()
ENDMACRO()

A demo use:

CMakeList.txt

PROJECT(cuda_flag_test)
FIND_PACKAGE(CUDA)
INCLUDE(CheckNvccCompilerFlag.cmake)
CHECK_NVCC_COMPILER_FLAG("--asdf" HAS_NVCC_ASDF)
IF(HAS_NVCC_ASDF)
    MESSAGE(STATUS "asdf is supported")
ENDIF()

CHECK_NVCC_COMPILER_FLAG("--relaxed-constexpr" HAS_NVCC_RELAXED_CONSTEXPR)
IF(HAS_NVCC_RELAXED_CONSTEXPR)
    MESSAGE(STATUS "relaxed-constexpr is supported")
ENDIF()

output

...

-- Found CUDA: /opt/cuda (found version "7.0") 
-- relaxed-constexpr is supported

...

(Personally, I would rely on CUDA_VERSION.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using CMakes CHECK_CXX_COMPILER_FLAG with nvcc/cuda

From Dev

Getting CMake CHECK_CXX_COMPILER_FLAG to work

From Dev

When is cmakes add_custom_command POST_BUILD being triggered?

From Dev

How to add global CXX compiler flag to yocto build

From Dev

intel Fortran compiler flag to check for implicit conversion

From Dev

How to control compiler flag invoked when specifing CMAKE_CXX_STANDARD?

From Dev

Checked Exception requires to be handled at compile time using try, catch and finally keywords or else compiler will flag error

From Dev

Why does an extra -I flag (include directory) break compilation? (using Intel Compiler)

From Dev

Quitting BackgroundWorker using flag

From Dev

Is there a C compiler flag to check function modified input parameter?

From Dev

How to check if a mail item has the "Mark Complete" flag set using EWS API

From Dev

Using compiler variables in Swift

From Dev

Using traceur compiler with meteor

From Dev

Detect if a compiler is using ccache

From Dev

Using an Enum as a flag in a class, Python

From Dev

using the find function and the exec flag

From Dev

Using -mod flag in go CLI

From Dev

Reduce dataframe using a running flag

From Dev

The CXX compiler identification is unknown: xcode

From Dev

StanfordCoreNLP compiler errors using javac

From Dev

CMake using 32 or 64 compiler

From Dev

StanfordCoreNLP compiler errors using javac

From Dev

Play audio using online compiler

From Dev

Check box using jQuery

From Dev

Null check using Optional

From Java

Check if user is using IE

From Dev

Using Knockout to check if undefined

From Dev

Check strings using enums

From Java

pattern check using awk

Related Related

HotTag

Archive