-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_device_query.cu
56 lines (54 loc) · 2.5 KB
/
4_device_query.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cuda_runtime.h>
#include <cuda.h>
#include <iostream>
#include <string>
int main() {
int deviceCount = 0;
// 获取当前机器的GPU数量
cudaError_t error_id = cudaGetDeviceCount(&deviceCount);
if (deviceCount == 0) {
printf("There are no available device(s) that support CUDA\n");
} else {
printf("Detected %d CUDA Capable device(s)\n", deviceCount);
}
for (int dev = 0; dev < deviceCount; ++dev) {
cudaSetDevice(dev);
// 初始化当前device的属性获取对象
cudaDeviceProp deviceProp{};
cudaGetDeviceProperties(&deviceProp, dev);
printf("\nDevice %d: \"%s\"\n", dev, deviceProp.name);
// 显存容量
printf(" Total amount of global memory: %.0f MBytes "
"(%llu bytes)\n",
static_cast<float>((float)deviceProp.totalGlobalMem / 1048576.0f),
(unsigned long long)deviceProp.totalGlobalMem);
// 时钟频率
printf( " GPU Max Clock rate: %.0f MHz (%0.2f "
"GHz)\n",
(float)deviceProp.clockRate * 1e-3f, (float)deviceProp.clockRate * 1e-6f);
// L2 cache大小
printf(" L2 Cache Size: %d bytes\n",
deviceProp.l2CacheSize);
// high-frequent used
// 注释见每个printf内的字符串
printf(" Total amount of shared memory per block: %zu bytes\n",
deviceProp.sharedMemPerBlock);
printf(" Total shared memory per multiprocessor: %zu bytes\n",
deviceProp.sharedMemPerMultiprocessor);
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(" Max dimension size of a block size (x,y,z): (%d, %d, %d)\n",
deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1],
deviceProp.maxThreadsDim[2]);
printf(" Max dimension size of a grid size (x,y,z): (%d, %d, %d)\n",
deviceProp.maxGridSize[0], deviceProp.maxGridSize[1],
deviceProp.maxGridSize[2]);
}
return 0;
}