通过使用cmake进行cuda编译来指定cuda架构



我有下面的cmake和cuda代码来生成750个cuda拱门,但是,这总是导致cuda_arch=300(2080 ti,带有cuda 10.1(。我尝试了set_propertytarget_compile_options,但都失败了。在这种情况下,我们是否有cuda_add_executablecuda_add_library的解决方案来使-gencode部分有效

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>)

#include <cstdio>
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
__device__ void print_arch(){
const char my_compile_time_arch[] = STR(__CUDA_ARCH__);
printf("__CUDA_ARCH__: %sn", my_compile_time_arch);
}
__global__ void example()
{
print_arch();
}
int main(){
example<<<1,1>>>();
cudaDeviceSynchronize();
}

将我的评论更改为答案:

project(Hello CUDA) 
enable_language(CUDA) 
set_property(TARGET oounne PROPERTY CUDA_ARCHITECTURES 75)

最新更新