Updated python to align with new structure

This commit is contained in:
Alejandro Saucedo 2021-02-09 19:19:09 +00:00
parent dead40c871
commit 650975838c
4 changed files with 18 additions and 21 deletions

View file

@ -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<kp::OpTensorCreate>,
"Records operation to create and initialise tensor GPU memory and buffer")
.def("record_tensor_copy", &kp::Sequence::record<kp::OpTensorCopy>,
"Records operation to copy one tensor to one or many tensors")
.def("record_tensor_sync_device", &kp::Sequence::record<kp::OpTensorSyncDevice>,
@ -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<kp::OpTensorCreate>,
"Evaluates operation to create and initialise tensor GPU memory and buffer with new anonymous Sequence")
.def("eval_tensor_copy_def", &kp::Manager::evalOpDefault<kp::OpTensorCopy>,
"Evaluates operation to copy one tensor to one or many tensors with new anonymous Sequence")
.def("eval_tensor_sync_device_def", &kp::Manager::evalOpDefault<kp::OpTensorSyncDevice>,
@ -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<kp::OpTensorCreate>,
"Evaluates operation to create and initialise tensor GPU memory and buffer with explicitly named Sequence")
.def("eval_tensor_copy", &kp::Manager::evalOp<kp::OpTensorCopy>,
"Evaluates operation to copy one tensor to one or many tensors with explicitly named Sequence")
.def("eval_tensor_sync_device", &kp::Manager::evalOp<kp::OpTensorSyncDevice>,
@ -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<kp::OpTensorCreate>,
"Evaluates asynchronously operation to create and initialise tensor GPU memory and buffer with anonymous Sequence")
.def("eval_async_tensor_copy_def", &kp::Manager::evalOpAsyncDefault<kp::OpTensorCopy>,
"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<kp::OpTensorSyncDevice>,
@ -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<kp::OpTensorCreate>,
"Evaluates asynchronously operation to create and initialise tensor GPU memory and buffer with explicitly named Sequence")
.def("eval_async_tensor_copy", &kp::Manager::evalOpAsync<kp::OpTensorCopy>,
"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<kp::OpTensorSyncDevice>,

View file

@ -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

View file

@ -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())

View file

@ -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()