AdaptiveOpticsControl
cudacomp.h
Go to the documentation of this file.
1 
15 #ifndef _CUDACOMP_H
16 #define _CUDACOMP_H
17 
18 
19 #ifdef HAVE_CUDA
20 
21 #include <cuda_runtime_api.h>
22 #include <cuda_runtime.h>
23 #include <cublas_v2.h>
24 #include <device_types.h>
25 #include <pthread.h>
26 
27 #endif
28 
29 #ifdef HAVE_CUDA
30 
31 // data passed to each thread
32 typedef struct
33 {
34  int thread_no;
35  long numl0;
36  int cindex; // computation index
37  int_fast8_t *status; // where to white status
38 } THDATA;
39 
40 
41 
49 typedef struct
50 {
51  int_fast8_t init;
52  int_fast8_t *refWFSinit;
53  int_fast8_t alloc;
54  long CM_ID;
55  long CM_cnt;
56  long timerID;
57 
58  uint_fast32_t M;
59  uint_fast32_t N;
60 
61 
63  int_fast8_t sem;
64  int_fast8_t gpuinit;
65 
67  sem_t **semptr1;
68  sem_t **semptr2;
69  sem_t **semptr3;
70  sem_t **semptr4;
71  sem_t **semptr5;
73  // computer memory (host)
74  float *cMat;
75  float **cMat_part;
76  float *wfsVec;
77  float **wfsVec_part;
78  float *wfsRef;
79  float **wfsRef_part;
80  float *dmVec;
81  float *dmVecTMP;
82  float **dmVec_part;
83  float **dmRef_part;
84 
85  // GPU memory (device)
86  float **d_cMat;
87  float **d_wfsVec;
88  float **d_dmVec;
89  float **d_wfsRef;
90  float **d_dmRef;
91 
92  // threads
94  int *iret;
95  pthread_t *threadarray;
96  int_fast8_t NBstreams;
97  cudaStream_t *stream;
98  cublasHandle_t *handle;
99 
100  // splitting limits
101  uint_fast32_t *Nsize;
102  uint_fast32_t *Noffset;
103 
104  int *GPUdevice;
105 
106  int_fast8_t orientation;
107 
108  long IDout;
109 
110 
112 #endif
113 
114 
115 
116 
117 
118 
119 /* =============================================================================================== */
120 /* =============================================================================================== */
124 /* =============================================================================================== */
126 /* =============================================================================================== */
127 
128 
132 int_fast8_t init_cudacomp();
133 
134 
144 int_fast8_t CUDACOMP_init();
145 
146 
147 int_fast8_t GPUcomp_test(long NBact, long NBmodes, long WFSsize, long GPUcnt);
148 
150 
151 
152 
153 
154 
155 #ifdef HAVE_CUDA
156 
157 /* =============================================================================================== */
158 /* =============================================================================================== */
164 /* =============================================================================================== */
166 /* =============================================================================================== */
167 
168 
169 
173 void matrixMulCPU(float *cMat, float *wfsVec, float *dmVec, int M, int N);
174 
175 
176 void *compute_function( void *ptr );
177 
178 
179 int GPUloadCmat(int index);
180 
181 
182 int GPU_loop_MultMat_setup(int index, const char *IDcontrM_name, const char *IDwfsim_name, const char *IDoutdmmodes_name, long NBGPUs, int *GPUdevice, int orientation, int USEsem, int initWFSref, long loopnb);
183 
184 
185 int GPU_loop_MultMat_execute(int index, int_fast8_t *status, int_fast8_t *GPUstatus, float alpha, float beta, int timing);
186 
187 
188 int GPU_loop_MultMat_free(int index);
189 
191 
192 
193 
194 #ifdef HAVE_MAGMA
195 /* =============================================================================================== */
196 /* =============================================================================================== */
200 /* =============================================================================================== */
202 /* =============================================================================================== */
203 
204 
205 long CUDACOMP_MatMatMult_testPseudoInverse(const char *IDmatA_name, const char *IDmatAinv_name, const char *IDmatOut_name);
206 
207 
208 
212 int CUDACOMP_magma_compute_SVDpseudoInverse_SVD(const char *ID_Rmatrix_name, const char *ID_Cmatrix_name, double SVDeps, long MaxNBmodes, const char *ID_VTmatrix_name);
213 
214 
215 
235 int CUDACOMP_magma_compute_SVDpseudoInverse(const char *ID_Rmatrix_name, const char *ID_Cmatrix_name, double SVDeps, long MaxNBmodes, const char *ID_VTmatrix_name, int LOOPmode);
236 
237 
238 
239 int GPU_SVD_computeControlMatrix(int device, const char *ID_Rmatrix_name, const char *ID_Cmatrix_name, double SVDeps, const char *ID_VTmatrix_name);
240 
242 
243 #endif
244 
245 
246 
247 /* =============================================================================================== */
248 /* =============================================================================================== */
252 /* =============================================================================================== */
254 /* =============================================================================================== */
255 
256 
257 int CUDACOMP_Coeff2Map_Loop(const char *IDmodes_name, const char *IDcoeff_name, int GPUindex, const char *IDoutmap_name, int offsetmode, const char *IDoffset_name);
258 
259 
260 
285 int CUDACOMP_extractModesLoop(const char *in_stream, const char *intot_stream, const char *IDmodes_name, const char *IDrefin_name, const char *IDrefout_name, const char *IDmodes_val_name, int GPUindex, int PROCESS, int TRACEMODE, int MODENORM, int insem, int axmode, long twait);
286 
287 
288 
289 #endif
290 
291 
292 #endif
int GPU_loop_MultMat_setup(int index, const char *IDcontrM_name, const char *IDwfsim_name, const char *IDoutdmmodes_name, long NBGPUs, int *GPUdevice, int orientation, int USEsem, int initWFSref, long loopnb)
Definition: cudacomp.c:1066
long timerID
Definition: cudacomp.h:56
int_fast8_t gpuinit
Definition: cudacomp.h:64
int GPU_loop_MultMat_execute(int index, int_fast8_t *status, int_fast8_t *GPUstatus, float alpha, float beta, int timing)
Definition: cudacomp.c:1527
sem_t ** semptr5
Definition: cudacomp.h:71
int CUDACOMP_magma_compute_SVDpseudoInverse(const char *ID_Rmatrix_name, const char *ID_Cmatrix_name, double SVDeps, long MaxNBmodes, const char *ID_VTmatrix_name, int LOOPmode)
Computes matrix pseudo-inverse (AT A)^-1 AT, using eigenvector/eigenvalue decomposition of AT A...
Definition: cudacomp.c:2271
int_fast8_t orientation
Definition: cudacomp.h:106
float ** cMat_part
Definition: cudacomp.h:75
uint_fast32_t M
Definition: cudacomp.h:58
int * GPUdevice
Definition: cudacomp.h:104
sem_t ** semptr3
Definition: cudacomp.h:69
sem_t ** semptr4
Definition: cudacomp.h:70
float * wfsRef
Definition: cudacomp.h:78
long CUDACOMP_MatMatMult_testPseudoInverse(const char *IDmatA_name, const char *IDmatAinv_name, const char *IDmatOut_name)
Test pseudo inverse.
Definition: cudacomp.c:1856
void matrixMulCPU(float *cMat, float *wfsVec, float *dmVec, int M, int N)
CPU-based matrix vector multiplication.
Definition: cudacomp.c:661
int_fast8_t NBstreams
Definition: cudacomp.h:96
int cindex
Definition: cudacomp.h:36
int_fast8_t * status
Definition: cudacomp.h:37
float ** d_wfsVec
Definition: cudacomp.h:87
void * compute_function(void *ptr)
Definition: cudacomp.c:722
int GPU_SVD_computeControlMatrix(int device, const char *ID_Rmatrix_name, const char *ID_Cmatrix_name, double SVDeps, const char *ID_VTmatrix_name)
Definition: cudacomp.c:3257
float ** d_dmRef
Definition: cudacomp.h:90
int thread_no
Definition: cudacomp.h:34
int * iret
Definition: cudacomp.h:94
uint_fast32_t N
Definition: cudacomp.h:59
int_fast8_t alloc
Definition: cudacomp.h:53
float ** dmVec_part
Definition: cudacomp.h:82
uint_fast32_t * Noffset
Definition: cudacomp.h:102
cudaStream_t * stream
Definition: cudacomp.h:97
THDATA * thdata
Definition: cudacomp.h:93
int_fast8_t sem
synchronization
Definition: cudacomp.h:63
float ** d_wfsRef
Definition: cudacomp.h:89
uint_fast32_t * Nsize
Definition: cudacomp.h:101
float ** d_cMat
Definition: cudacomp.h:86
float * wfsVec
Definition: cudacomp.h:76
int_fast8_t GPUcomp_test(long NBact, long NBmodes, long WFSsize, long GPUcnt)
Definition: cudacomp.c:503
int_fast8_t CUDACOMP_init()
Initialize CUDA and MAGMA.
Definition: cudacomp.c:472
long CM_cnt
Definition: cudacomp.h:55
int GPUloadCmat(int index)
Definition: cudacomp.c:1008
float ** dmRef_part
Definition: cudacomp.h:83
Definition: cudacomp.h:32
float * dmVec
Definition: cudacomp.h:80
int CUDACOMP_magma_compute_SVDpseudoInverse_SVD(const char *ID_Rmatrix_name, const char *ID_Cmatrix_name, double SVDeps, long MaxNBmodes, const char *ID_VTmatrix_name)
Compute pseudoinverse using MAGMA-based SVD.
Definition: cudacomp.c:1990
sem_t ** semptr1
one semaphore per thread
Definition: cudacomp.h:67
This structure holds the GPU computation setup for matrix multiplication.
Definition: cudacomp.h:49
long IDout
Definition: cudacomp.h:108
float ** wfsRef_part
Definition: cudacomp.h:79
float ** d_dmVec
Definition: cudacomp.h:88
cublasHandle_t * handle
Definition: cudacomp.h:98
long numl0
Definition: cudacomp.h:35
pthread_t * threadarray
Definition: cudacomp.h:95
sem_t ** semptr2
Definition: cudacomp.h:68
int_fast8_t * refWFSinit
Definition: cudacomp.h:52
int GPU_loop_MultMat_free(int index)
Definition: cudacomp.c:1721
long CM_ID
Definition: cudacomp.h:54
float ** wfsVec_part
Definition: cudacomp.h:77
int_fast8_t init
Definition: cudacomp.h:51
int CUDACOMP_Coeff2Map_Loop(const char *IDmodes_name, const char *IDcoeff_name, int GPUindex, const char *IDoutmap_name, int offsetmode, const char *IDoffset_name)
Definition: cudacomp.c:3687
float * cMat
Definition: cudacomp.h:74
int_fast8_t init_cudacomp()
Initialize cudacomp module and command line interface.
Definition: cudacomp.c:338
float * dmVecTMP
Definition: cudacomp.h:81
int CUDACOMP_extractModesLoop(const char *in_stream, const char *intot_stream, const char *IDmodes_name, const char *IDrefin_name, const char *IDrefout_name, const char *IDmodes_val_name, int GPUindex, int PROCESS, int TRACEMODE, int MODENORM, int insem, int axmode, long twait)
extract mode coefficients from data stream
Definition: cudacomp.c:3999