cuda 多计算能力支持、指明可见的cuda设备等知识储备

一、cuda 多计算能力支持

对于cuda程序 编译机器和运行机器卡 的卡的类型、计算能力、驱动情况都不尽相同,这就使得其编译时要讲究一下。

一般用比较旧的glibc 免得新机器出现问题。

而且 

CUDA driver version 和 CUDA runtime version 分别指

驱动中支持的CUDA版本和CUDA编译时的版本。

其能运行的条件是 driver version>=runtime version

所以编译时也用稍微低点的cuda toolkit。

同时 指定多个计算能力

-gencode=arch=compute_20,code=sm_20

-gencode=arch=compute_30,code=sm_30

-gencode=arch=compute_35,code=sm_35

扫描二维码关注公众号,回复: 3130405 查看本文章

-gencode=arch=compute_50,code=sm_50

一、指明可见的cuda 设备

设置环境变量CUDA_VISIBLE_DEVICES,指明可见的cuda设备

方法1:

sudo gedit /etc/profile
#或者 sudo gedit ~/.bashrc    #/etc/profile影响所有用户,~/.bashrc影响当前用户使用的bash shell

#在文件末尾添加以下行:
export CUDA_VISIBLE_DEVICES=0,1 ##仅显卡设备0,1GPU可见。可用的GPU可通过nvidia-smi -L命令查看
source /etc/profile             # 使配置文件生效


方法2:若上述配置无效,可在执行cuda程序时指明参数,如

CUDA_VISIBLE_DEVICES=0,1 ./cuda_executable

另附上一些参考文章: http://stackoverflow.com/questions/39649102/how-do-i-select-which-gpu-to-run-a-job-on

Environment Variable Syntax                               Results

CUDA_VISIBLE_DEVICES=1                Only device 1 will be seen

CUDA_VISIBLE_DEVICES=0,1             Devices 0 and 1 will be visible

CUDA_VISIBLE_DEVICES=”0,1”           Same as above, quotation marks are optional

CUDA_VISIBLE_DEVICES=0,2,3          Devices 0, 2, 3 will be visible; device 1 is masked

转于:https://www.cnblogs.com/reedlau/p/5892376.html

猜你喜欢

转载自blog.csdn.net/m0_37644085/article/details/82179102