COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
obj_half.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_OBJ_HALF_H_
42 #define _WRAP_OBJ_HALF_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 
55  template <typename T>
56  static void call(py::module &mod) {
57  auto name = appendName<T>("obj_");
58  using Class = CarmaObj<T>;
59  using ClassHost = CarmaHostObj<T>;
60 
61  py::class_<Class> carmaWrapObj(mod, name.data(), py::buffer_protocol());
62  carmaWrapObj.def(
63  py::init([](CarmaContext &c,
64  const py::array_t<T, py::array::f_style |
65  py::array::forcecast> &data) {
66  int ndim = data.ndim() + 1;
67  std::vector<long> data_dims(ndim);
68  data_dims[0] = data.ndim();
69  copy(data.shape(), data.shape() + data.ndim(), begin(data_dims) + 1);
70  return std::unique_ptr<Class>(
71  new Class(&c, data_dims.data(), (const T *)data.data()));
72  }),
73  "TODO", // TODO do the documentation...
74  py::arg("context").none(false), py::arg("h_data").none(false));
75 
76  carmaWrapObj.def(py::init([](CarmaContext &c, const Class &data) {
77  return std::unique_ptr<Class>(new Class(&c, &data));
78  }),
79  "TODO", // TODO do the documentation...
80  py::arg("context").none(false),
81  py::arg("d_data").none(false));
82 
83  carmaWrapObj.def_buffer([](Class &frame) -> py::buffer_info {
84  frame.sync_h_data();
85 
86  const long *dims = frame.get_dims();
87  std::vector<ssize_t> shape(dims[0]);
88  std::vector<ssize_t> strides(dims[0]);
89  ssize_t stride = sizeof(T);
90 
91  // C-style
92  // for (ssize_t dim(dims[0] - 1); dim >= 0; --dim)
93  // {
94  // shape[dim] = dims[dim + 1];
95  // strides[dim] = stride;
96  // stride *= shape[dim];
97  // }
98 
99  // F-style
100  for (ssize_t dim(0); dim < dims[0]; ++dim) {
101  shape[dim] = dims[dim + 1];
102  strides[dim] = stride;
103  stride *= shape[dim];
104  }
105 
106  return py::buffer_info(frame.get_h_data(), sizeof(T),
107  py::format_descriptor<T>::format(), dims[0], shape,
108  strides);
109  });
110 
111  carmaWrapObj.def("__repr__", &Class::to_string);
112 
113  // int get_nb_streams()
114  carmaWrapObj.def_property_readonly("nb_streams", &Class::get_nb_streams,
115  "TODO"); // TODO do the documentation...
116  // int add_stream()
117  carmaWrapObj.def("add_stream", (int (Class::*)()) & Class::add_stream,
118  "TODO"); // TODO do the documentation...
119  // int add_stream(int nb)
120  carmaWrapObj.def("add_stream", (int (Class::*)(int)) & Class::add_stream,
121  "TODO",
122  py::arg("np")); // TODO do the documentation...
123  // int del_stream()
124  carmaWrapObj.def("del_stream", (int (Class::*)()) & Class::del_stream,
125  "TODO"); // TODO do the documentation...
126  // int del_stream(int nb)
127  carmaWrapObj.def("del_stream", (int (Class::*)(int)) & Class::del_stream,
128  "TODO",
129  py::arg("np")); // TODO do the documentation...
130  // int wait_stream(int stream)
131  carmaWrapObj.def("wait_stream", &Class::wait_stream, "TODO",
132  py::arg("steam")); // TODO do the documentation...
133  carmaWrapObj.def(
134  "swap_ptr", [](Class &obj, Class &obj2) { obj.swap_ptr(obj2.get_data()); },
135  "TODO",
136  py::arg("ptr")); // TODO do the documentation...
137  // int wait_all_streams()
138  carmaWrapObj.def("wait_all_streams", &Class::wait_all_streams,
139  "TODO"); // TODO do the documentation...
140 
141  // const long *get_dims()
142  carmaWrapObj.def_property_readonly(
143  "shape",
144  [](Class &frame) -> py::array_t<long> {
145  long nb_dim = frame.get_dims(0);
146  const long *c_dim = frame.get_dims() + 1;
147  return py::array_t<long>(nb_dim, c_dim);
148  },
149  "TODO"); // TODO do the documentation...
150 
151  // int get_nb_elements()
152  carmaWrapObj.def_property_readonly("nbElem", &Class::get_nb_elements,
153  "TODO"); // TODO do the documentation...
154  // CarmaContext* get_context()
155  carmaWrapObj.def_property_readonly("context", &Class::get_context,
156  "TODO"); // TODO do the documentation...
157  // int get_device()
158  carmaWrapObj.def_property_readonly("device", &Class::get_device,
159  "TODO"); // TODO do the documentation...
160  // int get_o_data()
161  // carmaWrapObj.def_property_readonly("o_data", &Class::get_o_data_value,
162  // "TODO"); // TODO do the
163  // documentation...
164 
165  // int host2device(T_data *data);
166  carmaWrapObj.def(
167  "host2device",
168  [](Class &c,
169  py::array_t<T, py::array::f_style | py::array::forcecast> &data) {
170  c.host2device(data.data());
171  },
172  "TODO",
173  py::arg("data").none(false)); // TODO do the documentation...
174  // int device2host(T_data *data);
175  carmaWrapObj.def(
176  "device2host",
177  [](Class &c,
178  py::array_t<T, py::array::f_style | py::array::forcecast> &data) {
179  c.device2host(data.mutable_data());
180  },
181  "TODO",
182  py::arg("data").none(false)); // TODO do the documentation...
183 
184  // int copy_into(T_data *data, int nb_elem);
185  carmaWrapObj.def(
186  "copy_into",
187  [](Class &src, Class &dest, long nb_elem) {
188  if (nb_elem < 0) {
189  nb_elem = src.get_nb_elements();
190  }
191  src.copy_into(dest, nb_elem);
192  },
193  "TODO", py::arg("dest"),
194  py::arg("nb_elem") = -1); // TODO do the documentation...
195  // int copy_from(T_data *data, int nb_elem);
196  carmaWrapObj.def(
197  "copy_from",
198  [](Class &dest, Class &src, long nb_elem) {
199  if (nb_elem < 0) {
200  nb_elem = dest.get_nb_elements();
201  }
202  dest.copy_from(src, nb_elem);
203  },
204  "TODO", py::arg("data"),
205  py::arg("nb_elem") = -1); // TODO do the documentation...
206 #ifdef USE_OCTOPUS
207  carmaWrapObj.def("copy_into",
208  (int (Class::*)(ipc::Cacao<T> *)) & Class::copy_into);
209  carmaWrapObj.def("copy_from",
210  (int (Class::*)(ipc::Cacao<T> *)) & Class::copy_from);
211 #endif
212  // inline int reset()
213  carmaWrapObj.def("reset", &Class::reset,
214  "TODO"); // TODO do the documentation...
215  }
216 };
217 #endif
CarmaObjHalfInterfacer::call
static void call(py::module &mod)
Definition: obj_half.hpp:56
carma_utils::to_string
std::string to_string(const T &n)
Definition: carma_utils.h:82
CarmaObj< T >
CarmaContext
this class provides the context in which CarmaObj are created
Definition: carma_context.h:104
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
CarmaObjHalfInterfacer
Definition: obj_half.hpp:54