Skip to content

Commit

Permalink
Update Python bindings and docstrings. Fix examples not building.
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Quill <[email protected]>
  • Loading branch information
robquill committed Aug 27, 2024
1 parent b085445 commit 650665b
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ KomputeModelML::train(std::vector<float> yData,
std::shared_ptr<kp::Algorithm> algorithm = mgr.algorithm(
params, shader, kp::Workgroup({ 5 }), std::vector<float>({ 5.0 }));

mgr.sequence()->eval<kp::OpTensorSyncDevice>(params);
mgr.sequence()->eval<kp::OpSyncDevice>(params);

std::shared_ptr<kp::Sequence> sq =
mgr.sequence()
->record<kp::OpTensorSyncDevice>({ wIn, bIn })
->record<kp::OpSyncDevice>({ wIn, bIn })
->record<kp::OpAlgoDispatch>(algorithm)
->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
->record<kp::OpSyncLocal>({ wOutI, wOutJ, bOut, lOut });

// Iterate across all expected iterations
for (size_t i = 0; i < ITERATIONS; i++) {
Expand Down
4 changes: 2 additions & 2 deletions examples/array_multiplication/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ main()
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, shader);

mgr.sequence()
->record<kp::OpTensorSyncDevice>(params)
->record<kp::OpSyncDevice>(params)
->record<kp::OpAlgoDispatch>(algo)
->record<kp::OpTensorSyncLocal>(params)
->record<kp::OpSyncLocal>(params)
->eval();

// prints "Output { 0 4 12 }"
Expand Down
6 changes: 3 additions & 3 deletions examples/logistic_regression/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ main()
wIn, wOutI, wOutJ,
bIn, bOut, lOut };

mgr.sequence()->eval<kp::OpTensorSyncDevice>(params);
mgr.sequence()->eval<kp::OpSyncDevice>(params);

std::vector<uint32_t> spirv2{ 0x1, 0x2 };

Expand All @@ -44,9 +44,9 @@ main()

std::shared_ptr<kp::Sequence> sq =
mgr.sequence()
->record<kp::OpTensorSyncDevice>({ wIn, bIn })
->record<kp::OpSyncDevice>({ wIn, bIn })
->record<kp::OpAlgoDispatch>(algorithm)
->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
->record<kp::OpSyncLocal>({ wOutI, wOutJ, bOut, lOut });

// Iterate across all expected iterations
for (size_t i = 0; i < ITERATIONS; i++) {
Expand Down
6 changes: 3 additions & 3 deletions examples/neural_network_vgg7/run_vgg7.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
if i == 0:
# For first layer, the input isn't on-device yet
things_to_sync_to_device.append(tensor_in)
last_seq.eval_async(kp.OpTensorSyncDevice(things_to_sync_to_device))
last_seq.eval_async(kp.OpSyncDevice(things_to_sync_to_device))
last_seq.eval_await()

# Prepare
Expand All @@ -101,7 +101,7 @@
# DEBUG:
# We want to see the output, copy it to local
last_seq = kpm.sequence()
last_seq.eval_async(kp.OpTensorSyncLocal([tensor_out]))
last_seq.eval_async(kp.OpSyncLocal([tensor_out]))
last_seq.eval_await()
tensor_out.data().astype("<f4", "C").tofile("raw" + str(i) + ".bin")

Expand All @@ -114,7 +114,7 @@

# Download output
fin_seq = kpm.sequence()
fin_seq.eval_async(kp.OpTensorSyncLocal([tensor_in]))
fin_seq.eval_async(kp.OpSyncLocal([tensor_in]))
fin_seq.eval_await()

# Output
Expand Down
2 changes: 1 addition & 1 deletion examples/python_naive_matmul/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():

for MatMulOp in [MatMulOp1, MatMulOp2, MatMulOp3]:
tensor_out.data()[:] = 0
mgr.sequence().record(kp.OpTensorSyncDevice([tensor_out]))
mgr.sequence().record(kp.OpSyncDevice([tensor_out]))
matmul_op = MatMulOp(mgr)
matmul_op(tensor_shape, tensor_in_1, tensor_in_2, tensor_out)

Expand Down
4 changes: 2 additions & 2 deletions examples/python_naive_matmul/first_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def main():
[]) # push_consts

(mgr.sequence()
.record(kp.OpTensorSyncDevice(params))
.record(kp.OpSyncDevice(params))
.record(kp.OpAlgoDispatch(algo))
.record(kp.OpTensorSyncLocal(params))
.record(kp.OpSyncLocal(params))
.eval())

print(f'Output :\n{tensor_out.data().reshape(tensor_shape)}')
Expand Down
4 changes: 2 additions & 2 deletions examples/python_naive_matmul/imp1_naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def __call__(self, tensor_shape: tuple[int, int], tensor_in_1: kp.Tensor, tensor
[]) # push_consts

(self.mgr.sequence()
.record(kp.OpTensorSyncDevice([tensor_in_1, tensor_in_2]))
.record(kp.OpSyncDevice([tensor_in_1, tensor_in_2]))
.record(kp.OpAlgoDispatch(self.algo))
.record(kp.OpTensorSyncLocal([tensor_out]))
.record(kp.OpSyncLocal([tensor_out]))
.eval())


Expand Down
4 changes: 2 additions & 2 deletions examples/python_naive_matmul/imp2_tiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def __call__(self, tensor_shape: tuple[int, int], tensor_in_1: kp.Tensor, tensor
[]) # push_consts

(self.mgr.sequence()
.record(kp.OpTensorSyncDevice([tensor_in_1, tensor_in_2]))
.record(kp.OpSyncDevice([tensor_in_1, tensor_in_2]))
.record(kp.OpAlgoDispatch(self.algo))
.record(kp.OpTensorSyncLocal([tensor_out]))
.record(kp.OpSyncLocal([tensor_out]))
.eval())


Expand Down
4 changes: 2 additions & 2 deletions examples/python_naive_matmul/imp3_better_tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def __call__(self, tensor_shape: tuple[int, int], tensor_in_1: kp.Tensor, tensor
[]) # push_consts

(self.mgr.sequence()
.record(kp.OpTensorSyncDevice([tensor_in_1, tensor_in_2]))
.record(kp.OpSyncDevice([tensor_in_1, tensor_in_2]))
.record(kp.OpAlgoDispatch(self.algo))
.record(kp.OpTensorSyncLocal([tensor_out]))
.record(kp.OpSyncLocal([tensor_out]))
.eval())


Expand Down
Loading

0 comments on commit 650665b

Please sign in to comment.