isce3 0.25.0
Loading...
Searching...
No Matches
cudaUtil.h
Go to the documentation of this file.
1
9
10#ifndef __CUDAUTIL_H
11#define __CUDAUTIL_H
12
13#include <cuda_runtime.h>
14#include "cudaError.h"
15
16// for 2D FFT
17#define NRANK 2
18
19//typical choices of number of threads in a block
20// for processing 1D and 2D arrays
21#define NTHREADS 512 //
22#define NTHREADS2D 16 //
23
24#define WARPSIZE 32
25#define MAXTHREADS 1024 //2048 for newer GPUs
26
27#ifdef __FERMI__ //2.0: M2090
28#define MAXBLOCKS 65535 //x
29#define MAXBLOCKS2 65535 //y,z
30#else //2.0 and above : K40, ...
31#define MAXBLOCKS 4294967295 //x
32#define MAXBLOCKS2 65535 //y,z
33#endif
34
35#define IDX2R(i,j,NJ) (((i)*(NJ))+(j)) //row-major order
36#define IDX2C(i,j,NI) (((j)*(NI))+(i)) //col-major order
37
38#define IDIVUP(i,j) ((i+j-1)/j)
39
40#define IMUL(a, b) __mul24(a, b)
41
42#ifndef MAX
43#define MAX(a,b) (a > b ? a : b)
44#endif
45
46#ifndef MIN
47#define MIN(a,b) (a > b ? b: a)
48#endif
49
50// Float To Int conversion
51inline int ftoi(float value)
52{
53 return (value >= 0 ? (int)(value + 0.5) : (int)(value - 0.5));
54}
55
56// compute the next integer in power of 2
57inline int nextpower2(int value)
58{
59 int r=1;
60 while (r<value) r<<=1;
61 return r;
62}
63
64
65// General GPU Device CUDA Initialization
66inline int gpuDeviceInit(int devID)
67{
68 int device_count;
69 checkCudaErrors(cudaGetDeviceCount(&device_count));
70
71 if (device_count == 0)
72 {
73 fprintf(stderr, "gpuDeviceInit() CUDA error: no devices supporting CUDA.\n");
74 exit(EXIT_FAILURE);
75 }
76
77 if (devID < 0 || devID > device_count-1)
78 {
79 fprintf(stderr, "gpuDeviceInit() Device %d is not a valid GPU device. \n", devID);
80 exit(EXIT_FAILURE);
81 }
82
83 checkCudaErrors(cudaSetDevice(devID));
84 printf("Using CUDA Device %d ...\n", devID);
85
86 return devID;
87}
88
89// This function lists all available GPUs
90inline void gpuDeviceList()
91{
92 int device_count = 0;
93 int current_device = 0;
94 cudaDeviceProp deviceProp;
95 checkCudaErrors(cudaGetDeviceCount(&device_count));
96
97 fprintf(stderr, "Detecting all CUDA devices ...\n");
98 if (device_count == 0)
99 {
100 fprintf(stderr, "CUDA error: no devices supporting CUDA.\n");
101 exit(EXIT_FAILURE);
102 }
103
104 while (current_device < device_count)
105 {
106 checkCudaErrors(cudaGetDeviceProperties(&deviceProp, current_device));
107 if (deviceProp.computeMode == cudaComputeModeProhibited)
108 {
109 fprintf(stderr, "CUDA Device [%d]: \"%s\" is not available: device is running in <Compute Mode Prohibited> \n", current_device, deviceProp.name);
110 }
111 else if (deviceProp.major < 1)
112 {
113 fprintf(stderr, "CUDA Device [%d]: \"%s\" is not available: device does not support CUDA \n", current_device, deviceProp.name);
114 }
115 else {
116 fprintf(stderr, "CUDA Device [%d]: \"%s\" is available.\n", current_device, deviceProp.name);
117 }
118 current_device++;
119 }
120}
121
122#endif //__CUDAUTIL_H
123//end of file
Define error checking in cuda calls.

Generated for ISCE3.0 by doxygen 1.13.2.