-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcudaDevices.cu
47 lines (41 loc) · 1.58 KB
/
cudaDevices.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
#include "cudaDevices.cuh"
cudaDevices::cudaDevices()
{
/**
* * Constructor Function
* Prints all CUDA devices.
* No input or return passes.
**/
cout << "Listing all CUDA capable devices:" << endl;
int nDevices;
cudaGetDeviceCount(&nDevices);
for (int i = 0; i < nDevices; i++)
{
/**
* Once a CUDA enabled device has been detected its details will be printed.
* It is advised to check the printed information with the known details of the device to ensure that
* NVIDIA's CUDA toolkit is properly communicating with the query device.
**/
cout << endl;
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, i);
cout << "GPU number\t: " << i << endl;
cout << "GPU name\t: " << prop.name << endl;
size_t l_free = 0;
size_t l_Total = 0;
cudaError_t error_id = cudaMemGetInfo(&l_free, &l_Total);
cout << "GPU memory (GB)\t: " << l_Total / (1000 * 1000 * 1000) << endl;
cout << "GPU number of multiprocessor(s)\t: " << prop.multiProcessorCount << endl;
cout << "GPU block(s) per multiprocessor\t: " << prop.maxBlocksPerMultiProcessor << endl;
cout << "GPU thread(s) per block\t: " << prop.maxThreadsPerBlock << endl;
cout << endl;
/**
* If there is an ERROR in the execution of the CUDA device the error will be printed.
**/
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess)
{
printf("CUDA Error: %s\n", cudaGetErrorString(err));
}
}
}