COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
sutra_dm.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_DM_H_
18 #define _SUTRA_DM_H_
19 
20 #include <carma_utils.h>
21 #include <sutra_kl.h>
22 #include <sutra_phase.h>
23 #include <sutra_utils.h>
24 #include <map>
25 
26 #include <cuda.h>
27 
28 #define CHEAT_CODE
29 // #define COMPN 1 // 1, 2 or 3
30 // //#define REDUCTION
31 // //#define TEXTURE
32 #define BLOCKSIZE 512
33 #define CEIL(a, b) ((a) + (b)-1) / (b)
34 #define MAXSPOT 16
35 #define PIXELPERBLOCK 10
36 
37 using std::string;
38 using std::vector;
39 
40 // ██████╗ ███╗ ███╗
41 // ██╔══██╗████╗ ████║
42 // ██║ ██║██╔████╔██║
43 // ██║ ██║██║╚██╔╝██║
44 // ██████╔╝██║ ╚═╝ ██║
45 // ╚═════╝ ╚═╝ ╚═╝
46 //
47 
48 class SutraDm {
49  public:
50  int device;
51  string type;
52  float altitude;
53  long nactus;
54  long influsize;
55  long dim;
56  float push4imat;
57  float volt_min;
58  float volt_max;
59  float dx;
60  float dy;
61  float thetaML;
62  float G;
63 
64  uint16_t val_max;
65 
67 
69 
70  CarmaObj<float> *d_influ; // if relevant
71 
74 
76 
77  // pzt
81  // CarmaSparseObj<float> *d_IFsparse;
82  // CarmaObj<float> *d_comdouble;
83  // CarmaObj<double> *d_shapedouble;
84 
86 
88  cublasHandle_t cublas_handle() { return current_context->get_cublas_handle(); }
89  cusparseHandle_t cusparse_handle() {
91  }
92 
93  public:
94  SutraDm(CarmaContext *context, const char *type, float altitude, long dim,
95  long nactus, long influsize, long ninflupos, long n_npoints,
96  float push4imat, long nord, float dx, float dy, float thetaML, float G, int device);
98 
99  int nact();
100  int pzt_loadarrays(float *influ, int *influpos, int *npoints, int *istart,
101  int *xoff, int *yoff);
102  int kl_loadarrays(float *rabas, float *azbas, int *ord, float *cr, float *cp);
103  int tt_loadarrays(float *influ);
104  int reset_shape();
105  int comp_shape();
106 
107  int comp_shape(uint16_t *comm);
108  int comp_shape(float *comm);
109  int comp_oneactu(int nactu, float ampli);
110  // Florian features
111  int kl_floloadarrays(float *covmat, float *filter, float *evals, float *bas);
112 
113  template <class T>
114  int get_IF(T *IF, int *indx_pup, long nb_pts, float ampli);
115  template <class T>
116  int get_IF_sparse(CarmaSparseObj<T> *&d_IFsparse, int *indx_pup,
117  long nb_pts, float ampli, int puponly);
118 
119  int do_geomat(float *d_geocov, float *d_IF, long n_pts);
120 
121  template <class T>
122  int do_geomat_from_sparse(T *d_geocov, CarmaSparseObj<T> *d_IFsparse);
123 
124  int DDiago(CarmaObj<float> *d_statcov, CarmaObj<float> *d_geocov);
125  int compute_KLbasis(float *xpos, float *ypos, int *indx, long dim, float norm,
126  float ampli);
127  int piston_filt(CarmaObj<float> *d_statcov);
128  int set_registration(float dx, float dy, float thetaML, float G);
129 };
130 
131 // ██████╗ ███╗ ███╗███████╗
132 // ██╔══██╗████╗ ████║██╔════╝
133 // ██║ ██║██╔████╔██║███████╗
134 // ██║ ██║██║╚██╔╝██║╚════██║
135 // ██████╔╝██║ ╚═╝ ██║███████║
136 // ╚═════╝ ╚═╝ ╚═╝╚══════╝
137 //
138 
139 class SutraDms {
140  public:
141  vector<SutraDm *> d_dms;
142 
143  public:
146 
147  int add_dm(CarmaContext *context, const char *type, float alt, long dim,
148  long nactus, long influsize, long ninflupos, long n_npoints,
149  float push4imat, long nord, float dx, float dy, float thetaML, float G, int device);
150  int add_dm(CarmaContext *context, const char *type, float alt, long dim,
151  long nactus, long influsize, long ninflupos, long n_npoints,
152  float push4imat, long nord, int device);
153  int insert_dm(CarmaContext *context, const char *type, float alt, long dim,
154  long nactus, long influsize, long ninflupos, long n_npoints,
155  float push4imat, long nord, float dx, float dy, float thetaML, float G, int device, int idx);
156  int remove_dm(int idx);
157 
158  int ndm() { return d_dms.size(); };
159  int nact_total();
160 };
161 
162 template <class T>
163 void comp_dmshape(int threads, int blocks, T *d_idata, T *d_odata, int *pos,
164  int *istart, int *npts, T *comm, unsigned int n, int N);
165 
166 template <class T>
167 void comp_dmshape2(T *outData, const T *cmdVector, const T *influData,
168  const int *iStart_t, const int *iPos, const int roiLength,
169  const dim3 threads, const dim3 blocks, const int shared);
170 
171 template <class T>
172 void oneactu(int threads, int blocks, T *d_idata, T *d_odata, int nactu,
173  T ampli, int *xoff, int *yoff, int dim_im, int dim_influ, int N);
174 template <class T>
175 void oneactu(int threads, int blocks, T *d_idata, T *d_odata, int nactu,
176  T ampli, int dim_im, int dim_influ, int N);
177 template <class T>
178 void comp_fulldmshape(int threads, int blocks, T *d_idata, T *d_odata,
179  int nactus, int diminflu, T *comm, int N);
180 
181 template <class T>
182 int getIF(T *IF, float *dmshape, int *indx_pup, long nb_pts, int column,
183  long nb_col, int puponly, CarmaDevice *device);
184 int dm_dostatmat(float *d_statcov, long Nkl, float *d_xpos, float *d_ypos,
185  float norm, CarmaDevice *device);
186 int fill_filtermat(float *filter, int nactu, int N, CarmaDevice *device);
187 int find_nnz(float *d_data, int N, CarmaDevice *device);
188 int convertToCom(uint16_t *volts, float *com, int N, float volt_min, float volt_max,
189  uint16_t val_max, CarmaDevice *device);
190 
191 #endif // _SUTRA_DM_H_
this file provides tools to CarmaObj
this class provides the context in which CarmaObj are created
Definition: carma_context.h:79
cublasHandle_t get_cublas_handle()
cusparseHandle_t get_cusparse_handle()
this class provides wrappers to the generic carma sparse object
this class provides the dm features to COMPASS
Definition: sutra_dm.h:48
int piston_filt(CarmaObj< float > *d_statcov)
int device
Definition: sutra_dm.h:50
CarmaObj< int > * d_influpos
Definition: sutra_dm.h:75
CarmaObj< float > * d_KLbasis
Definition: sutra_dm.h:80
cusparseHandle_t cusparse_handle()
Definition: sutra_dm.h:89
int comp_shape(uint16_t *comm)
cublasHandle_t cublas_handle()
Definition: sutra_dm.h:88
float thetaML
Definition: sutra_dm.h:61
CarmaObj< int > * d_xoff
Definition: sutra_dm.h:78
SutraDm(CarmaContext *context, const char *type, float altitude, long dim, long nactus, long influsize, long ninflupos, long n_npoints, float push4imat, long nord, float dx, float dy, float thetaML, float G, int device)
int do_geomat(float *d_geocov, float *d_IF, long n_pts)
long influsize
Definition: sutra_dm.h:54
int comp_shape()
int nact()
int comp_shape(float *comm)
int reset_shape()
float altitude
Definition: sutra_dm.h:52
SutraKL * d_kl
Definition: sutra_dm.h:85
float push4imat
Definition: sutra_dm.h:56
SutraPhase * d_shape
Definition: sutra_dm.h:66
CarmaObj< float > * d_com
Definition: sutra_dm.h:68
float volt_max
Definition: sutra_dm.h:58
CarmaObj< int > * d_istart
Definition: sutra_dm.h:72
int tt_loadarrays(float *influ)
int get_IF_sparse(CarmaSparseObj< T > *&d_IFsparse, int *indx_pup, long nb_pts, float ampli, int puponly)
int do_geomat_from_sparse(T *d_geocov, CarmaSparseObj< T > *d_IFsparse)
float volt_min
Definition: sutra_dm.h:57
int pzt_loadarrays(float *influ, int *influpos, int *npoints, int *istart, int *xoff, int *yoff)
long dim
Definition: sutra_dm.h:55
int kl_floloadarrays(float *covmat, float *filter, float *evals, float *bas)
float G
Definition: sutra_dm.h:62
int compute_KLbasis(float *xpos, float *ypos, int *indx, long dim, float norm, float ampli)
float dx
Definition: sutra_dm.h:59
CarmaObj< int > * d_npoints
Definition: sutra_dm.h:73
CarmaObj< float > * d_influ
Definition: sutra_dm.h:70
int set_registration(float dx, float dy, float thetaML, float G)
string type
Definition: sutra_dm.h:51
int comp_oneactu(int nactu, float ampli)
int kl_loadarrays(float *rabas, float *azbas, int *ord, float *cr, float *cp)
long nactus
Definition: sutra_dm.h:53
CarmaObj< int > * d_yoff
Definition: sutra_dm.h:79
int DDiago(CarmaObj< float > *d_statcov, CarmaObj< float > *d_geocov)
uint16_t val_max
Definition: sutra_dm.h:64
float dy
Definition: sutra_dm.h:60
CarmaContext * current_context
Definition: sutra_dm.h:87
int get_IF(T *IF, int *indx_pup, long nb_pts, float ampli)
int insert_dm(CarmaContext *context, const char *type, float alt, long dim, long nactus, long influsize, long ninflupos, long n_npoints, float push4imat, long nord, float dx, float dy, float thetaML, float G, int device, int idx)
int ndm()
Definition: sutra_dm.h:158
int nact_total()
int add_dm(CarmaContext *context, const char *type, float alt, long dim, long nactus, long influsize, long ninflupos, long n_npoints, float push4imat, long nord, float dx, float dy, float thetaML, float G, int device)
int add_dm(CarmaContext *context, const char *type, float alt, long dim, long nactus, long influsize, long ninflupos, long n_npoints, float push4imat, long nord, int device)
int remove_dm(int idx)
vector< SutraDm * > d_dms
Definition: sutra_dm.h:141
this class provides the kl features to COMPASS
Definition: sutra_kl.h:24
this class provides the phase features to COMPASS
Definition: sutra_phase.h:31
void comp_dmshape2(T *outData, const T *cmdVector, const T *influData, const int *iStart_t, const int *iPos, const int roiLength, const dim3 threads, const dim3 blocks, const int shared)
int fill_filtermat(float *filter, int nactu, int N, CarmaDevice *device)
void oneactu(int threads, int blocks, T *d_idata, T *d_odata, int nactu, T ampli, int *xoff, int *yoff, int dim_im, int dim_influ, int N)
int dm_dostatmat(float *d_statcov, long Nkl, float *d_xpos, float *d_ypos, float norm, CarmaDevice *device)
int getIF(T *IF, float *dmshape, int *indx_pup, long nb_pts, int column, long nb_col, int puponly, CarmaDevice *device)
int find_nnz(float *d_data, int N, CarmaDevice *device)
void comp_dmshape(int threads, int blocks, T *d_idata, T *d_odata, int *pos, int *istart, int *npts, T *comm, unsigned int n, int N)
void comp_fulldmshape(int threads, int blocks, T *d_idata, T *d_odata, int nactus, int diminflu, T *comm, int N)
int convertToCom(uint16_t *volts, float *com, int N, float volt_min, float volt_max, uint16_t val_max, CarmaDevice *device)