CUDA ---- device管理
device管理
NVIDIA提供了集中凡是来查询和管理GPU device,掌握GPU信息查询很重要,因为这可以帮助你设置kernel的执行配置。
本博文将主要介绍下面两方面内容:
- CUDA runtime API function
- NVIDIA系统管理命令行
使用runtime API来查询GPU信息
你可以使用下面的function来查询所有关于GPU device 的信息:
cudaError_t cudaGetDeviceProperties(cudaDeviceProp *prop, int device);
GPU的信息放在cudaDeviceProp这个结构体中。
代码
#include <cuda_runtime.h>
#include <stdio.h>
int main(int argc, char **argv) {
printf("%s Starting...\n", argv[]);
int deviceCount = ;
cudaError_t error_id = cudaGetDeviceCount(&deviceCount);
if (error_id != cudaSuccess) {
printf("cudaGetDeviceCount returned %d\n-> %s\n",
(int)error_id, cudaGetErrorString(error_id));
printf("Result = FAIL\n");
exit(EXIT_FAILURE);
}
if (deviceCount == ) {
printf("There are no available device(s) that support CUDA\n");
} else {
printf("Detected %d CUDA Capable device(s)\n", deviceCount);
}
int dev, driverVersion = , runtimeVersion = ;
dev =;
cudaSetDevice(dev);
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, dev);
printf("Device %d: \"%s\"\n", dev, deviceProp.name);
cudaDriverGetVersion(&driverVersion);
cudaRuntimeGetVersion(&runtimeVersion);
printf(" CUDA Driver Version / Runtime Version %d.%d / %d.%d\n",driverVersion/, (driverVersion%)/,runtimeVersion/, (runtimeVersion%)/);
printf(" CUDA Capability Major/Minor version number: %d.%d\n",deviceProp.major, deviceProp.minor);
printf(" Total amount of global memory: %.2f MBytes (%llu bytes)\n",(float)deviceProp.totalGlobalMem/(pow(1024.0,)),(unsigned long long) deviceProp.totalGlobalMem);
printf(" GPU Clock rate: %.0f MHz (%0.2f GHz)\n",deviceProp.clockRate * 1e-3f, deviceProp.clockRate * 1e-6f);
printf(" Memory Clock rate: %.0f Mhz\n",deviceProp.memoryClockRate * 1e-3f);
printf(" Memory Bus Width: %d-bit\n",deviceProp.memoryBusWidth);
if (deviceProp.l2CacheSize) {
printf(" L2 Cache Size: %d bytes\n",
deviceProp.l2CacheSize);
}
printf(" Max Texture Dimension Size (x,y,z) 1D=(%d), 2D=(%d,%d), 3D=(%d,%d,%d)\n",
deviceProp.maxTexture1D , deviceProp.maxTexture2D[],
deviceProp.maxTexture2D[],
deviceProp.maxTexture3D[], deviceProp.maxTexture3D[],
deviceProp.maxTexture3D[]);
printf(" Max Layered Texture Size (dim) x layers 1D=(%d) x %d, 2D=(%d,%d) x %d\n",
deviceProp.maxTexture1DLayered[], deviceProp.maxTexture1DLayered[],
deviceProp.maxTexture2DLayered[], deviceProp.maxTexture2DLayered[],
deviceProp.maxTexture2DLayered[]);
printf(" Total amount of constant memory: %lu bytes\n",deviceProp.totalConstMem);
printf(" Total amount of shared memory per block: %lu bytes\n",deviceProp.sharedMemPerBlock);
printf(" Total number of registers available per block: %d\n",deviceProp.regsPerBlock);
printf(" Warp size: %d\n", deviceProp.warpSize);
printf(" Maximum number of threads per multiprocessor: %d\n",deviceProp.maxThreadsPerMultiProcessor);
printf(" Maximum number of threads per block: %d\n",deviceProp.maxThreadsPerBlock);
printf(" Maximum sizes of each dimension of a block: %d x %d x %d\n",
deviceProp.maxThreadsDim[],
deviceProp.maxThreadsDim[],
deviceProp.maxThreadsDim[]);
printf(" Maximum sizes of each dimension of a grid: %d x %d x %d\n",
deviceProp.maxGridSize[],
deviceProp.maxGridSize[],
deviceProp.maxGridSize[]);
printf(" Maximum memory pitch: %lu bytes\n", deviceProp.memPitch);
exit(EXIT_SUCCESS);
}
编译运行:
$ nvcc checkDeviceInfor.cu -o checkDeviceInfor
$ ./checkDeviceInfor
输出:
./checkDeviceInfor Starting...
Detected CUDA Capable device(s)
Device : "Tesla M2070"
CUDA Driver Version / Runtime Version 5.5 / 5.5
CUDA Capability Major/Minor version number: 2.0
Total amount of global memory: 5.25 MBytes ( bytes)
GPU Clock rate: MHz (1.15 GHz)
Memory Clock rate: Mhz
Memory Bus Width: -bit
L2 Cache Size: bytes
Max Texture Dimension Size (x,y,z) 1D=(), 2D=(,), 3D=(,,)
Max Layered Texture Size (dim) x layers 1D=() x , 2D=(,) x
Total amount of constant memory: bytes
Total amount of shared memory per block: bytes
Total number of registers available per block:
Warp size:
Maximum number of threads per multiprocessor:
Maximum number of threads per block:
Maximum sizes of each dimension of a block: x x
Maximum sizes of each dimension of a grid: x x
Maximum memory pitch: bytes
决定最佳GPU
对于支持多GPU的系统,是需要从中选择一个来作为我们的device的,抉择出最佳计算性能GPU的一种方法就是由其拥有的处理器数量决定,可以用下面的代码来选择最佳GPU。
int numDevices = ;
cudaGetDeviceCount(&numDevices);
if (numDevices > ) {
int maxMultiprocessors = , maxDevice = ;
for (int device=; device<numDevices; device++) {
cudaDeviceProp props;
cudaGetDeviceProperties(&props, device);
if (maxMultiprocessors < props.multiProcessorCount) {
maxMultiprocessors = props.multiProcessorCount;
maxDevice = device;
}
}
cudaSetDevice(maxDevice);
}
使用nvidia-smi来查询GPU信息
nvidia-smi是一个命令行工具,可以帮助你管理操作GPU device,并且允许你查询和更改device状态。
nvidia-smi用处很多,比如,下面的指令:
$ nvidia-smi -L
GPU : Tesla M2070 (UUID: GPU-68df8aec-e85c--2b81-0c9e689a43a7)
GPU : Tesla M2070 (UUID: GPU-382f23c1--01e2--ff9628930b70)
然后可以使用下面的命令来查询GPU 0 的详细信息:
$nvidia-smi –q –i
下面是该命令的一些参数,可以精简nvidia-smi的显示信息:
MEMORY
UTILIZATION
ECC
TEMPERATURE
POWER
CLOCK
COMPUTE
PIDS
PERFORMANCE
SUPPORTED_CLOCKS
PAGE_RETIREMENT
ACCOUNTING
比如,显示只device memory的信息:
$nvidia-smi –q –i –d MEMORY | tail –n
Memory Usage
Total : MB
Used : MB
Free : MB
设置device
对于多GPU系统,使用nvidia-smi可以查看各GPU属性,每个GPU从0开始依次标注,使用环境变量CUDA_VISIBLE_DEVICES可以指定GPU而不用修改application。
可以设置环境变量CUDA_VISIBLE_DEVICES-2来屏蔽其他GPU,这样只有GPU2能被使用。当然也可以使用CUDA_VISIBLE_DEVICES-2,3来设置多个GPU,他们的device ID分别为0和1.
代码下载:CodeSamples.zip
CUDA ---- device管理的更多相关文章
- [转] HTML5+规范:device(管理设备信息)
http://blog.csdn.net/qq_27626333/article/details/51815310 Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号 ...
- BEP 7:CUDA外部内存管理插件(上)
BEP 7:CUDA外部内存管理插件(上) 背景和目标 在CUDA阵列接口使得能够共享不同的Python之间的数据库的访问CUDA设备.但是,每个库都与其它库区别对待.例如: Numba在内部管理内存 ...
- 【CUDA 基础】4.2 内存管理
title: [CUDA 基础]4.2 内存管理 categories: - CUDA - Freshman tags: - CUDA内存管理 - CUDA内存分配和释放 - CUDA内存传输 - 固 ...
- Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明
本文安装显卡驱动的方式已经过时, 最新安装说明请参考发布在Gist上的这篇文章,如有任何疑问,仍然欢迎在本文下留言 :P (本文档使用同一块NVIDIA显卡进行显示与计算, 如分别使用不同的显卡进行显 ...
- CUDA C Best Practices Guide 在线教程学习笔记 Part 2
10. 执行配置优化 ● 一个 SM中,占用率 = 活动线程束的数量 / 最大可能活动线程束的数量.后者保存在设备属性的 maxThreadsPerMultiProcessor 分量中(GTX10 ...
- Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明2
1. 安装build-essentials 安装开发所需要的一些基本包 sudo apt-get install build-essential 2. 安装NVIDIA驱动 (3.4.0) 2.1 准 ...
- Caffe使用: Ubuntu 14.04(x64) 从cuda 7.0 升级到 cuda8.0
由于之前已经在Ubuntu 14.04 x64上面安装cuda7.0+caffe, 并且已经配置好,caffe也已经跑通. 但是最近需要使用Torch,而Torch对cuda的要求是8.0,因此决定对 ...
- Ubuntu14.04 64bit下Caffe + CUDA 6.5安装详细步骤
不多说,直接上干货! 笔者花了很长时间才装完,主要是cuda安装和opencv安装比较费劲,cuda找不到32位的安装包只好重装64位的ubuntu系统,opencv 也是尝试了很久才解决,这里建议用 ...
- Caffe+UbuntuKylin14.04_X64+CUDA 6.5配置
在编译Caffe的漫长过程中,经过了一个又一个坑,掉进去再爬出来,挺有趣的.对比原文有修改! LInux下配置安装:(本文档使用同一块NVIDIA显卡进行显示与计算, 如分别使用不同的显卡进行显示和计 ...
随机推荐
- java List集合中contains方法总是返回false
ArrayList的contains方法 java 今天在用ArrayList类的caontains方法是遇到了问题,我写了一个存放User类的ArrayList 但在调用list.contains( ...
- Android 导入工程文件引用包出错
解决办法:将工程文件夹和引用文件夹需在同一目录下,问题解决.
- Python3.2-re模块之常用正则记录
python的re模块是个很好的模块,这里简单记录下自己编写的几个有用的正则: 1:邮箱匹配: gReMailbox = re.compile(r'([\w\.\-+]+@[\w\-]+(?:\.[\ ...
- mvn dependency:tree
jar依赖冲突解决实践 前言 随着功能的增多,各种中间件的引入.应用以来的各种jar的规模极具膨胀,出现jar冲突和Class冲突的问题层出不穷,让人不胜其扰.本文针对冲突,提供一个排查和定位问题的最 ...
- Oracle-归档日志详解(运行模式、分类)
一.Oracle日志分类 分三大类: Alert log files--警报日志,Trace files--跟踪日志(用户和进程)和 redo log 重做日志(记录数据库的更改 ...
- c# 无边框窗体的边框阴影
Windows API: using System; using System.Collections.Generic; using System.ComponentModel; using Syst ...
- 20155223 Exp8 WEB基础实践
20155223 Exp8 WEB基础实践 基础问题回答 什么是表单? 表单是一个包含表单元素的区域. 表单元素是允许用户在表单中(比如:文本域.下拉列表.单选框.复选框等等)输入信息的元素. 表单使 ...
- 记一次SpringMVC碰到的坑
在SpringMVC中,我们Controller中接收比如表单的参数,只要保证方法的形参的名字和表单中input元素的的name一样就可以接收到参数. 但是,我开发的一 ...
- [c#]记一次实验室局域网的ARP欺骗
起因 某天中午午睡时,笔者被激烈的键盘和鼠标声音吵醒,发现实验室的同学在那边忘我地打LOL,顿觉不爽,于是决定整他一下.想了一下之后觉得就让他掉线一下作为惩罚好了.结合以往的理论知识,大家在同一个局域 ...
- 汇编 OR运算
知识点: OR运算 逻辑或 按位或 一.OR运算 12||1=1; 1||01=1; 0||0=0; || //逻辑或 | //按位或 int _tmain(int argc, _TCHA ...