MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / PYBIND11_MODULE

Function PYBIND11_MODULE

ngscuda/python_ngscuda.cpp:19–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19PYBIND11_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

Callers

nothing calls this directly

Calls 15

InitCUDAFunction · 0.85
InitCuLinalgFunction · 0.85
MatMultFunction · 0.85
CreateDevMatrixFunction · 0.85
argFunction · 0.85
FVDoubleMethod · 0.80
AddMethod · 0.80
StopMethod · 0.80
SetPrecisionMethod · 0.80
SetMaxStepsMethod · 0.80
SetPrintRatesMethod · 0.80

Tested by

no test coverage detected