I have a simple cuda code in ttt.cu
#include <iostream>
__global__ void example(){
printf("__CUDA_ARCH__: %d \n", __CUDA_ARCH__);
}
int main(){
example<<<1,1>>>();
}
with CMakeLists.txt:
cmake_minimum_required(VERSION 3.18)
project(Hello)
find_package(CUDA REQUIRED)
cuda_add_executable(sss ttt.cu)
Then I got the error: identifier "__CUDA_ARCH__" is undefined
. I would like to know why does this happen and what should I do for making the __CUDA_ARCH__
valid? And can we use valid __CUDA_ARCH__
in host code within a header .h
file?
Update:
I intended to use the following cmake for generating a 750 cuda arch, however, this always results in a __CUDA_ARCH__
= 300 (2080 ti with cuda 10.1). I tried both set_property
and target_compile_options
, which all failed.
cmake_minimum_required(VERSION 3.18)
project(Hello)
find_package(CUDA REQUIRED)
cuda_add_executable(oounne ttt.cu)
set_property(TARGET oounne PROPERTY CUDA_ARCHITECTURES 75)
#target_compile_options(oounne PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-gencode
arch=compute_75,code=sm_75>)