COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
CarmaObjHalfInterfacer Struct Reference

#include <obj_half.hpp>

Collaboration diagram for CarmaObjHalfInterfacer:

Static Public Member Functions

template<typename T >
static void call (py::module &mod)
 

Detailed Description

Definition at line 54 of file obj_half.hpp.

Member Function Documentation

◆ call()

template<typename T >
static void CarmaObjHalfInterfacer::call ( py::module &  mod)
static

Definition at line 56 of file obj_half.hpp.

56  {
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  }
Here is the call graph for this function:

The documentation for this struct was generated from the following file:
correlation_bokeh.data
data
Definition: correlation_bokeh.py:280
test_cublas1.c
c
Definition: test_cublas1.py:14
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
CarmaHostObj
this class provides wrappers to the generic carma host object
Definition: carma_host_obj.h:68
test_rtcFHF.frame
frame
Definition: test_rtcFHF.py:36
layers_test.name
string name
Definition: layers_test.py:21