4-1. CUDA
This is a sample code which retrieves CUDA device information and prints the specifications of the GPU devices you will be using.
#include <cuda_runtime_api.h>
#include <iostream>
int main() {
int deviceCount = 0;
cudaError_t error = cudaGetDeviceCount(&deviceCount);
if (error != cudaSuccess) {
std::cerr << "Error getting device count: " << cudaGetErrorString(error) << std::endl;
return -1;
}
std::cout << "Found " << deviceCount << " CUDA capable device(s)" << std::endl;
for (int i = 0; i < deviceCount; i++) {
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, i);
std::cout << "\nDevice " << i << ": \"" << deviceProp.name << "\"" << std::endl;
std::cout << " CUDA Capability Major/Minor version: " << deviceProp.major << "." << deviceProp.minor << std::endl;
std::cout << " Total Global Memory: " << deviceProp.totalGlobalMem / (1024 * 1024) << " MB" << std::endl;
std::cout << " GPU Clock rate: " << deviceProp.clockRate * 1e-3f << " MHz" << std::endl;
std::cout << " Memory Clock rate: " << deviceProp.memoryClockRate * 1e-3f << " MHz" << std::endl;
std::cout << " Memory Bus Width: " << deviceProp.memoryBusWidth << " bits" << std::endl;
std::cout << " L2 Cache Size: " << deviceProp.l2CacheSize / 1024 << " KB" << std::endl;
std::cout << " Max Threads per Block: " << deviceProp.maxThreadsPerBlock << std::endl;
std::cout << " Multiprocessor Count: " << deviceProp.multiProcessorCount << std::endl;
std::cout << " Max Threads per Multiprocessor: " << deviceProp.maxThreadsPerMultiProcessor << std::endl;
std::cout << " Max Grid Size: " << deviceProp.maxGridSize[0] << " x "
<< deviceProp.maxGridSize[1] << " x " << deviceProp.maxGridSize[2] << std::endl;
}
return 0;
}
Last updated
Was this helpful?