Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cuda – 在CMake中确定我需要的nvcc所需的gencode(compute_,arch_)值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在使用CMake作为我的代码的构建系统,它涉及CUDA.我正在虑自动执行决定哪个compute_XX和arch_XX需要传递给我的nvcc以便我当前机器上的GPU编译的任务. >有没有办法做到这一点: >使用NVIDIA GPU部署套件? >没有NVIDIA GPU部署套件? > CMake的FindCUDA可以帮助您确定这些开关的值吗? 我的策略是编译并运行一个bash脚本来探测卡并返
我正在使用CMake作为我的代码的构建系统,它涉及CUDA.我正在自动执行决定哪个compute_XX和arch_XX需要传递给我的nvcc以便我当前机器上的GPU编译的任务.

>有没有办法做到这一点:

>使用NVIDIA GPU部署套件?
>没有NVIDIA GPU部署套件?

> CMake的FindCUDA可以帮助您确定这些开关的值吗?

解决方法

我的策略是编译并运行一个bash脚本来探测卡并返回cmake的gencode.灵感来自 University of Chicago’s SLURM.要处理错误或多个gpus或其他情况,请根据需要进行修改.

在项目文件夹中创建一个文件cudaComputeVersion.bash并确保它可以从sHell执行.进入这个文件放:

#!/bin/bash

# create a 'here document' that is code we compile and use to probe the card
cat << EOF > /tmp/cudaComputeVersion.cu
#include <stdio.h>
int main()
{
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop,0);
int v = prop.major * 10 + prop.minor;
printf("-gencode arch=compute_%d,code=sm_%d\n",v,v);
}
EOF

# probe the card and cleanup
/usr/local/cuda/bin/nvcc /tmp/cudaComputeVersion.cu -o /tmp/cudaComputeVersion
/tmp/cudaComputeVersion
rm /tmp/cudaComputeVersion.cu
rm /tmp/cudaComputeVersion

并在您的CMakeLists.txt中放置:

# at cmake-build-time,probe the card and set a cmake variable
execute_process(COMMAND ${CR_598_11845@AKE_CURRENT_sourcE_DIR}/cudaComputeVersion.bash OUTPUT_VARIABLE GENCODE)
# at project-compile-time,include the gencodE into the compile options
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; "${GENCODE}")

# this makes CMake all chatty and allows you to see that GENCODE was set correctly
set(CMAKE_VERBOSE_MAKEFILE TRUE)

干杯

大佬总结

以上是大佬教程为你收集整理的cuda – 在CMake中确定我需要的nvcc所需的gencode(compute_,arch_)值全部内容,希望文章能够帮你解决cuda – 在CMake中确定我需要的nvcc所需的gencode(compute_,arch_)值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。