| 15 | py::object kp_trace, kp_debug, kp_info, kp_warning, kp_error; |
| 16 | |
| 17 | std::unique_ptr<kp::OpAlgoDispatch> |
| 18 | opAlgoDispatchPyInit(std::shared_ptr<kp::Algorithm>& algorithm, |
| 19 | const py::array& push_consts) |
| 20 | { |
| 21 | const py::buffer_info info = push_consts.request(); |
| 22 | KP_LOG_DEBUG("Kompute Python Manager creating tensor_T with push_consts " |
| 23 | "size {} dtype {}", |
| 24 | push_consts.size(), |
| 25 | std::string(py::str(push_consts.dtype()))); |
| 26 | |
| 27 | if (push_consts.dtype().is(py::dtype::of<std::float_t>())) { |
| 28 | std::vector<float> dataVec((float*)info.ptr, |
| 29 | ((float*)info.ptr) + info.size); |
| 30 | return std::unique_ptr<kp::OpAlgoDispatch>{ new kp::OpAlgoDispatch( |
| 31 | algorithm, dataVec) }; |
| 32 | } else if (push_consts.dtype().is(py::dtype::of<std::uint32_t>())) { |
| 33 | std::vector<uint32_t> dataVec((uint32_t*)info.ptr, |
| 34 | ((uint32_t*)info.ptr) + info.size); |
| 35 | return std::unique_ptr<kp::OpAlgoDispatch>{ new kp::OpAlgoDispatch( |
| 36 | algorithm, dataVec) }; |
| 37 | } else if (push_consts.dtype().is(py::dtype::of<std::int32_t>())) { |
| 38 | std::vector<int32_t> dataVec((int32_t*)info.ptr, |
| 39 | ((int32_t*)info.ptr) + info.size); |
| 40 | return std::unique_ptr<kp::OpAlgoDispatch>{ new kp::OpAlgoDispatch( |
| 41 | algorithm, dataVec) }; |
| 42 | } else if (push_consts.dtype().is(py::dtype::of<std::double_t>())) { |
| 43 | std::vector<double> dataVec((double*)info.ptr, |
| 44 | ((double*)info.ptr) + info.size); |
| 45 | return std::unique_ptr<kp::OpAlgoDispatch>{ new kp::OpAlgoDispatch( |
| 46 | algorithm, dataVec) }; |
| 47 | } else { |
| 48 | throw std::runtime_error("Kompute Python no valid dtype supported"); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | PYBIND11_MODULE(kp, m) |
| 53 | { |