Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple and extended python examples do not work (v 0.7.0) #228

Closed
yves-surrel opened this issue Jun 6, 2021 · 5 comments
Closed

Simple and extended python examples do not work (v 0.7.0) #228

yves-surrel opened this issue Jun 6, 2021 · 5 comments

Comments

@yves-surrel
Copy link

In Line 28 of the "simple" example, OpAlgoSyncLocal does not exist. I tried replacing by OpTensorSyncLocal, but the test fails as tensor_out.data() remains stuck to (0, 0, 0).

The "extended" example does not compile at line 8

 tensor_in_a = Tensor([2, 2, 2])

with

TypeError: kp.Tensor: No constructor defined!

At line #12

mgr.eval_tensor_create_def([tensor_in_a, tensor_in_b, tensor_out])

refers to a non-existent attribute (eval_tensor_create_def) of Manager, etc.

(MacBookPro 2017, MacOs 11.2.1)

@axsaucedo
Copy link
Member

Thanks @yves-surrel - it seems the examples are outdated, I will have a look at this. Are you abel to run the python test files to see if those work? It's under python/test

@yves-surrel
Copy link
Author

Here they are:

https://github.com/EthicalML/vulkan-kompute/blob/master/python/test/test_kompute.py

In [16]: test_end_to_end()

In [17]: test_shader_str()

In [18]: test_sequence()
WARNING:kp:Kompute Sequence destroy called with null Device pointer
WARNING:kp:Kompute Tensor destructor reached with null Device pointer
WARNING:kp:Kompute Tensor destructor reached with null Device pointer
WARNING:kp:Kompute Tensor destructor reached with null Device pointer

In [19]: test_pushconsts()

In [20]: test_workgroup()
[ 0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  1.  1.  1.  1.  1.  1.  2.  2.
  2.  2.  2.  2.  2.  2.  3.  3.  3.  3.  3.  3.  3.  3.  4.  4.  4.  4.
  4.  4.  4.  4.  5.  5.  5.  5.  5.  5.  5.  5.  6.  6.  6.  6.  6.  6.
  6.  6.  7.  7.  7.  7.  7.  7.  7.  7.  8.  8.  8.  8.  8.  8.  8.  8.
  9.  9.  9.  9.  9.  9.  9.  9. 10. 10. 10. 10. 10. 10. 10. 10. 11. 11.
 11. 11. 11. 11. 11. 11. 12. 12. 12. 12. 12. 12. 12. 12. 13. 13. 13. 13.
 13. 13. 13. 13. 14. 14. 14. 14. 14. 14. 14. 14. 15. 15. 15. 15. 15. 15.
 15. 15.]
[0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7.
 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7.
 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7.
 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7.
 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7. 0. 1. 2. 3. 4. 5. 6. 7.
 0. 1. 2. 3. 4. 5. 6. 7.]

In [21]: test_mgr_utils()

In [22]: 

https://github.com/EthicalML/vulkan-kompute/blob/master/python/test/test_array_multiplication.py
pass

https://github.com/EthicalML/vulkan-kompute/blob/master/python/test/test_logistic_regression.py
pass

https://github.com/EthicalML/vulkan-kompute/blob/master/python/test/test_tensor_types.py

In [3]: test_type_float()

In [4]: test_type_float_double_incorrect()

In [5]: test_type_double()
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Unable to convert SPIR-V to MSL:
MSL conversion error: double types are not supported in buffers in MSL.


[mvk-error] VK_ERROR_INVALID_SHADER_NV: Compute shader function could not be compiled into pipeline. See previous logged error.
Traceback (most recent call last):

  File "<ipython-input-5-2d088eb457a5>", line 1, in <module>
    test_type_double()

  File "/Volumes/FAT/Developpement/Python/core/untitled1.py", line 122, in test_type_double

RuntimeError: vk::Device::createComputePipeline: ErrorInvalidShaderNV


In [6]: test_type_int()
Dtype value int32

In [7]: test_type_unsigned_int()
Dtype value uint32

In [8]: test_tensor_numpy_ownership()
ERROR:kp:Kompute Manager destructor reached with null Device pointer

@yves-surrel
Copy link
Author

Here is the working "simple" example:

from kp import Manager, Tensor, OpTensorSyncDevice, OpTensorSyncLocal, OpAlgoDispatch
from pyshader import python2shader, ivec3, f32, Array

mgr = Manager()

# Can be initialized with List[] or np.Array
tensor_in_a = mgr.tensor([2, 2, 2])
tensor_in_b = mgr.tensor([1, 2, 3])
tensor_out = mgr.tensor([0, 0, 0])

sq = mgr.sequence()

sq.eval(OpTensorSyncDevice([tensor_in_a, tensor_in_b, tensor_out]))

# Define the function via PyShader or directly as glsl string or spirv bytes
@python2shader
def compute_shader_multiply(index=("input", "GlobalInvocationId", ivec3),
                            data1=("buffer", 0, Array(f32)),
                            data2=("buffer", 1, Array(f32)),
                            data3=("buffer", 2, Array(f32))):
    i = index.x
    data3[i] = data1[i] * data2[i]

algo = mgr.algorithm([tensor_in_a, tensor_in_b, tensor_out], compute_shader_multiply.to_spirv())

# Run shader operation synchronously
sq.eval(OpAlgoDispatch(algo))

sq.eval(OpTensorSyncLocal([tensor_out]))

assert tensor_out.data().tolist() == [2.0, 4.0, 6.0]```

@axsaucedo
Copy link
Member

Thank you @yves-surrel - would you be interested on contributing this as a PR? I can help testing that the documentation all works as expected

@axsaucedo
Copy link
Member

I've updated the readme to align with the test to ensure that it correctly runs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants