Skip to content

Support for CUDA Tile C++ kernels - #404

Open
benvanwerkhoven wants to merge 4 commits into
masterfrom
support_tile_kernels
Open

Support for CUDA Tile C++ kernels#404
benvanwerkhoven wants to merge 4 commits into
masterfrom
support_tile_kernels

Conversation

@benvanwerkhoven

Copy link
Copy Markdown
Collaborator

This pull request adds support for tuning CUDA Tile C++ kernels using the cuda-python backend. CUDA Tile C++ was introduced in CUDA 13.3 and requires a C++ compiler that supports C++20.

For a while I have been trying to get it to work with NVRTC, but without much luck unfortunately. The kernels do compile with NVRTC and produce no compiler errors, but result in all kinds of errors when you try to load the compiled CUBIN or TileIR binaries, or when you try to retrieve the mangled/lowered/nonmangled name from the compiled program. When I finally managed to retrieve the NVRTC compiled kernels (either as cuFunction or cuKernel), I got segmentation faults when trying to launch those kernels (either with cuLaunchKernel or cuLaunchKernelEx).

After trying many different flavors of retrieving and launching the NVRTC compiled kernels, I decided to go for the NVCC route, which is also taken by Nvidia's Tile-Gym (https://github.com/NVIDIA/TileGym/blob/ff2a52ec4895764cb48473312164471fd031021d/src/tilegym/ops/tilecpp/utils/_cuda_utils.py#L249). This route also uses the cuda.core Python bindings, which are more high-level than the cuda.bindings APIs that we typically use.

It all feels a bit like a workaround, because it really seems that it should be possible to compile tile kernels with NVRTC. It is also quite a bit slower to dump the kernel to a file, call nvcc in a subprocess, and read the tilecubin back in. However, for now it seems to be the only route that actually works. Perhaps in the future we can simplify the code again when NVRTC and its Python bindings fully support tile kernels.

The entire use case of using Python to compile CUDA Tile C++ kernels is likely something that is not the typical path that CUDA/NVRTC developers had in mind. Also the documentation seems to direct Python users to cuTile rather than CUDA Tile C++ kernels. This is understandable and indeed for most Python users it is probably more convenient to just use cuTile. However, we're specifically interested in compiling and calling CUDA Tile C++ kernels from Python, which is a bit more of a hassle for now.

The current state of this pull is that it works on my system, but needs to be tested on other systems. There is an example kernel and script that tunes it for now. However, I need to add more tests and also check how errors like 'too much shared memory' etc can be captured when compiling this type of kernel.

@sonarqubecloud

Copy link
Copy Markdown

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

Successfully merging this pull request may close these issues.

1 participant