| 17 | } |
| 18 | |
| 19 | PYBIND11_MODULE(_ngscuda, m) { |
| 20 | |
| 21 | InitCUDA(1); |
| 22 | InitCuLinalg(); |
| 23 | InitApplyIntegrationPoints(); |
| 24 | |
| 25 | m.def("InitCuLinalg", &InitCuLinalg, "Initializing cublas and cusparse."); |
| 26 | |
| 27 | py::class_<UnifiedVector, BaseVector, shared_ptr<UnifiedVector>> |
| 28 | (m, "UnifiedVector", "UnifiedVector for CUDA applications", py::multiple_inheritance()) |
| 29 | |
| 30 | .def(py::init([] (int size) |
| 31 | { |
| 32 | return make_shared<UnifiedVector>(size); |
| 33 | })) |
| 34 | .def(py::init([] (const BaseVector &vec) |
| 35 | { |
| 36 | return make_shared<UnifiedVector>(vec); |
| 37 | })) |
| 38 | .def(py::init([] (py::array_t<double> bvec) |
| 39 | { |
| 40 | auto vec = bvec.template unchecked<1>(); |
| 41 | shared_ptr<UnifiedVector> uv = make_shared<UnifiedVector>(vec.size()); |
| 42 | FlatVector<double> fv = uv->FVDouble(); |
| 43 | for (size_t i = 0; i < vec.size(); i++) |
| 44 | { |
| 45 | fv(i) = vec(i); |
| 46 | } |
| 47 | return uv; |
| 48 | })) |
| 49 | |
| 50 | .def("UpdateHost", &UnifiedVector::UpdateHost) |
| 51 | .def("UpdateDevice", &UnifiedVector::UpdateDevice) |
| 52 | .def_property_readonly("__cuda_array_interface__", [](UnifiedVector& self) |
| 53 | { |
| 54 | self.UpdateDevice(); |
| 55 | auto ptr = reinterpret_cast<uintptr_t>(self.DevData()); |
| 56 | py::dict cai; |
| 57 | cai["version"] = 2; |
| 58 | cai["shape"] = py::make_tuple(self.Size()); |
| 59 | // "<f8" = little-endian float64 |
| 60 | cai["typestr"] = "<f8"; |
| 61 | // data: (ptr, readonly_flag) |
| 62 | cai["data"] = py::make_tuple(ptr, false); |
| 63 | // contiguous 1D, so no strides |
| 64 | cai["strides"] = py::none(); |
| 65 | return cai; |
| 66 | }) |
| 67 | .def_property_readonly("dev_ptr", [](UnifiedVector& self) |
| 68 | { |
| 69 | return reinterpret_cast<uintptr_t>(self.DevData()); |
| 70 | }) |
| 71 | ; |
| 72 | |
| 73 | |
| 74 | py::class_<DevMatrix, BaseMatrix, shared_ptr<DevMatrix>> |
| 75 | (m, "DevBaseMatrix", "device matrix for CUDA applications"); |
| 76 |
nothing calls this directly
no test coverage detected