【问题标题】:Specify the cuda architecture by using cmake for cuda compilation使用 cmake 指定 cuda 架构进行 cuda 编译
【发布时间】:2021-12-30 17:02:43
【问题描述】:

我有以下用于生成 750 cuda 拱门的 cmake 和 cuda 代码,但是,这总是导致 CUDA_ARCH = 300(使用 cuda 10.1 时为 2080 ti)。我尝试了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__: %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


【解决方案1】:

将我的评论更改为答案:

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

【讨论】:

    猜你喜欢
    • 2017-01-19
    • 2015-06-05
    • 1970-01-01
    • 2021-08-19
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    相关资源
    最近更新 更多