COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
sutra_controller_utils.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // This file is part of COMPASS <https://anr-compass.github.io/compass/>
3 //
4 // Copyright (C) 2011-2019 COMPASS Team <https://github.com/ANR-COMPASS>
5 // All rights reserved.
6 // Distributed under GNU - LGPL
7 //
8 // COMPASS is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
9 // General Public License as published by the Free Software Foundation, either version 3 of the License,
10 // or any later version.
11 //
12 // COMPASS: End-to-end AO simulation tool using GPU acceleration
13 // The COMPASS platform was designed to meet the need of high-performance for the simulation of AO systems.
14 //
15 // The final product includes a software package for simulating all the critical subcomponents of AO,
16 // particularly in the context of the ELT and a real-time core based on several control approaches,
17 // with performances consistent with its integration into an instrument. Taking advantage of the specific
18 // hardware architecture of the GPU, the COMPASS tool allows to achieve adequate execution speeds to
19 // conduct large simulation campaigns called to the ELT.
20 //
21 // The COMPASS platform can be used to carry a wide variety of simulations to both testspecific components
22 // of AO of the E-ELT (such as wavefront analysis device with a pyramid or elongated Laser star), and
23 // various systems configurations such as multi-conjugate AO.
24 //
25 // COMPASS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
26 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 // See the GNU Lesser General Public License for more details.
28 //
29 // You should have received a copy of the GNU Lesser General Public License along with COMPASS.
30 // If not, see <https://www.gnu.org/licenses/lgpl-3.0.txt>.
31 // -----------------------------------------------------------------------------
32 
40 
41 #ifndef SUTRA_CONTROLLER_UTILS_H_
42 #define SUTRA_CONTROLLER_UTILS_H_
43 
44 #include <sutra_atmos.h>
45 #include <sutra_dm.h>
46 #include <sutra_sensors.h>
47 #include <cstdio>
48 
49 struct gtomo_struct {
50  double DiamTel; // Telescope diameter [m]
51  double obs; // Central obstruction
52  double pasDPHI; // DPHI step
53  long Nw; // Number of WFS
54  long Nx; // Total number of valid ssp
55  long *Nssp; // Number of nxsub for each wfs
56  long *Nsubap; // Number of valid subap for each wfs
57  double *diamPup; // Nssp
58  double *XPup; // 0
59  double *YPup; // 0
60  double *thetaML; // 0
61  double *alphaX; // wfs positions
62  double *alphaY; // wfs positions
63  double *GsAlt; // LGS altitude (0)
64 
65  double lgs_cst; // 0
66  double spot_width; // 1
67  double lgs_depth; // 10000
68  double lgs_alt; // 90000.
69  int nlgs; // 0
70 
71  long *ioff_d; // Cumulative number of nvalid ssp with ioff[0] = 0
72  long *Nssp_d; // Nssp
73  long *Nsubap_d;
74 
75  double *alphaX_d;
76  double *alphaY_d;
77  double *GsAlt_d;
78  double *diamPup_d;
79  double *thetaML_d;
80  double *X_d;
81  double *Y_d;
82  double *XPup_d;
83  double *YPup_d;
84 
85  long max_Nl0;
86  long *indexL0_d;
87  double *L0diff_d;
88  double *h_d;
89  double *cn2_d;
90  double *tabDPHI_d;
91  double *u_d;
92  double *v_d;
93  double *sspSizeL_d;
94 
95  cudaStream_t matcov_stream;
96 };
97 
98 struct cphim_struct {
99  double DiamTel;
100  long Ndphi; // Useless ?
101  long Nlayer;
102  double pasDPHI;
103  double pasDu; // Useless
104  long int_npts;
105  long Nw;
106  long Nx;
107  long Ndm;
108  long Nactu;
109  long *Nactu_tot;
110  long *indLayerDm;
111  long *NlayerDM;
112  long *Nssp;
113  long *Nsubap; // Number of valid subap for each wfs
114  double *diamPup;
115  double *XPup;
116  double *YPup;
117  double *thetaML;
118  double *alphaX;
119  double *alphaY;
120  double *GsAlt;
121  double x0;
122  double y0;
123 
124  double lgs_cst;
125  double spot_width;
126  double lgs_depth;
127  double lgs_alt;
128  int nlgs;
129 
130  long *ioff_d;
131  long *Nssp_d;
132  long *Nactu_tot_d;
134  long *NlayerDM_d;
135  double *alphaX_d;
136  double *alphaY_d;
137  double *GsAlt_d;
138  double *diamPup_d;
139  double *thetaML_d;
140  double *X_d;
141  double *Y_d;
142  double *XPup_d;
143  double *YPup_d;
144 
145  long max_Nl0;
146  long *indexL0_d;
147  long *Nsubap_d; // Number of valid subap for each wfs
148  double *L0diff_d;
149  double *h_d;
150  double *hDm_d;
151  double *cn2_d;
152  double *k2_d;
153  double *tabDPHI_d;
154  double *tab_int_x;
155  double *tab_int_y;
156  double *xact_d;
157  double *yact_d;
158  double *u_d;
159  double *v_d;
160  double *dx_d;
161  double *sspSizeL_d;
162  double FoV;
163 
164  cudaStream_t cphim_stream;
165 };
166 
167 void process_err(cudaError_t e, const char *str);
168 void matts_gpu_gb(double *data, int nrows, int ncols, int xoffset, int yoffset,
169  int lda, struct tomo_struct tomo,
170  struct gtomo_struct *tomo_gpu);
171 void init_tomo_gpu_gb(struct gtomo_struct *tomo_gpu, SutraAtmos *atmos,
172  SutraSensors *sensors, double diamTel, double cobs);
173 void free_tomo_gpu_gb(struct gtomo_struct *tomo_gpu);
174 void update_tomo_atm_gpu_gb(struct gtomo_struct *tomo_gpu,
175  SutraSensors *sensors, SutraAtmos *atmos,
176  double *L0, double *cn2, double *alphaX,
177  double *alphaY);
178 void update_tomo_sys_gpu_gb(struct gtomo_struct *tomo_gpu,
179  SutraSensors *sensors, double *alphaX,
180  double *alphaY);
182  SutraAtmos *atmos, double *L0, double *cn2,
183  double *alphaX, double *alphaY);
185  double *alphaX, double *alphaY, double *xactu,
186  double *yactu, double *X, double *Y, long *NlayerDm,
187  long *indLayerDm, double *alt_dm, double *pitch,
188  double *k2, double FoV);
189 void matcov_gpu_3(double *data, int nrows, int ncols, int xoffset, int yoffset,
190  int lda, struct tomo_struct tomo,
191  struct gtomo_struct *tomo_gpu);
192 void matcov_gpu_4(float *data, int nrows, int ncols, int xoffset, int yoffset,
193  int lda, struct gtomo_struct *tomo_gpu, SutraAtmos *atmos,
194  SutraSensors *sensors, double *alphaX, double *alphaY);
195 void CPHIM(float *data, int nrows, int ncols, int xoffset, int yoffset, int lda,
196  struct cphim_struct *cphim_struct, SutraAtmos *atmos,
197  SutraSensors *sensors, double *alphaX, double *alphaY,
198  CarmaDevice *device);
199 void generateXY(struct gtomo_struct *tomo_gpu, SutraSensors *sensors);
200 void tab_dphi_gpu_gb(double *tab_dphi, struct gtomo_struct *tomo_gpu,
201  long Ndphi, double *L0diff_d, int Nl0, double convert);
202 void sub_pos_gpu_gb(struct gtomo_struct *tomo_gpu, long Nlayer);
203 void sub_pos_cphim(struct cphim_struct *cphim_struct, long Nlayer, long Nw,
204  long Nsubap);
205 void tab_u831J0(double *tab_int_x, double *tab_int_y, long npts);
206 void cuda_zcen(double *idata, double *odata, int N, CarmaDevice *device);
207 void cumsum(double *odata, double *idata, int N);
209  SutraSensors *sensors, SutraDms *dms, double diamTel);
211 void test_DPHI_highpass(double R, double x0, long npts, CarmaDevice *device);
212 
213 #endif // SUTRA_CONTROLLER_UTILS_H_
gtomo_struct::L0diff_d
double * L0diff_d
Definition: sutra_controller_utils.h:87
cphim_struct::XPup
double * XPup
Definition: sutra_controller_utils.h:115
cphim_struct::Y_d
double * Y_d
Definition: sutra_controller_utils.h:141
cphim_struct::YPup
double * YPup
Definition: sutra_controller_utils.h:116
cphim_struct::y0
double y0
Definition: sutra_controller_utils.h:122
cphim_struct::diamPup_d
double * diamPup_d
Definition: sutra_controller_utils.h:138
cphim_struct::alphaY_d
double * alphaY_d
Definition: sutra_controller_utils.h:136
gtomo_struct::matcov_stream
cudaStream_t matcov_stream
Definition: sutra_controller_utils.h:95
cphim_struct::Nsubap
long * Nsubap
Definition: sutra_controller_utils.h:113
cphim_struct::nlgs
int nlgs
Definition: sutra_controller_utils.h:128
init_cphim_struct
void init_cphim_struct(struct cphim_struct *cphim_struct, SutraAtmos *atmos, SutraSensors *sensors, SutraDms *dms, double diamTel)
cumsum
void cumsum(double *odata, double *idata, int N)
cphim_struct::Nssp_d
long * Nssp_d
Definition: sutra_controller_utils.h:131
CarmaDevice
Definition: carma_context.h:57
update_cphim_sys
void update_cphim_sys(struct cphim_struct *cphim_struct, SutraSensors *sensors, double *alphaX, double *alphaY, double *xactu, double *yactu, double *X, double *Y, long *NlayerDm, long *indLayerDm, double *alt_dm, double *pitch, double *k2, double FoV)
gtomo_struct::YPup_d
double * YPup_d
Definition: sutra_controller_utils.h:83
tab_u831J0
void tab_u831J0(double *tab_int_x, double *tab_int_y, long npts)
cphim_struct::max_Nl0
long max_Nl0
Definition: sutra_controller_utils.h:145
cphim_struct::Nw
long Nw
Definition: sutra_controller_utils.h:105
gtomo_struct::Y_d
double * Y_d
Definition: sutra_controller_utils.h:81
gtomo_struct::Nsubap_d
long * Nsubap_d
Definition: sutra_controller_utils.h:73
cphim_struct::NlayerDM
long * NlayerDM
Definition: sutra_controller_utils.h:111
matcov_gpu_4
void matcov_gpu_4(float *data, int nrows, int ncols, int xoffset, int yoffset, int lda, struct gtomo_struct *tomo_gpu, SutraAtmos *atmos, SutraSensors *sensors, double *alphaX, double *alphaY)
cphim_struct::yact_d
double * yact_d
Definition: sutra_controller_utils.h:157
cphim_struct::h_d
double * h_d
Definition: sutra_controller_utils.h:149
test_DPHI_highpass
void test_DPHI_highpass(double R, double x0, long npts, CarmaDevice *device)
gtomo_struct::XPup
double * XPup
Definition: sutra_controller_utils.h:58
SutraDms
Definition: sutra_dm.h:164
gtomo_struct::v_d
double * v_d
Definition: sutra_controller_utils.h:92
cphim_struct
Definition: sutra_controller_utils.h:98
cphim_struct::k2_d
double * k2_d
Definition: sutra_controller_utils.h:152
cphim_struct::XPup_d
double * XPup_d
Definition: sutra_controller_utils.h:142
cphim_struct::ioff_d
long * ioff_d
Definition: sutra_controller_utils.h:130
cphim_struct::X_d
double * X_d
Definition: sutra_controller_utils.h:140
gtomo_struct::obs
double obs
Definition: sutra_controller_utils.h:51
cphim_struct::GsAlt_d
double * GsAlt_d
Definition: sutra_controller_utils.h:137
cphim_struct::Nlayer
long Nlayer
Definition: sutra_controller_utils.h:101
cphim_struct::Nactu_tot_d
long * Nactu_tot_d
Definition: sutra_controller_utils.h:132
cphim_struct::cn2_d
double * cn2_d
Definition: sutra_controller_utils.h:151
update_tomo_sys_gpu_gb
void update_tomo_sys_gpu_gb(struct gtomo_struct *tomo_gpu, SutraSensors *sensors, double *alphaX, double *alphaY)
gtomo_struct::YPup
double * YPup
Definition: sutra_controller_utils.h:59
gtomo_struct::Nx
long Nx
Definition: sutra_controller_utils.h:54
gtomo_struct::alphaY
double * alphaY
Definition: sutra_controller_utils.h:62
gtomo_struct::Nsubap
long * Nsubap
Definition: sutra_controller_utils.h:56
cphim_struct::thetaML_d
double * thetaML_d
Definition: sutra_controller_utils.h:139
cphim_struct::sspSizeL_d
double * sspSizeL_d
Definition: sutra_controller_utils.h:161
cphim_struct::int_npts
long int_npts
Definition: sutra_controller_utils.h:104
SutraAtmos
this class provides the atmos features to COMPASS
Definition: sutra_atmos.h:50
gtomo_struct::diamPup_d
double * diamPup_d
Definition: sutra_controller_utils.h:78
cphim_struct::pasDu
double pasDu
Definition: sutra_controller_utils.h:103
gtomo_struct::thetaML_d
double * thetaML_d
Definition: sutra_controller_utils.h:79
cphim_struct::u_d
double * u_d
Definition: sutra_controller_utils.h:158
cphim_struct::Ndm
long Ndm
Definition: sutra_controller_utils.h:107
gtomo_struct::alphaX_d
double * alphaX_d
Definition: sutra_controller_utils.h:75
cphim_struct::tab_int_x
double * tab_int_x
Definition: sutra_controller_utils.h:154
cphim_struct::FoV
double FoV
Definition: sutra_controller_utils.h:162
free_cphim_struct
void free_cphim_struct(struct cphim_struct *cphim_struct)
cphim_struct::NlayerDM_d
long * NlayerDM_d
Definition: sutra_controller_utils.h:134
gtomo_struct::thetaML
double * thetaML
Definition: sutra_controller_utils.h:60
cphim_struct::indexL0_d
long * indexL0_d
Definition: sutra_controller_utils.h:146
gtomo_struct::Nw
long Nw
Definition: sutra_controller_utils.h:53
cphim_struct::tab_int_y
double * tab_int_y
Definition: sutra_controller_utils.h:155
gtomo_struct::Nssp_d
long * Nssp_d
Definition: sutra_controller_utils.h:72
gtomo_struct::cn2_d
double * cn2_d
Definition: sutra_controller_utils.h:89
sutra_sensors.h
cphim_struct::Nactu
long Nactu
Definition: sutra_controller_utils.h:108
gtomo_struct::indexL0_d
long * indexL0_d
Definition: sutra_controller_utils.h:86
gtomo_struct::sspSizeL_d
double * sspSizeL_d
Definition: sutra_controller_utils.h:93
gtomo_struct::Nssp
long * Nssp
Definition: sutra_controller_utils.h:55
gtomo_struct::h_d
double * h_d
Definition: sutra_controller_utils.h:88
sub_pos_cphim
void sub_pos_cphim(struct cphim_struct *cphim_struct, long Nlayer, long Nw, long Nsubap)
update_tomo_atm_gpu_gb
void update_tomo_atm_gpu_gb(struct gtomo_struct *tomo_gpu, SutraSensors *sensors, SutraAtmos *atmos, double *L0, double *cn2, double *alphaX, double *alphaY)
cphim_struct::lgs_cst
double lgs_cst
Definition: sutra_controller_utils.h:124
gtomo_struct::lgs_depth
double lgs_depth
Definition: sutra_controller_utils.h:67
sutra_atmos.h
CPHIM
void CPHIM(float *data, int nrows, int ncols, int xoffset, int yoffset, int lda, struct cphim_struct *cphim_struct, SutraAtmos *atmos, SutraSensors *sensors, double *alphaX, double *alphaY, CarmaDevice *device)
update_cphim_atm
void update_cphim_atm(struct cphim_struct *cphim_struct, SutraSensors *sensors, SutraAtmos *atmos, double *L0, double *cn2, double *alphaX, double *alphaY)
cphim_struct::spot_width
double spot_width
Definition: sutra_controller_utils.h:125
cphim_struct::alphaY
double * alphaY
Definition: sutra_controller_utils.h:119
gtomo_struct
Definition: sutra_controller_utils.h:49
cphim_struct::alphaX
double * alphaX
Definition: sutra_controller_utils.h:118
gtomo_struct::u_d
double * u_d
Definition: sutra_controller_utils.h:91
cphim_struct::indLayerDm_d
long * indLayerDm_d
Definition: sutra_controller_utils.h:133
gtomo_struct::alphaY_d
double * alphaY_d
Definition: sutra_controller_utils.h:76
init_tomo_gpu_gb
void init_tomo_gpu_gb(struct gtomo_struct *tomo_gpu, SutraAtmos *atmos, SutraSensors *sensors, double diamTel, double cobs)
cphim_struct::dx_d
double * dx_d
Definition: sutra_controller_utils.h:160
gtomo_struct::max_Nl0
long max_Nl0
Definition: sutra_controller_utils.h:85
generateXY
void generateXY(struct gtomo_struct *tomo_gpu, SutraSensors *sensors)
gtomo_struct::GsAlt
double * GsAlt
Definition: sutra_controller_utils.h:63
gtomo_struct::DiamTel
double DiamTel
Definition: sutra_controller_utils.h:50
matcov_gpu_3
void matcov_gpu_3(double *data, int nrows, int ncols, int xoffset, int yoffset, int lda, struct tomo_struct tomo, struct gtomo_struct *tomo_gpu)
cphim_struct::GsAlt
double * GsAlt
Definition: sutra_controller_utils.h:120
SutraSensors
this class provides the sensors features to COMPASS
Definition: sutra_sensors.h:59
cphim_struct::alphaX_d
double * alphaX_d
Definition: sutra_controller_utils.h:135
gtomo_struct::ioff_d
long * ioff_d
Definition: sutra_controller_utils.h:71
cphim_struct::cphim_stream
cudaStream_t cphim_stream
Definition: sutra_controller_utils.h:164
free_tomo_gpu_gb
void free_tomo_gpu_gb(struct gtomo_struct *tomo_gpu)
cphim_struct::Nssp
long * Nssp
Definition: sutra_controller_utils.h:112
gtomo_struct::nlgs
int nlgs
Definition: sutra_controller_utils.h:69
sutra_dm.h
cphim_struct::pasDPHI
double pasDPHI
Definition: sutra_controller_utils.h:102
cphim_struct::Nx
long Nx
Definition: sutra_controller_utils.h:106
gtomo_struct::lgs_alt
double lgs_alt
Definition: sutra_controller_utils.h:68
cphim_struct::x0
double x0
Definition: sutra_controller_utils.h:121
cphim_struct::xact_d
double * xact_d
Definition: sutra_controller_utils.h:156
cphim_struct::diamPup
double * diamPup
Definition: sutra_controller_utils.h:114
cphim_struct::hDm_d
double * hDm_d
Definition: sutra_controller_utils.h:150
gtomo_struct::alphaX
double * alphaX
Definition: sutra_controller_utils.h:61
cphim_struct::YPup_d
double * YPup_d
Definition: sutra_controller_utils.h:143
cphim_struct::lgs_alt
double lgs_alt
Definition: sutra_controller_utils.h:127
matts_gpu_gb
void matts_gpu_gb(double *data, int nrows, int ncols, int xoffset, int yoffset, int lda, struct tomo_struct tomo, struct gtomo_struct *tomo_gpu)
cphim_struct::DiamTel
double DiamTel
Definition: sutra_controller_utils.h:99
sub_pos_gpu_gb
void sub_pos_gpu_gb(struct gtomo_struct *tomo_gpu, long Nlayer)
process_err
void process_err(cudaError_t e, const char *str)
cphim_struct::Ndphi
long Ndphi
Definition: sutra_controller_utils.h:100
gtomo_struct::X_d
double * X_d
Definition: sutra_controller_utils.h:80
cphim_struct::v_d
double * v_d
Definition: sutra_controller_utils.h:159
cphim_struct::tabDPHI_d
double * tabDPHI_d
Definition: sutra_controller_utils.h:153
cphim_struct::Nsubap_d
long * Nsubap_d
Definition: sutra_controller_utils.h:147
gtomo_struct::pasDPHI
double pasDPHI
Definition: sutra_controller_utils.h:52
cphim_struct::Nactu_tot
long * Nactu_tot
Definition: sutra_controller_utils.h:109
gtomo_struct::XPup_d
double * XPup_d
Definition: sutra_controller_utils.h:82
cphim_struct::thetaML
double * thetaML
Definition: sutra_controller_utils.h:117
gtomo_struct::spot_width
double spot_width
Definition: sutra_controller_utils.h:66
cuda_zcen
void cuda_zcen(double *idata, double *odata, int N, CarmaDevice *device)
gtomo_struct::tabDPHI_d
double * tabDPHI_d
Definition: sutra_controller_utils.h:90
cphim_struct::L0diff_d
double * L0diff_d
Definition: sutra_controller_utils.h:148
gtomo_struct::GsAlt_d
double * GsAlt_d
Definition: sutra_controller_utils.h:77
tab_dphi_gpu_gb
void tab_dphi_gpu_gb(double *tab_dphi, struct gtomo_struct *tomo_gpu, long Ndphi, double *L0diff_d, int Nl0, double convert)
gtomo_struct::lgs_cst
double lgs_cst
Definition: sutra_controller_utils.h:65
gtomo_struct::diamPup
double * diamPup
Definition: sutra_controller_utils.h:57
cphim_struct::indLayerDm
long * indLayerDm
Definition: sutra_controller_utils.h:110
cphim_struct::lgs_depth
double lgs_depth
Definition: sutra_controller_utils.h:126