SciNim / nimcuda

Nim bindings for CUDA
Apache License 2.0
42 stars 9 forks source link

Nvrtc #23

Open lilkeet opened 5 days ago

lilkeet commented 5 days ago

What

This pr adds two new modules to the library: nvrtc and cuda.

cuda is better known the cuda driver api, which is very similar to the cuda runtime api but a bit lower level.

nvrtc is a module that enables the use of runtime compilation of cuda code.

An example of runtime compilation is also added. https://github.com/SciNim/nimcuda/issues/19

Why

Currently, there is no good way to run cuda kernels from Nim. Here are some known options:

Use a cuda compiler to compile the entire project

Transpile nim code to ptx

This pr enables a native, easy solution. Checkout the example (355290f903e316ca1a7303337a61b5ba9eede3f5) for all that is required to run a cuda kernel. Much of it is boilerplate that could be minimized by a higher-level library.

The cuda driver api was added mostly due to the fact that nvrtc requires that you use it instead of the cuda runtime api, but it should've been added long ago, imo.