From 21131ca60cd37cdd306c10781df254e261f27c8a Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Fri, 27 Mar 2020 21:32:38 +0200 Subject: CUDA: Add CudaOnly.CompileFlags test Covers passing compile flags explicitly for both NVCC and Clang. --- Tests/CudaOnly/CMakeLists.txt | 1 + Tests/CudaOnly/CompileFlags/CMakeLists.txt | 16 ++++++++++++++++ Tests/CudaOnly/CompileFlags/main.cu | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 Tests/CudaOnly/CompileFlags/CMakeLists.txt create mode 100644 Tests/CudaOnly/CompileFlags/main.cu diff --git a/Tests/CudaOnly/CMakeLists.txt b/Tests/CudaOnly/CMakeLists.txt index 0b2628c..d74e810 100644 --- a/Tests/CudaOnly/CMakeLists.txt +++ b/Tests/CudaOnly/CMakeLists.txt @@ -1,6 +1,7 @@ ADD_TEST_MACRO(CudaOnly.Architecture Architecture) ADD_TEST_MACRO(CudaOnly.CircularLinkLine CudaOnlyCircularLinkLine) +ADD_TEST_MACRO(CudaOnly.CompileFlags CudaOnlyCompileFlags) ADD_TEST_MACRO(CudaOnly.EnableStandard CudaOnlyEnableStandard) ADD_TEST_MACRO(CudaOnly.ExportPTX CudaOnlyExportPTX) ADD_TEST_MACRO(CudaOnly.GPUDebugFlag CudaOnlyGPUDebugFlag) diff --git a/Tests/CudaOnly/CompileFlags/CMakeLists.txt b/Tests/CudaOnly/CompileFlags/CMakeLists.txt new file mode 100644 index 0000000..cbce7d6 --- /dev/null +++ b/Tests/CudaOnly/CompileFlags/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.17) +cmake_policy(SET CMP0104 OLD) +project(CompileFlags CUDA) + +# Clear defaults. +set(CMAKE_CUDA_ARCHITECTURES) + +add_executable(CudaOnlyCompileFlags main.cu) + +# Try passing CUDA architecture flags explicitly. +if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + target_compile_options(CudaOnlyCompileFlags PRIVATE + -gencode arch=compute_50,code=compute_50 + --compiler-options=-DHOST_DEFINE + ) +endif() diff --git a/Tests/CudaOnly/CompileFlags/main.cu b/Tests/CudaOnly/CompileFlags/main.cu new file mode 100644 index 0000000..573d230 --- /dev/null +++ b/Tests/CudaOnly/CompileFlags/main.cu @@ -0,0 +1,16 @@ +#ifdef __CUDA_ARCH__ +# if __CUDA_ARCH__ != 500 +# error "Passed architecture 50, but got something else." +# endif +#endif + +// Check HOST_DEFINE only for nvcc +#ifndef __CUDA__ +# ifndef HOST_DEFINE +# error "HOST_DEFINE not defined!" +# endif +#endif + +int main() +{ +} -- cgit v0.12