Commit df98143cfa3e96610fa1e264ce2c3ca336f59390
1 parent
ca41e27d
added CUDA debugging code for individual devices
Showing
1 changed file
with
26 additions
and
5 deletions
Show diff stats
stim/cuda/cudatools/devices.h
1 | -#ifndef RTS_CUDA_DEVICES | ||
2 | -#define RTS_CUDA_DEVICES | 1 | +#ifndef STIM_CUDA_DEVICES |
2 | +#define STIM_CUDA_DEVICES | ||
3 | 3 | ||
4 | #include <cuda.h> | 4 | #include <cuda.h> |
5 | 5 | ||
@@ -35,11 +35,15 @@ namespace stim{ | @@ -35,11 +35,15 @@ namespace stim{ | ||
35 | bool testDevice(int d, int major, int minor){ | 35 | bool testDevice(int d, int major, int minor){ |
36 | int nd; | 36 | int nd; |
37 | cudaGetDeviceCount(&nd); //get the number of CUDA devices | 37 | cudaGetDeviceCount(&nd); //get the number of CUDA devices |
38 | - if(d < nd && d > 0) { //if the given ID has an associated device | 38 | + if(d <= nd && d >= 0) { //if the given ID has an associated device |
39 | cudaDeviceProp props; | 39 | cudaDeviceProp props; |
40 | cudaGetDeviceProperties(&props, d); //get the device properties structure | 40 | cudaGetDeviceProperties(&props, d); //get the device properties structure |
41 | - if(props.major >= major && props.minor >= minor) | ||
42 | - return true; | 41 | + if(props.major > major){ |
42 | + return true; | ||
43 | + } | ||
44 | + else if(props.major == major && props.minor >= minor){ | ||
45 | + return true; | ||
46 | + } | ||
43 | } | 47 | } |
44 | return false; | 48 | return false; |
45 | } | 49 | } |
@@ -54,6 +58,23 @@ namespace stim{ | @@ -54,6 +58,23 @@ namespace stim{ | ||
54 | } | 58 | } |
55 | return valid; | 59 | return valid; |
56 | } | 60 | } |
61 | + | ||
62 | + void printDevice(int device){ | ||
63 | + int nd; | ||
64 | + cudaGetDeviceCount(&nd); //get the number of CUDA devices | ||
65 | + printf("CUDA Device Diagnosis: [%i]\n", device); | ||
66 | + if(device < 0){ | ||
67 | + printf("Device %i is an invalid device ID\n", device); | ||
68 | + } | ||
69 | + else if(device >= nd){ | ||
70 | + printf("Device %i is unavailable - only %i devices are detected", device, nd); | ||
71 | + } | ||
72 | + else{ | ||
73 | + cudaDeviceProp props; | ||
74 | + cudaGetDeviceProperties(&props, device); //get the device properties structure | ||
75 | + printf("compute capability: %i.%i\n", props.major, props.minor); | ||
76 | + } | ||
77 | + } | ||
57 | } //end namespace rts | 78 | } //end namespace rts |
58 | 79 | ||
59 | #endif | 80 | #endif |