cacao  Release 0.1.03-dev
Compute And Control For Adaptive Optics
cudacomp.h
Go to the documentation of this file.
1 
13 #ifndef _CUDACOMP_H
14 #define _CUDACOMP_H
15 
16 
17 #ifdef HAVE_CUDA
18 
19 #include <cuda_runtime_api.h>
20 #include <cuda_runtime.h>
21 #include <cublas_v2.h>
22 #include <device_types.h>
23 #include <pthread.h>
24 
25 #endif
26 
27 #ifdef HAVE_CUDA
28 
29 // data passed to each thread
30 typedef struct
31 {
32  int thread_no;
33  long numl0;
34  int cindex; // computation index
35  int_fast8_t *status; // where to white status
36 
37  // timers
38  struct timespec *t0;
39  struct timespec *t1;
40  struct timespec *t2;
41  struct timespec *t3;
42  struct timespec *t4;
43  struct timespec *t5;
44 
45 } THDATA;
46 
47 
48 
56 typedef struct
57 {
58  int8_t init;
59  int8_t *refWFSinit;
60  int8_t alloc;
61  imageID CM_ID;
62  uint64_t CM_cnt;
63  long timerID;
64 
65  uint32_t M;
66  uint32_t N;
67 
68 
70  int_fast8_t
71  sem;
72  int_fast8_t gpuinit;
73 
75  sem_t **semptr1;
76  sem_t **semptr2;
77  sem_t **semptr3;
78  sem_t **semptr4;
79  sem_t **semptr5;
81  // computer memory (host)
82  float *cMat;
83  float **cMat_part;
84  float *wfsVec;
85  float **wfsVec_part;
86  float *wfsRef;
87  float **wfsRef_part;
88  float *dmVec;
89  float *dmVecTMP;
90  float **dmVec_part;
91  float **dmRef_part;
92 
93  // GPU memory (device)
94  float **d_cMat;
95  float **d_wfsVec;
96  float **d_dmVec;
97  float **d_wfsRef;
98  float **d_dmRef;
99 
100  // threads
101  THDATA *thdata;
102  int *iret;
103  pthread_t *threadarray;
104  int NBstreams;
105  cudaStream_t *stream;
106  cublasHandle_t *handle;
107 
108  // splitting limits
109  uint_fast32_t *Nsize;
110  uint_fast32_t *Noffset;
111 
112  int *GPUdevice;
113 
114  int_fast8_t orientation;
115 
116  long IDout;
117 
118 
119 } GPUMATMULTCONF;
120 #endif
121 
122 
123 
124 
125 
126 
127 /* =============================================================================================== */
128 /* =============================================================================================== */
132 /* =============================================================================================== */
134 /* =============================================================================================== */
135 
136 
137 void __attribute__((constructor)) libinit_cudacomp();
138 
142 //errno_t init_cudacomp();
143 
144 
154 int CUDACOMP_init();
155 
156 int CUDACOMP_printGPUMATMULTCONF(int index);
157 
158 errno_t GPUcomp_test(long NBact, long NBmodes, long WFSsize, long GPUcnt);
159 
161 
162 
163 
164 
165 
166 #ifdef HAVE_CUDA
167 
168 /* =============================================================================================== */
169 /* =============================================================================================== */
175 /* =============================================================================================== */
177 /* =============================================================================================== */
178 
179 
180 
182 void matrixMulCPU(float *cMat, float *wfsVec, float *dmVec, int M, int N);
183 
184 
185 void *compute_function(void *ptr);
186 
187 
188 int GPUloadCmat(int index);
189 
190 
193 int GPU_loop_MultMat_setup(
194  int index,
195  const char *IDcontrM_name,
196  const char *IDwfsim_name,
197  const char *IDoutdmmodes_name,
198  long NBGPUs,
199  int *GPUdevice,
200  int orientation,
201  int USEsem,
202  int initWFSref,
203  long loopnb
204 );
205 
206 
207 int GPU_loop_MultMat_execute(
208  int index,
209  int_fast8_t *status,
210  int_fast8_t *GPUstatus,
211  float alpha,
212  float beta,
213  int timing,
214  int TimerOffsetIndex
215 );
216 
217 
218 int GPU_loop_MultMat_free(int index);
219 
221 
222 
223 
224 #ifdef HAVE_MAGMA
225 /* =============================================================================================== */
226 /* =============================================================================================== */
230 /* =============================================================================================== */
232 /* =============================================================================================== */
233 
234 
235 long CUDACOMP_MatMatMult_testPseudoInverse(
236  const char *IDmatA_name,
237  const char *IDmatAinv_name,
238  const char *IDmatOut_name
239 );
240 
241 
242 
246 int CUDACOMP_magma_compute_SVDpseudoInverse_SVD(
247  const char *ID_Rmatrix_name,
248  const char *ID_Cmatrix_name,
249  double SVDeps,
250  long MaxNBmodes,
251  const char *ID_VTmatrix_name
252 );
253 
254 
255 
275 int CUDACOMP_magma_compute_SVDpseudoInverse(
276  const char *ID_Rmatrix_name,
277  const char *ID_Cmatrix_name,
278  double SVDeps,
279  long MaxNBmodes,
280  const char *ID_VTmatrix_name,
281  int LOOPmode,
282  int PSINV_MODE,
283  double qdwh_s,
284  float qdwh_tol,
285  int testmode
286 );
287 
288 
289 
290 int GPU_SVD_computeControlMatrix(
291  int device,
292  const char *ID_Rmatrix_name,
293  const char *ID_Cmatrix_name,
294  double SVDeps,
295  const char *ID_VTmatrix_name
296 );
297 
299 
300 #endif
301 
302 
303 
304 /* =============================================================================================== */
305 /* =============================================================================================== */
309 /* =============================================================================================== */
311 /* =============================================================================================== */
312 
313 
314 int CUDACOMP_Coeff2Map_Loop(const char *IDmodes_name, const char *IDcoeff_name,
315  int GPUindex, const char *IDoutmap_name, int offsetmode,
316  const char *IDoffset_name);
317 
318 
319 errno_t CUDACOMP_MVMextractModesLoop_FPCONF();
320 errno_t CUDACOMP_MVMextractModesLoop_RUN();
321 
347 int CUDACOMP_MVMextractModesLoop(
348  const char *in_stream,
349  const char *intot_stream,
350  const char *IDmodes_name,
351  const char *IDrefin_name,
352  const char *IDrefout_name,
353  const char *IDmodes_val_name,
354  int GPUindex,
355  int PROCESS,
356  int TRACEMODE,
357  int MODENORM,
358  int insem,
359  int axmode,
360  long twait,
361  int semwarn
362 );
363 
364 
365 
366 #endif
367 
368 
369 #endif
errno_t GPUcomp_test(long NBact, long NBmodes, long WFSsize, long GPUcnt)
static struct timespec t1
Definition: processtools.c:146
int errno_t
Definition: AOloopControl_IOtools.h:20
long imageID
Definition: CLIcore.h:54
void __attribute__((constructor)) libinit_cudacomp()
Initialize module.
Definition: ImageStreamIO.c:77
int CUDACOMP_init()
Initialize cudacomp module and command line interface.
static struct timespec t2
Definition: processtools.c:147
int CUDACOMP_printGPUMATMULTCONF(int index)