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

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