NVIDIA / cuda-python

CUDA Python Low-level Bindings
https://nvidia.github.io/cuda-python/
Other
878 stars 73 forks source link

Document best practices in preparing arguments for `cuLaunchKernel` #127

Open leofang opened 1 month ago

leofang commented 1 month ago

@gigony complained the following example is unclear compared to CuPy's RawKernel, and I agree. https://github.com/NVIDIA/cuda-python/blob/e1e332564c48db556212d59262a149b1a63285e8/docs_src/source/overview.md?plain=1#L208-L223 Specifically, how to pass typed pointers and scalars is really unclear.

This also raises the question: It seems NumPy has to be a run-time dependency of cuda-python (which is completely fine, since it is impossible that users have GPU projects installed to an environment where NumPy does not exist, we just need to ensure this intent is expressed as a package dependency).

For comparison, here's cupy.RawKernel's documentation https://docs.cupy.dev/en/stable/user_guide/kernel.html#kernel-arguments

vzhurba01 commented 2 weeks ago

https://github.com/NVIDIA/cuda-python/blob/main/cuda_bindings/tests/test_kernelParams.py

To add on, ctypes is another alternative for constructing kernel params. Both the ctypes and numpy approaches are tested in test_kernelParams.