Blame view

stim/cuda/cudatools/devices.h 2.2 KB
df98143c   David Mayerich   added CUDA debugg...
1
2
  #ifndef STIM_CUDA_DEVICES
  #define STIM_CUDA_DEVICES
a9275be5   David Mayerich   added vector fiel...
3
4
5
  
  #include <cuda.h>
  
8a86bd56   David Mayerich   changed rts names...
6
  namespace stim{
2a10ecf4   David Mayerich   updated files and...
7
8
9
10
11
12
13
14
  	extern "C"
  	int maxThreadsPerBlock(){
  		int device;
  		cudaGetDevice(&device);		//get the id of the current device
  		cudaDeviceProp props;		//device property structure
  		cudaGetDeviceProperties(&props, device);
  		return props.maxThreadsPerBlock;
  	}
f186dbda   Tianshu Cheng   header file for b...
15
  
2a10ecf4   David Mayerich   updated files and...
16
17
18
19
20
21
22
23
  	extern "C"
  	size_t sharedMemPerBlock(){
  		int device;
  		cudaGetDevice(&device);		//get the id of the current device
  		cudaDeviceProp props;		//device property structure
  		cudaGetDeviceProperties(&props, device);
  		return props.sharedMemPerBlock;
  	}
8e4f8364   David Mayerich   started a new opt...
24
  
2a10ecf4   David Mayerich   updated files and...
25
26
27
28
29
30
31
32
33
34
35
36
37
  	extern "C"
  	size_t constMem(){
  		int device;
  		cudaGetDevice(&device);		//get the id of the current device
  		cudaDeviceProp props;		//device property structure
  		cudaGetDeviceProperties(&props, device);
  		return props.totalConstMem;
  	}
  
  	//tests that a given device ID is valid and provides at least the specified compute capability
  	bool testDevice(int d, int major, int minor){
  		int nd;
  		cudaGetDeviceCount(&nd);		//get the number of CUDA devices
df98143c   David Mayerich   added CUDA debugg...
38
  		if(d <= nd && d >= 0)	{		//if the given ID has an associated device
2a10ecf4   David Mayerich   updated files and...
39
40
  			cudaDeviceProp props;
  			cudaGetDeviceProperties(&props, d);	//get the device properties structure
df98143c   David Mayerich   added CUDA debugg...
41
42
43
44
45
46
  			if(props.major > major){
  				return true;
  			}
  			else if(props.major == major && props.minor >= minor){
  				return true;
  			}
2a10ecf4   David Mayerich   updated files and...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  		}
  		return false;
  	}
  
  	//tests each device ID in a list and returns the number of devices that fit the desired
  	//	compute capability
  	int testDevices(int* dlist, unsigned n_devices, int major, int minor){
  		int valid = 0;
  		for(int d = 0; d < n_devices; d++){
  			if(testDevice(dlist[d], major, minor))
  				valid++;
  		}
  		return valid;
  	}
df98143c   David Mayerich   added CUDA debugg...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
  	void printDevice(int device){
  		int nd;
  		cudaGetDeviceCount(&nd);		//get the number of CUDA devices
  		printf("CUDA Device Diagnosis: [%i]\n", device);
  		if(device < 0){
  			printf("Device %i is an invalid device ID\n", device);
  		}
  		else if(device >= nd){
  			printf("Device %i is unavailable - only %i devices are detected", device, nd);
  		}
  		else{
  			cudaDeviceProp props;
  			cudaGetDeviceProperties(&props, device);	//get the device properties structure
  			printf("compute capability: %i.%i\n", props.major, props.minor);
  		}
  	}
a9275be5   David Mayerich   added vector fiel...
78
79
  }	//end namespace rts
  
8a86bd56   David Mayerich   changed rts names...
80
  #endif