COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
sutra_wfs.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-2023 COMPASS Team <https://github.com/ANR-COMPASS>
5 // All rights reserved.
6 
7 // -----------------------------------------------------------------------------
8 
16 
17 #ifndef _SUTRA_WFS_H_
18 #define _SUTRA_WFS_H_
19 
20 #include <carma_utils.h>
21 #include <sutra_lgs.h>
22 #include <sutra_phase.h>
23 #include <sutra_target.h>
24 #include <sutra_telemetry.h>
25 #include <sutra_telescope.h>
26 #include <sutra_utils.h>
27 
28 #include <map>
29 #include <vector>
30 //#include <sutra_slopes.h>
31 
32 using std::map;
33 using std::string;
34 
35 class SutraWfs {
36  public:
37  int device;
38  string type;
39  long nxsub;
40  long nvalid;
41  long npix;
42  long nrebin;
43  long nfft;
44  long ntot;
45  long npup;
46  long nphase;
47  long nmaxhr;
48  long nffthr;
49  float subapd;
50  float nphot;
51  float nphot4imat;
52  float noise;
53  bool lgs;
54  bool kernconv;
55  bool roket;
57 
58  bool fakecam;
61 
62  cufftHandle *campli_plan;
63  cufftHandle *fttotim_plan;
68 
81 
83 
85 
87  std::vector<CarmaObj<float> *> d_pupil_ngpu;
88 
90  int nstreams;
91 
97  CarmaObj<float> *d_submask; //field stop
98 
100 
102  int offset;
104  int rank;
107 
108  public:
109  virtual ~SutraWfs(){};
110 
111  int wfs_initgs(CarmaObj<float> *d_lgskern,
112  CarmaObj<cuFloatComplex> *d_ftlgskern,
113  map<vector<int>, cufftHandle *> ftlgskern_plans, float xpos,
114  float ypos, float lambda, float mag, float zerop, long size,
115  float noise, long seed, float G, float thetaML, float dx,
116  float dy);
117  int set_pupil(float *pupil);
118  int set_binimg(float *binimg, int nElem);
119  int set_dark(float *dark, int nElem);
120  int set_flat(float *flat, int nElem);
121  int set_fakecam(bool fakecam);
124 
125  int load_kernels(float *lgskern);
126  int sensor_trace(SutraAtmos *yatmos);
127  int sensor_trace(SutraDms *ydm, int rst);
128  int sensor_trace(SutraAtmos *atmos, SutraDms *ydms);
129  int sensor_trace(int rst);
130  int slopes_geom(float *slopes, int type = 0);
131  int slopes_geom(int type = 0);
132 
133  virtual int fill_binimage(int async) = 0;
134  virtual int comp_image(bool noise = true) = 0;
135 
136  virtual int define_mpi_rank(int rank, int size) = 0;
137  virtual int allocate_buffers(
138  map<vector<int>, cufftHandle *> campli_plans,
139  map<vector<int>, cufftHandle *> fttotim_plans) = 0;
140  int set_noise(float noise, long seed);
141 
142  protected:
143  virtual int comp_generic() = 0;
148  long nvalid, long npix, long nphase, long nrebin, long nfft,
149  long ntot, long npup, float pdiam, float nphotons, float nphot4imat,
150  int lgs, bool fakecam, int max_flux_per_pix, int max_pix_value,
151  bool is_low_order, bool roket, int device);
152 };
153 
154 // General utilities
155 int fillcamplipup(cuFloatComplex *amplipup, float *phase, float *offset,
156  float *mask, float scale, int *istart, int *jstart,
157  int *ivalid, int *jvalid, int nphase, int npup, int Nfft,
158  int Ntot, CarmaDevice *device, int offset_phase);
159 int fillcamplipup(cuFloatComplex *amplipup, cuFloatComplex *phase, float *offset,
160  int *istart, int *jstart,
161  int *ivalid, int *jvalid, int nphase, int N, int Nfft,
162  int Ntot, CarmaDevice *device);
163 int fillfsamplipup(cuFloatComplex *d_odata, float *idata, float *mask, float scale,
164  int Nfft, int N, CarmaDevice *device);
165 int indexfill(cuFloatComplex *d_odata, cuFloatComplex *d_idata, int *indx,
166  int nx, int Nx, int N, CarmaDevice *device);
167 int fillbincube(float *bcube, cuFloatComplex *hrimage, int *indxpix, int Nfft,
168  int Npix, int Nrebin, int Nsub, CarmaDevice *device);
169 int fillbincube_async(CarmaStreams *streams, float *bcube,
170  cuFloatComplex *hrimage, int *indxpix, int Nfft, int Npix,
171  int Nrebin, int Nsub, CarmaDevice *device);
172 int fillbinimg(float *bimage, float *bcube, int npix, int nsub, int Nsub,
173  int *ivalid, int *jvalid, bool add, CarmaDevice *device);
175  CarmaObj<float> *bcube, int npix, int nsub, int Nsub,
176  int *ivalid, int *jvalid, bool add, CarmaDevice *device);
177 int fillbinimg_async(CarmaHostObj<float> *image_telemetry, float *bimage,
178  float *bcube, int npix, int nsub, int Nsub, int *ivalid,
179  int *jvalid, int nim, bool add, CarmaDevice *device);
180 int convolve_cube(cuFloatComplex *d_odata, cuFloatComplex *d_idata, int N,
181  int n, CarmaDevice *device);
182 template <class T>
183 int digitalize(T *camimg, float *binimg, float *dark, float *flat,
184  int max_flux_per_pix, int max_pix_value, int N, CarmaDevice *device);
185 // CUDA templates
186 // this is for cog
187 template <class T>
188 void subap_reduce(int size, int threads, int blocks, T *d_idata, T *d_odata,
189  CarmaDevice *device);
190 
191 template <class T>
192 void subap_reduce_async(int threads, int blocks, CarmaStreams *streams,
193  T *d_idata, T *d_odata);
194 // this is for tcog
195 template <class T>
196 void subap_reduce(int size, int threads, int blocks, T *d_idata, T *d_odata,
197  T thresh, CarmaDevice *device);
198 // this is for tcog_new
199 template <class T>
200 void subap_reduce_new(int size, int threads, int blocks, T *d_idata, T *d_odata,
201  T thresh, CarmaDevice *device);
202 // this is for wcog
203 template <class T>
204 void subap_reduce(int size, int threads, int blocks, T *d_idata, T *d_odata,
205  T *weights, CarmaDevice *device);
206 
207 template <class T>
208 void phase_reduce(int threads, int blocks, T *d_idata, T *d_odata, int *indx,
209  T alpha);
210 
211 template <class T>
212 void phase_derive(int size, int threads, int blocks, int n, T *d_idata,
213  T *d_odata, int *indx, T *mask, T alpha, float *fluxPerSub);
214 
215 template <class T>
216 void phase_project(int nphase, int nvalid, T *d_idata, T *d_odata, int *indx,
217  T *d_ttprojmat, T *d_ttprojvec, CarmaDevice *device);
218 
219 template <class Tout, class Tin>
220 void pyr_getpup(Tout *d_odata, Tin *d_idata, Tout *d_offsets, Tin *d_pup,
221  int np, float lambda, CarmaDevice *device);
222 
223 template <class Tout, class Tin>
224 void pyr_getpup(Tout *d_odata, Tin *d_idata, Tin *d_pup, int np, int N,
225  float lambda, float cx, float cy, CarmaDevice *device);
226 
227 template <class T>
228 void pyr_rollmod(T *d_odata, T *d_idata, T *d_mask, float cx, float cy, int np,
229  int ns, CarmaDevice *device);
230 
231 template <class T>
232 void pyr_fillbin(T *d_odata, T *d_idata, int nrebin, int np, int ns, int nim,
233  CarmaDevice *device);
234 
235 template <class T>
236 int pyr_fillbinimg(T *bimage, const T *bcube, const int nxsub, const bool add,
237  CarmaDevice *device);
238 
239 template <class T>
240 int pyr_fillbinimg(T *oimage, const T *image, const int n, const int N,
241  const int rebin, const bool add, CarmaDevice *device);
242 
243 template <class Tin, class Tout>
244 void pyr_abs2(Tout *d_odata, Tin *d_idata, Tout fact, int ns, int nim,
245  CarmaDevice *device);
246 
247 template <class Tout, class Tin>
248 void apply_submask(Tout *d_odata, Tin *d_mask, int n, CarmaDevice *device);
249 
250 template <class T>
251 void pyr_submaskpyr(T *d_odata, T *d_mask, int n, CarmaDevice *device);
252 
253 template <class T>
254 void pyr_submaskpyr(T *d_odata, float *d_mask, int n, CarmaDevice *device);
255 
256 template <class Tout, class Tin>
257 void pyr_abs(Tout *d_odata, Tin *d_idata, int ns, int nim,
258  CarmaDevice *device);
259 
260 template <class Tout, class Tin>
261 void pyr_submask3d(Tout *d_odata, Tin *d_mask, int n, int nim,
262  CarmaDevice *device);
263 
264 template <class T>
265 void pyr_intensities(T *d_odata, T *d_idata, int *subindx, int *subindy, int ns,
266  int nvalid, int nim, CarmaDevice *device);
267 
268 template <class T>
269 void pyr_intensities(T *d_odata, T *d_idata, int *subindx, int *subindy, int ns,
270  int nvalid, CarmaDevice *device);
271 
272 template <class T>
273 void pyr_fact(T *d_data, T fact, int n, int nim, CarmaDevice *device);
274 
275 void pyr_fact(cuFloatComplex *d_data, float fact, int n, int nim,
276  CarmaDevice *device);
277 void pyr_fact(float *d_data, float fact1, float *fact2, int n, int nim,
278  CarmaDevice *device);
279 
280 template <class Tin, class Tout>
281 void roof_abs2(Tout *d_odata, Tin *d_idata, Tout fact, int ns, int nim,
282  CarmaDevice *device);
283 
284 template <class T>
285 void roof_intensities(T *d_odata, T *d_idata, int *subindx, int *subindy,
286  int ns, int nvalid, int nim, CarmaDevice *device);
287 
288 template <class T>
289 void roof_rollmod(T *d_odata, T *d_idata, T *d_mask, float cx, float cy, int np,
290  int ns, CarmaDevice *device);
291 
292 template <class T>
293 void roof_fillbin(T *d_odata, T *d_idata, int nrebin, int np, int ns, int nim,
294  CarmaDevice *device);
295 
296 void copy_imgin_binimg(float *binimg, int *validsubsx, int *validsubsy, int Nb,
297  float *img, int *validx, int *validy, int Nim, int Npix,
298  CarmaDevice *device);
299 
300 #endif // _SUTRA_WFS_H_
this file provides tools to CarmaObj
this class provides the context in which CarmaObj are created
Definition: carma_context.h:79
this class provides the stream features to CarmaObj
Definition: carma_streams.h:24
this class provides the atmos features to COMPASS
Definition: sutra_atmos.h:25
this class provides the source features to COMPASS
Definition: sutra_source.h:37
this class provides the telescope features to COMPASS
this class provides the wfs features to COMPASS
Definition: sutra_wfs.h:35
CarmaObj< float > * d_ttprojmat
Definition: sutra_wfs.h:93
std::vector< CarmaObj< float > * > d_pupil_ngpu
Definition: sutra_wfs.h:87
virtual ~SutraWfs()
Definition: sutra_wfs.h:109
CarmaObj< float > * d_binimg_notnoisy
Definition: sutra_wfs.h:72
CarmaStreams * streams
Definition: sutra_wfs.h:89
float subapd
Definition: sutra_wfs.h:49
cufftHandle * fttotim_plan
Definition: sutra_wfs.h:63
int slopes_geom(float *slopes, int type=0)
int max_pix_value
Definition: sutra_wfs.h:60
float nphot4imat
Definition: sutra_wfs.h:51
bool lgs
Definition: sutra_wfs.h:53
long nfft
Definition: sutra_wfs.h:43
int * displ_bincube
Definition: sutra_wfs.h:105
CarmaObj< float > * d_dark
Definition: sutra_wfs.h:79
float nphot
Definition: sutra_wfs.h:50
int set_binimg(float *binimg, int nElem)
CarmaObj< float > * d_sincar
Definition: sutra_wfs.h:76
CarmaObj< int > * d_hrmap
Definition: sutra_wfs.h:77
CarmaObj< float > * d_submask
Definition: sutra_wfs.h:97
int nstreams
Definition: sutra_wfs.h:90
int set_dark(float *dark, int nElem)
CarmaObj< float > * d_slopes
Definition: sutra_wfs.h:82
int load_kernels(float *lgskern)
bool roket
Definition: sutra_wfs.h:55
CarmaObj< float > * d_intensities
Definition: sutra_wfs.h:73
long npix
Definition: sutra_wfs.h:41
CarmaObj< cuFloatComplex > * d_fttotim
Definition: sutra_wfs.h:67
cufftHandle * campli_plan
Definition: sutra_wfs.h:62
CarmaObj< cuFloatComplex > * d_camplifoc
Definition: sutra_wfs.h:66
int max_flux_per_pix
Definition: sutra_wfs.h:59
string type
Definition: sutra_wfs.h:38
int sensor_trace(int rst)
CarmaObj< uint16_t > * d_camimg
Definition: sutra_wfs.h:78
bool is_low_order
Definition: sutra_wfs.h:56
long nrebin
Definition: sutra_wfs.h:42
int set_max_flux_per_pix(int max_flux_per_pix)
CarmaObj< int > * d_validsubsy
Definition: sutra_wfs.h:96
CarmaContext * current_context
Definition: sutra_wfs.h:99
int sensor_trace(SutraDms *ydm, int rst)
int rank
Definition: sutra_wfs.h:104
long nvalid
Definition: sutra_wfs.h:40
int * count_bincube
Definition: sutra_wfs.h:106
int set_pupil(float *pupil)
int set_max_pix_value(int max_pix_value)
int nvalid_tot
Definition: sutra_wfs.h:103
CarmaObj< float > * d_offsets
Definition: sutra_wfs.h:74
int set_flat(float *flat, int nElem)
int sensor_trace(SutraAtmos *atmos, SutraDms *ydms)
CarmaObj< float > * d_flat
Definition: sutra_wfs.h:80
CarmaObj< float > * d_ttprojvec
Definition: sutra_wfs.h:94
bool kernconv
Definition: sutra_wfs.h:54
int slopes_geom(int type=0)
virtual int allocate_buffers(map< vector< int >, cufftHandle * > campli_plans, map< vector< int >, cufftHandle * > fttotim_plans)=0
CarmaObj< float > * d_binimg
Definition: sutra_wfs.h:71
long ntot
Definition: sutra_wfs.h:44
CarmaObj< float > * d_pupil
Definition: sutra_wfs.h:69
long nphase
Definition: sutra_wfs.h:46
CarmaObj< cuFloatComplex > * d_camplipup
Definition: sutra_wfs.h:65
CarmaHostObj< float > * image_telemetry
Definition: sutra_wfs.h:84
long nxsub
Definition: sutra_wfs.h:39
int wfs_initgs(CarmaObj< float > *d_lgskern, CarmaObj< cuFloatComplex > *d_ftlgskern, map< vector< int >, cufftHandle * > ftlgskern_plans, float xpos, float ypos, float lambda, float mag, float zerop, long size, float noise, long seed, float G, float thetaML, float dx, float dy)
CarmaObj< cuFloatComplex > * d_ftkernel
Definition: sutra_wfs.h:64
CarmaObj< int > * d_phasemap
Definition: sutra_wfs.h:92
SutraWfs(CarmaContext *context, SutraTelescope *d_tel, CarmaObj< cuFloatComplex > *d_camplipup, CarmaObj< cuFloatComplex > *d_camplifoc, CarmaObj< cuFloatComplex > *d_fttotim, string type, long nxsub, long nvalid, long npix, long nphase, long nrebin, long nfft, long ntot, long npup, float pdiam, float nphotons, float nphot4imat, int lgs, bool fakecam, int max_flux_per_pix, int max_pix_value, bool is_low_order, bool roket, int device)
virtual int comp_generic()=0
CarmaObj< int > * d_validsubsx
Definition: sutra_wfs.h:95
virtual int comp_image(bool noise=true)=0
SutraSource * d_gs
Definition: sutra_wfs.h:86
int offset
MPI stuff.
Definition: sutra_wfs.h:102
int set_noise(float noise, long seed)
bool fakecam
Definition: sutra_wfs.h:58
long nffthr
Definition: sutra_wfs.h:48
int set_fakecam(bool fakecam)
float noise
Definition: sutra_wfs.h:52
CarmaObj< float > * d_fluxPerSub
Definition: sutra_wfs.h:75
int device
Definition: sutra_wfs.h:37
virtual int define_mpi_rank(int rank, int size)=0
int sensor_trace(SutraAtmos *yatmos)
virtual int fill_binimage(int async)=0
CarmaObj< float > * d_bincube
Definition: sutra_wfs.h:70
long npup
Definition: sutra_wfs.h:45
long nmaxhr
Definition: sutra_wfs.h:47
int pyr_fillbinimg(T *bimage, const T *bcube, const int nxsub, const bool add, CarmaDevice *device)
void phase_reduce(int threads, int blocks, T *d_idata, T *d_odata, int *indx, T alpha)
void roof_rollmod(T *d_odata, T *d_idata, T *d_mask, float cx, float cy, int np, int ns, CarmaDevice *device)
int indexfill(cuFloatComplex *d_odata, cuFloatComplex *d_idata, int *indx, int nx, int Nx, int N, CarmaDevice *device)
void roof_fillbin(T *d_odata, T *d_idata, int nrebin, int np, int ns, int nim, CarmaDevice *device)
void pyr_submask3d(Tout *d_odata, Tin *d_mask, int n, int nim, CarmaDevice *device)
void pyr_abs(Tout *d_odata, Tin *d_idata, int ns, int nim, CarmaDevice *device)
int fillcamplipup(cuFloatComplex *amplipup, float *phase, float *offset, float *mask, float scale, int *istart, int *jstart, int *ivalid, int *jvalid, int nphase, int npup, int Nfft, int Ntot, CarmaDevice *device, int offset_phase)
void pyr_submaskpyr(T *d_odata, T *d_mask, int n, CarmaDevice *device)
int fillbincube_async(CarmaStreams *streams, float *bcube, cuFloatComplex *hrimage, int *indxpix, int Nfft, int Npix, int Nrebin, int Nsub, CarmaDevice *device)
void subap_reduce_async(int threads, int blocks, CarmaStreams *streams, T *d_idata, T *d_odata)
void subap_reduce_new(int size, int threads, int blocks, T *d_idata, T *d_odata, T thresh, CarmaDevice *device)
void phase_derive(int size, int threads, int blocks, int n, T *d_idata, T *d_odata, int *indx, T *mask, T alpha, float *fluxPerSub)
void apply_submask(Tout *d_odata, Tin *d_mask, int n, CarmaDevice *device)
void pyr_fact(T *d_data, T fact, int n, int nim, CarmaDevice *device)
int fillfsamplipup(cuFloatComplex *d_odata, float *idata, float *mask, float scale, int Nfft, int N, CarmaDevice *device)
int fillbinimg_async(CarmaStreams *streams, CarmaObj< float > *bimage, CarmaObj< float > *bcube, int npix, int nsub, int Nsub, int *ivalid, int *jvalid, bool add, CarmaDevice *device)
void subap_reduce(int size, int threads, int blocks, T *d_idata, T *d_odata, CarmaDevice *device)
void roof_intensities(T *d_odata, T *d_idata, int *subindx, int *subindy, int ns, int nvalid, int nim, CarmaDevice *device)
int convolve_cube(cuFloatComplex *d_odata, cuFloatComplex *d_idata, int N, int n, CarmaDevice *device)
void roof_abs2(Tout *d_odata, Tin *d_idata, Tout fact, int ns, int nim, CarmaDevice *device)
void copy_imgin_binimg(float *binimg, int *validsubsx, int *validsubsy, int Nb, float *img, int *validx, int *validy, int Nim, int Npix, CarmaDevice *device)
int fillbinimg(float *bimage, float *bcube, int npix, int nsub, int Nsub, int *ivalid, int *jvalid, bool add, CarmaDevice *device)
void pyr_rollmod(T *d_odata, T *d_idata, T *d_mask, float cx, float cy, int np, int ns, CarmaDevice *device)
void pyr_fillbin(T *d_odata, T *d_idata, int nrebin, int np, int ns, int nim, CarmaDevice *device)
void phase_project(int nphase, int nvalid, T *d_idata, T *d_odata, int *indx, T *d_ttprojmat, T *d_ttprojvec, CarmaDevice *device)
void pyr_getpup(Tout *d_odata, Tin *d_idata, Tout *d_offsets, Tin *d_pup, int np, float lambda, CarmaDevice *device)
void pyr_intensities(T *d_odata, T *d_idata, int *subindx, int *subindy, int ns, int nvalid, int nim, CarmaDevice *device)
int fillbincube(float *bcube, cuFloatComplex *hrimage, int *indxpix, int Nfft, int Npix, int Nrebin, int Nsub, CarmaDevice *device)
void pyr_abs2(Tout *d_odata, Tin *d_idata, Tout fact, int ns, int nim, CarmaDevice *device)
int digitalize(T *camimg, float *binimg, float *dark, float *flat, int max_flux_per_pix, int max_pix_value, int N, CarmaDevice *device)