【发布时间】:2021-12-30 17:02:43
【问题描述】:
我有以下用于生成 750 cuda 拱门的 cmake 和 cuda 代码,但是,这总是导致 CUDA_ARCH = 300(使用 cuda 10.1 时为 2080 ti)。我尝试了set_property 和target_compile_options,都失败了。在这种情况下,我们是否有针对cuda_add_executable 和cuda_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__: %s\n", 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) -
这个很好用,谢谢
-
@kjpus 如果你想提供答案,我会投赞成票。
标签: c++ cmake compilation cuda cmakelists-options