COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
host_obj.hpp
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 _WRAP_HOST_OBJ_H_
42 #define _WRAP_HOST_OBJ_H_
43 
44 #include "declare_name.hpp"
45 
46 #include <carma.h>
47 
48 #include <wyrm>
49 
50 #include <type_list.hpp>
51 
52 namespace py = pybind11;
53 
54 
55 
57  template <typename T> static void call(py::module &mod) {
58  auto name = appendName<T>("host_obj_");
59  using Class = CarmaHostObj<T>;
60 
61  py::class_<Class>(mod, name.data(), py::buffer_protocol())
62  .def(py::init([](const py::array_t<T, py::array::f_style |
63  py::array::forcecast> &data,
64  MemAlloc malloc_type) {
65  int ndim = data.ndim() + 1;
66  std::vector<long> data_dims(ndim);
67  data_dims[0] = data.ndim();
68  copy(data.shape(), data.shape() + data.ndim(),
69  begin(data_dims) + 1);
70  return std::unique_ptr<Class>(
71  new Class(data_dims.data(), (const T *)data.data()));
72  }),
73  "TODO", // TODO do the documentation...
74  py::arg("h_data").none(false), py::arg("malloc_type")=MA_MALLOC)
75 
76  .def(py::init([](const Class &data) {
77  return std::unique_ptr<Class>(new Class(&data));
78  }),
79  "TODO", // TODO do the documentation...
80  py::arg("d_data").none(false))
81 
82  .def_buffer([](Class &frame) -> py::buffer_info {
83 
84  const long *dims = frame.get_dims();
85  std::vector<ssize_t> shape(dims[0]);
86  std::vector<ssize_t> strides(dims[0]);
87  ssize_t stride = sizeof(T);
88 
89  // C-style
90  // for (ssize_t dim(dims[0] - 1); dim >= 0; --dim)
91  // {
92  // shape[dim] = dims[dim + 1];
93  // strides[dim] = stride;
94  // stride *= shape[dim];
95  // }
96 
97  // F-style
98  for (ssize_t dim(0); dim < dims[0]; ++dim) {
99  shape[dim] = dims[dim + 1];
100  strides[dim] = stride;
101  stride *= shape[dim];
102  }
103 
104  return py::buffer_info(frame.get_data(), sizeof(T),
105  py::format_descriptor<T>::format(), dims[0],
106  shape, strides);
107  })
108 
109  // .def("__repr__", &std::string)
110 
111  // const long *get_dims()
112  .def_property_readonly("shape",
113  [](Class &frame) -> py::array_t<long> {
114  long nb_dim = frame.get_dims(0);
115  const long *c_dim = frame.get_dims() + 1;
116  return py::array_t<long>(nb_dim, c_dim);
117  },
118  "TODO") // TODO do the documentation...
119 
120  // int get_nb_elements()
121  .def_property_readonly("nbElem", &Class::get_nb_elements,
122  "TODO") // TODO do the documentation...
123  ;
124  // MAGMA functions
125 
126  // template<class T>
127  // int carma_svd(CarmaObj<T> *imat, CarmaObj<T> *eigenvals,
128  // CarmaObj<T> *mod2act, CarmaObj<T> *mes2mod);
129  mod.def(appendName<T>("magma_svd_cpu_").data(), py::overload_cast<Class *,
130  Class *, Class *, Class *>(&carma_magma_svd_cpu<T>));
131 
132  // TODO after CarmaHostObj
133  // template<class T>
134  // int carma_magma_syevd(char jobz, CarmaObj<T> *mat, CarmaHostObj<T>
135  // *eigenvals);
136  // mod.def(appendName<T>("syevd_").data(), &carma_magma_syevd<T>);
137  mod.def(appendName<T>("magma_syevd_cpu_").data(), py::overload_cast<char, Class *, Class *>(&carma_magma_syevd_cpu<T>));
138 
139  // template<class T, int method>
140  // int carma_magma_syevd(char jobz, CarmaObj<T> *mat, CarmaHostObj<T>
141  // *eigenvals); template<class T> int carma_magma_syevd_m(long ngpu, char jobz,
142  // long N, T *mat, T *eigenvals); template<class T> int carma_magma_syevd_m(long
143  // ngpu, char jobz, CarmaHostObj<T> *mat,
144  // CarmaHostObj<T> *eigenvals);
145  // template<class T>
146  // int carma_magma_syevd_m(long ngpu, char jobz, CarmaHostObj<T> *mat,
147  // CarmaHostObj<T> *eigenvals, CarmaHostObj<T> *U);
148  // template<class T>
149  // int carma_magma_getri(CarmaObj<T> *d_iA);
150  mod.def(appendName<T>("magma_getri_cpu_").data(), py::overload_cast<Class *>(&carma_magma_getri_cpu<T>));
151 
152  // template<class T>
153  // int carma_magma_potri(CarmaObj<T> *d_iA);
154  mod.def(appendName<T>("magma_potri_cpu_").data(), py::overload_cast<Class *>(&carma_magma_potri_cpu<T>));
155 
156  // TODO after CarmaHostObj
157  // template<class T>
158  // int carma_magma_potri_m(long num_gpus, CarmaHostObj<T> *h_A, CarmaObj<T>
159  // *d_iA);
160 
161  // MAGMA functions (direct access)
162  // template<class T>
163  // int carma_magma_syevd(char jobz, long N, T *mat, T *eigenvals);
164  // template<class T, int method>
165  // int carma_magma_syevd(char jobz, long N, T *mat, T *eigenvals);
166  // template<class T>
167  // int carma_magma_syevd_m(long ngpu, char jobz, long N, T *mat, T *eigenvals);
168  // template<class T>
169  // int carma_magma_potri_m(long num_gpus, long N, T *h_A, T *d_iA);
170 
171  }
172 };
173 #endif
MA_MALLOC
@ MA_MALLOC
Definition: carma_host_obj.h:53
CarmaHostObjInterfacer::call
static void call(py::module &mod)
Definition: host_obj.hpp:57
CarmaHostObjInterfacer
Definition: host_obj.hpp:56
MemAlloc
MemAlloc
Definition: carma_host_obj.h:52
declare_name.hpp
this file provides pybind wrapper for libcarma
CarmaHostObj
this class provides wrappers to the generic carma host object
Definition: carma_host_obj.h:68