#include <stdio.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
int main(void)
{
int device_id = 0;
cudaSetDevice(device_id);
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, device_id);
printf("Device id: %d\n", device_id);
printf("Device name: %s\n", prop.name);
printf("Compute capability: %d.%d\n", prop.major, prop.minor);
printf("Amount of global memory: %g GB\n", prop.totalGlobalMem / (1024.0 * 1024 * 1024));
printf("Amount of constant memory: %g KB\n", prop.totalConstMem / 1024.0);
printf("Maximum grid size: %d %d %d\n", prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]); // 网格的最大尺寸
printf("Maximum block size: %d %d %d\n", prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]); // 块的最大尺寸
printf("Number of SMs: %d\n", prop.multiProcessorCount);
printf("Maximum amount of shared memory per block: %g KB\n", prop.sharedMemPerBlock / 1024.0); // 块内共享内存大小
printf("Maximum amount of shared memory per SM: %g KB\n", prop.sharedMemPerMultiprocessor / 1024.0);
printf("Maximum number of registers per block: %d K\n", prop.regsPerBlock / 1024); // 块内寄存器大小
printf("Maximum number of registers per SM: %d K\n", prop.regsPerMultiprocessor / 1024);
printf("Maximum number of threads per block: %d\n", prop.maxThreadsPerBlock); // 每个GPU块的最大线程数
printf("Maximun number of thread per multiprocesser: %d\n", prop.maxThreadsPerMultiProcessor); // 每个GPU的最大线程数
return 0;
}
CUDA C++ 读取GPU设备信息
于 2023-08-27 22:08:18 首次发布