From 6c6132942247bcc7a04144b9f29e12eacc58b74e Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 8 Nov 2020 11:20:12 +0000 Subject: [PATCH] Updated to add separate bytes load and str load functions --- python/src/main.cpp | 76 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/python/src/main.cpp b/python/src/main.cpp index 52b39eb9a..265df8f52 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -72,7 +72,17 @@ PYBIND11_MODULE(kp, m) { "Records operation to run multiplication compute shader to two input tensors and an output tensor") .def("record_algo_file", &kp::Sequence::record, "Records an operation using a custom shader provided from a shader path") - .def("record_algo_data", &kp::Sequence::record, + .def("record_algo_data", [](kp::Sequence &self, + std::vector> tensors, + py::bytes &bytes) { + // Bytes have to be converted into std::vector + py::buffer_info info(py::buffer(bytes).request()); + const char *data = reinterpret_cast(info.ptr); + size_t length = static_cast(info.size); + self.record( + tensors, + std::vector(data, data + length)); + }, "Records an operation using a custom shader provided as raw string or spirv bytes") .def("record_algo_lro", &kp::Sequence::record, "Records operation to run left right out operation with custom shader"); @@ -112,8 +122,20 @@ PYBIND11_MODULE(kp, m) { "Evaluates operation to run multiplication compute shader to two input tensors and an output tensor with new anonymous Sequence") .def("eval_algo_file_def", &kp::Manager::evalOpDefault, "Evaluates an operation using a custom shader provided from a shader path with new anonymous Sequence") - .def("eval_algo_data_def", &kp::Manager::evalOpDefault, - "Evaluates an operation using a custom shader provided as raw string or spirv bytes with new anonymous Sequence") + .def("eval_algo_str_def", &kp::Manager::evalOpDefault>, + "Evaluates an operation using a custom shader provided as string provided as list of characters with new anonymous Sequence") + .def("eval_algo_data_def", [](kp::Manager &self, + std::vector> tensors, + py::bytes &bytes) { + // Bytes have to be converted into std::vector + py::buffer_info info(py::buffer(bytes).request()); + const char *data = reinterpret_cast(info.ptr); + size_t length = static_cast(info.size); + self.evalOpDefault( + tensors, + std::vector(data, data + length)); + }, + "Evaluates an operation using a custom shader provided as spirv bytes with new anonymous Sequence") .def("eval_algo_lro_def", &kp::Manager::evalOpDefault, "Evaluates operation to run left right out operation with custom shader with new anonymous Sequence") // eval @@ -129,8 +151,22 @@ PYBIND11_MODULE(kp, m) { "Evaluates operation to run multiplication compute shader to two input tensors and an output tensor with explicitly named Sequence") .def("eval_algo_file", &kp::Manager::evalOp, "Evaluates an operation using a custom shader provided from a shader path with explicitly named Sequence") - .def("eval_algo_data", &kp::Manager::evalOp, - "Evaluates an operation using a custom shader provided as raw string or spirv bytes with explicitly named Sequence") + .def("eval_algo_str", &kp::Manager::evalOp>, + "Evaluates an operation using a custom shader provided as string provided as list of characters with explicitly named Sequence") + .def("eval_algo_data", [](kp::Manager &self, + std::vector> tensors, + std::string sequenceName, + py::bytes &bytes) { + // Bytes have to be converted into std::vector + py::buffer_info info(py::buffer(bytes).request()); + const char *data = reinterpret_cast(info.ptr); + size_t length = static_cast(info.size); + self.evalOp( + tensors, + sequenceName, + std::vector(data, data + length)); + }, + "Evaluates an operation using a custom shader provided as spirv bytes with explicitly named Sequence") .def("eval_algo_lro", &kp::Manager::evalOp, "Evaluates operation to run left right out operation with custom shader with explicitly named Sequence") // eval async default @@ -146,7 +182,19 @@ PYBIND11_MODULE(kp, m) { "Evaluates asynchronously operation to run multiplication compute shader to two input tensors and an output tensor with anonymous Sequence") .def("eval_async_algo_file_def", &kp::Manager::evalOpAsyncDefault, "Evaluates asynchronously an operation using a custom shader provided from a shader path with anonymous Sequence") - .def("eval_async_algo_data_def", &kp::Manager::evalOpAsyncDefault, + .def("eval_async_algo_str_def", &kp::Manager::evalOpAsyncDefault>, + "Evaluates Asynchronously an operation using a custom shader provided as string provided as list of characters with new anonymous Sequence") + .def("eval_async_algo_data_def", [](kp::Manager &self, + std::vector> tensors, + py::bytes &bytes) { + // Bytes have to be converted into std::vector + py::buffer_info info(py::buffer(bytes).request()); + const char *data = reinterpret_cast(info.ptr); + size_t length = static_cast(info.size); + self.evalOpAsyncDefault( + tensors, + std::vector(data, data + length)); + }, "Evaluates asynchronously an operation using a custom shader provided as raw string or spirv bytes with anonymous Sequence") .def("eval_async_algo_lro_def", &kp::Manager::evalOpAsyncDefault, "Evaluates asynchronously operation to run left right out operation with custom shader with anonymous Sequence") @@ -163,7 +211,21 @@ PYBIND11_MODULE(kp, m) { "Evaluates asynchronously operation to run multiplication compute shader to two input tensors and an output tensor with explicitly named Sequence") .def("eval_async_algo_file", &kp::Manager::evalOpAsync, "Evaluates asynchronously an operation using a custom shader provided from a shader path with explicitly named Sequence") - .def("eval_async_algo_data", &kp::Manager::evalOpAsync, + .def("eval_async_algo_str", &kp::Manager::evalOpAsync>, + "Evaluates Asynchronous an operation using a custom shader provided as string provided as list of characters with explicitly named Sequence") + .def("eval_async_algo_data", [](kp::Manager &self, + std::vector> tensors, + std::string sequenceName, + py::bytes &bytes) { + // Bytes have to be converted into std::vector + py::buffer_info info(py::buffer(bytes).request()); + const char *data = reinterpret_cast(info.ptr); + size_t length = static_cast(info.size); + self.evalOpAsync( + tensors, + sequenceName, + std::vector(data, data + length)); + }, "Evaluates asynchronously an operation using a custom shader provided as raw string or spirv bytes with explicitly named Sequence") .def("eval_async_algo_lro", &kp::Manager::evalOpAsync, "Evaluates asynchronously operation to run left right out operation with custom shader with explicitly named Sequence");