From 650975838c35e8786a05b02a62f33c77e0f0a4e0 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 9 Feb 2021 19:19:09 +0000 Subject: [PATCH] Updated python to align with new structure --- python/src/main.cpp | 15 ++++----------- python/test/test_array_multiplication.py | 2 +- python/test/test_kompute.py | 20 ++++++++++++-------- python/test/test_logistic_regression.py | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/python/src/main.cpp b/python/src/main.cpp index 6e795fad5..74f010f0a 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -105,8 +105,6 @@ PYBIND11_MODULE(kp, m) { .def("is_init", &kp::Sequence::isInit, "Checks if the Sequence has been initialized") // record - .def("record_tensor_create", &kp::Sequence::record, - "Records operation to create and initialise tensor GPU memory and buffer") .def("record_tensor_copy", &kp::Sequence::record, "Records operation to copy one tensor to one or many tensors") .def("record_tensor_sync_device", &kp::Sequence::record, @@ -161,7 +159,10 @@ PYBIND11_MODULE(kp, m) { .def("create_sequence", &kp::Manager::createManagedSequence, py::arg("name") = "", py::arg("queueIndex") = 0, "Create a sequence with specific name and specified index of available queues") .def("build_tensor", &kp::Manager::buildTensor, - py::arg("data"), py::arg("tensorType") = kp::Tensor::TensorTypes::eDevice, + py::arg("data"), py::arg("tensorType") = kp::Tensor::TensorTypes::eDevice, py::arg("syncDataToGPU") = true, + "Build and initialise tensor") + .def("rebuild_tensors", &kp::Manager::rebuildTensors, + py::arg("tensors"), py::arg("syncDataToGPU") = true, "Build and initialise tensor") // Await functions @@ -172,8 +173,6 @@ PYBIND11_MODULE(kp, m) { py::arg("waitFor") = UINT64_MAX, "Awaits for asynchronous operation on the last anonymous Sequence created") // eval default - .def("eval_tensor_create_def", &kp::Manager::evalOpDefault, - "Evaluates operation to create and initialise tensor GPU memory and buffer with new anonymous Sequence") .def("eval_tensor_copy_def", &kp::Manager::evalOpDefault, "Evaluates operation to copy one tensor to one or many tensors with new anonymous Sequence") .def("eval_tensor_sync_device_def", &kp::Manager::evalOpDefault, @@ -209,8 +208,6 @@ PYBIND11_MODULE(kp, m) { "Evaluates operation to run left right out operation with custom shader with new anonymous Sequence") // eval - .def("eval_tensor_create", &kp::Manager::evalOp, - "Evaluates operation to create and initialise tensor GPU memory and buffer with explicitly named Sequence") .def("eval_tensor_copy", &kp::Manager::evalOp, "Evaluates operation to copy one tensor to one or many tensors with explicitly named Sequence") .def("eval_tensor_sync_device", &kp::Manager::evalOp, @@ -249,8 +246,6 @@ PYBIND11_MODULE(kp, m) { "Evaluates operation to run left right out operation with custom shader with explicitly named Sequence") // eval async default - .def("eval_async_tensor_create_def", &kp::Manager::evalOpAsyncDefault, - "Evaluates asynchronously operation to create and initialise tensor GPU memory and buffer with anonymous Sequence") .def("eval_async_tensor_copy_def", &kp::Manager::evalOpAsyncDefault, "Evaluates asynchronously operation to copy one tensor to one or many tensors with anonymous Sequence") .def("eval_async_tensor_sync_device_def", &kp::Manager::evalOpAsyncDefault, @@ -286,8 +281,6 @@ PYBIND11_MODULE(kp, m) { "Evaluates asynchronously operation to run left right out operation with custom shader with anonymous Sequence") // eval async - .def("eval_async_tensor_create", &kp::Manager::evalOpAsync, - "Evaluates asynchronously operation to create and initialise tensor GPU memory and buffer with explicitly named Sequence") .def("eval_async_tensor_copy", &kp::Manager::evalOpAsync, "Evaluates asynchronously operation to copy one tensor to one or many tensors with explicitly named Sequence") .def("eval_async_tensor_sync_device", &kp::Manager::evalOpAsync, diff --git a/python/test/test_array_multiplication.py b/python/test/test_array_multiplication.py index 337c7a5db..fac2ed415 100644 --- a/python/test/test_array_multiplication.py +++ b/python/test/test_array_multiplication.py @@ -14,7 +14,7 @@ def test_array_multiplication(): tensor_out = kp.Tensor([0, 0, 0]) # 3. Initialise the Kompute Tensors in the GPU - mgr.eval_tensor_create_def([tensor_in_a, tensor_in_b, tensor_out]) + mgr.rebuild_tensors([tensor_in_a, tensor_in_b, tensor_out]) # 4. Define the multiplication shader code to run on the GPU @ps.python2shader diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index 9dee9df93..bec4b40ec 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -2,6 +2,7 @@ import os import kp import numpy as np +import logging DIRNAME = os.path.dirname(os.path.abspath(__file__)) @@ -16,7 +17,7 @@ def test_opmult(): mgr = kp.Manager() - mgr.eval_tensor_create_def([tensor_in_a, tensor_in_b, tensor_out]) + mgr.rebuild_tensors([tensor_in_a, tensor_in_b, tensor_out]) mgr.eval_algo_mult_def([tensor_in_a, tensor_in_b, tensor_out]) @@ -52,7 +53,7 @@ def test_opalgobase_data(): } """ - mgr.eval_tensor_create_def([tensor_in_a, tensor_in_b, tensor_out]) + mgr.rebuild_tensors([tensor_in_a, tensor_in_b, tensor_out]) mgr.eval_algo_str_def([tensor_in_a, tensor_in_b, tensor_out], shaderData) @@ -75,7 +76,7 @@ def test_opalgobase_file(): shaderFilePath = os.path.join(DIRNAME, "../../shaders/glsl/opmult.comp") - mgr.eval_tensor_create_def([tensor_in_a, tensor_in_b, tensor_out]) + mgr.rebuild_tensors([tensor_in_a, tensor_in_b, tensor_out]) mgr.eval_algo_file_def([tensor_in_a, tensor_in_b, tensor_out], shaderFilePath) @@ -93,7 +94,7 @@ def test_sequence(): tensor_in_b = kp.Tensor([1, 2, 3]) tensor_out = kp.Tensor([0, 0, 0]) - mgr.eval_tensor_create_def([tensor_in_a, tensor_in_b, tensor_out]) + mgr.rebuild_tensors([tensor_in_a, tensor_in_b, tensor_out]) shaderFilePath = os.path.join(DIRNAME, "../../shaders/glsl/opmult.comp") mgr.eval_async_algo_file_def([tensor_in_a, tensor_in_b, tensor_out], shaderFilePath) @@ -118,7 +119,8 @@ def test_workgroup(): tensor_a = kp.Tensor(np.zeros([16,8])) tensor_b = kp.Tensor(np.zeros([16,8])) - mgr.eval_tensor_create_def([tensor_a, tensor_b]) + + mgr.rebuild_tensors([tensor_a, tensor_b]) shader_src = """ #version 450 @@ -131,19 +133,21 @@ def test_workgroup(): void main() { uint index = gl_WorkGroupID.x*gl_NumWorkGroups.y + gl_WorkGroupID.y; - + toutx[index] = gl_GlobalInvocationID.x; touty[index] = gl_GlobalInvocationID.y; } """ shader_src = bytes(shader_src, encoding='utf8') - seq = mgr.create_sequence() + seq = mgr.create_sequence("new") seq.begin() seq.record_algo_data([tensor_a, tensor_b], shader_src, (16,8,1)) seq.end() seq.eval() - + mgr.eval_tensor_sync_local_def([tensor_a, tensor_b]) + assert np.all(tensor_a.numpy() == np.stack([np.arange(16)]*8, axis=1).ravel()) assert np.all(tensor_b.numpy() == np.stack([np.arange(8)]*16, axis=0).ravel()) + diff --git a/python/test/test_logistic_regression.py b/python/test/test_logistic_regression.py index f87375887..1fbcd5bcd 100644 --- a/python/test/test_logistic_regression.py +++ b/python/test/test_logistic_regression.py @@ -66,7 +66,7 @@ def test_logistic_regression(): params = [tensor_x_i, tensor_x_j, tensor_y, tensor_w_in, tensor_w_out_i, tensor_w_out_j, tensor_b_in, tensor_b_out, tensor_l_out, tensor_m] - mgr.eval_tensor_create_def(params) + mgr.rebuild_tensors(params) # Create a managed sequence sq = mgr.create_sequence()