COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
carma_sparse_host_obj.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 
43 #ifndef CARMASPARSEHOSTOBJ_H_
44 #define CARMASPARSEHOSTOBJ_H_
45 #include "carma_host_obj.h"
46 
47 template <class T_data>
49 
50 template <class T_data>
52  public:
56  CarmaSparseHostObj(const long* dims, T_data* M, char order);
58 
59  // delete all arrays and create new for nnz=new_nnz
60  void resize(int new_nnz, int dim1_, int dim2_);
61 
64 
65  void init_from_matrix(const long* dims, T_data* M, char major_dim);
66  void copy_into_matrix(T_data* M, char major_dim);
69  char get_major_dim() const { return major_dim; }
70 
72  operator T_data*() { return h_data; }
73  T_data* operator[](int index) { return &h_data[index]; }
74  T_data* get_data() { return h_data; }
75  T_data* get_data(int index) { return &h_data[index]; }
76  const long* get_dims() { return dims_data; }
77  long get_dims(int i) { return dims_data[i]; }
78  int get_nonzero_elem() { return nz_elem; }
79 
80  private:
81  void _create(int nnz_, int dim1_, int dim2_); // create new arrays
82  void _clear(); // clear arrays
83 
84  char major_dim; // U - undefined
85  // R - row major
86  // C - col major
87 
88  MemAlloc malloc_type;
89 
90  public:
91  long dims_data[3];
92  int nz_elem;
93 
94  // see Sparse Matrix Storage Formats (coordinate format)
95  // ONE-BASED!!!!
96  T_data* h_data;
97  int* rowind;
98  int* colind;
99 };
100 
101 // Multiply sparce matrix by vector
102 // y := alpha*A*x + betta * y
103 template <class T_data>
105  CarmaHostObj<T_data>* x, T_data betta,
107  void (*ptr_coomv)(char* transa, long* m, long* k, T_data* alpha,
108  char* matdescra, T_data* val, int* rowind,
109  int* colind, int* nnz, T_data* x,
110  T_data* beta, T_data* y));
111 
112 // Multiply sparce matrix by dense matrix
113 // C := alpha*op(A)*B + betta * y
114 // op_A could be N (do nothing) or T (transpose)
115 template <class T_data>
116 void carma_gemm(char op_A, T_data alpha, CarmaSparseHostObj<T_data>* A,
117  CarmaHostObj<T_data>* B, T_data betta,
119 
120 // Multiply sparce matrix by dense matrix
121 // C := alpha*A*B + betta * y
122 template <class T_data>
123 inline void carma_gemm(T_data alpha, CarmaSparseHostObj<T_data>* A,
124  CarmaHostObj<T_data>* B, T_data betta,
126  kp_gemm('N', alpha, A, B, betta, C);
127 }
128 
129 #endif /* CARMASPARSEHOSTOBJ_H_ */
CarmaSparseHostObj::h_data
T_data * h_data
Definition: carma_sparse_host_obj.h:96
CarmaSparseHostObj::dims_data
long dims_data[3]
dimensions of the array
Definition: carma_sparse_host_obj.h:91
CarmaSparseHostObj::CarmaSparseHostObj
CarmaSparseHostObj(CarmaSparseObj< T_data > &sm)
CarmaSparseHostObj::~CarmaSparseHostObj
virtual ~CarmaSparseHostObj()
CarmaSparseHostObj::resize2row_major
void resize2row_major()
CarmaSparseHostObj::get_data
T_data * get_data()
Definition: carma_sparse_host_obj.h:74
carma_gemv
void carma_gemv(T_data alpha, CarmaSparseHostObj< T_data > *A, CarmaHostObj< T_data > *x, T_data betta, CarmaHostObj< T_data > *y, void(*ptr_coomv)(char *transa, long *m, long *k, T_data *alpha, char *matdescra, T_data *val, int *rowind, int *colind, int *nnz, T_data *x, T_data *beta, T_data *y))
CarmaSparseHostObj::resize
void resize(int new_nnz, int dim1_, int dim2_)
CarmaSparseHostObj::operator=
void operator=(CarmaSparseHostObj< T_data > &M)
CarmaSparseHostObj::get_dims
const long * get_dims()
Definition: carma_sparse_host_obj.h:76
CarmaSparseHostObj::get_nonzero_elem
int get_nonzero_elem()
Definition: carma_sparse_host_obj.h:78
CarmaSparseHostObj::CarmaSparseHostObj
CarmaSparseHostObj(const long *dims, T_data *M, char order)
MemAlloc
MemAlloc
Definition: carma_host_obj.h:52
CarmaSparseHostObj::resize2col_major
void resize2col_major()
CarmaSparseHostObj::CarmaSparseHostObj
CarmaSparseHostObj(CarmaSparseHostObj< T_data > &sm)
CarmaSparseHostObj::operator[]
T_data * operator[](int index)
Definition: carma_sparse_host_obj.h:73
CarmaSparseHostObj::colind
int * colind
Definition: carma_sparse_host_obj.h:98
CarmaSparseObj
this class provides wrappers to the generic carma sparse object
Definition: carma_sparse_host_obj.h:48
CarmaSparseHostObj::get_dims
long get_dims(int i)
Definition: carma_sparse_host_obj.h:77
CarmaSparseHostObj::init_from_matrix
void init_from_matrix(const long *dims, T_data *M, char major_dim)
CarmaSparseHostObj::operator=
void operator=(CarmaSparseObj< T_data > &M)
CarmaSparseHostObj::copy_into_matrix
void copy_into_matrix(T_data *M, char major_dim)
CarmaHostObj
this class provides wrappers to the generic carma host object
Definition: carma_host_obj.h:68
CarmaSparseHostObj
this class provides wrappers to the generic carma sparse host object
Definition: carma_sparse_host_obj.h:51
CarmaSparseHostObj::nz_elem
int nz_elem
number of elements in the array
Definition: carma_sparse_host_obj.h:92
CarmaSparseHostObj::rowind
int * rowind
Definition: carma_sparse_host_obj.h:97
carma_gemm
void carma_gemm(char op_A, T_data alpha, CarmaSparseHostObj< T_data > *A, CarmaHostObj< T_data > *B, T_data betta, CarmaHostObj< T_data > *C)
CarmaSparseHostObj::get_data
T_data * get_data(int index)
Definition: carma_sparse_host_obj.h:75
CarmaSparseHostObj::get_major_dim
char get_major_dim() const
Definition: carma_sparse_host_obj.h:69
CarmaSparseHostObj::CarmaSparseHostObj
CarmaSparseHostObj()
carma_host_obj.h