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