[CIR] Upstream CUDA / HIP support from incubator
In the past year ClangIR. got CUDA and HIP support in the incubator (pass Polybench), adding these implementations to upstream would be a good initial task for someone who wants to get more involved. This is tracking the overall support, subtasks can be tracked in new issues.
(cc @koparasy @RiverDave @andykaylor)
I will give some pointers to the incubator project so people can follow them. By no means this is the proper and only order we should follow, but it definitely provides most directions.
The first thing on incubator that helped setting offload compilation was the work of @seven-mile . He has this issue that shows all the steps required to get OpenCL support for GPUs.
I could not find any other single point of documentation for the CUDA|HIP support. But one can follow the issues on the incubator.
For CUDA this link here should be a good starting point.
For HIP this link here should show most of the required work.
I have been reading OG Clang testing and here is a subset of tests I think we are able to built in incubator. Just to clarify this is my expectation, I did NOT test whether my expectation matches reality. I think though a reasonable target would be to support these tests after we finish porting the HIP/CUDA work from incubator to upstream:
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/address-spaces.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/const-var.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/device-stub.cu <--- Partially they test older CUDA versions here and RDC linkage. We have never worked on either AFAIK on incubator
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/device-init-fun.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/device-var-init.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/global-initializers.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/kernel-args.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/kernel-call.cu <---- Here the test also the per thread API which we had partially implemented in the incubator AFAIK.
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/kernel-stub-name.cu <---- @RiverDave take some inspiration from this one.
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/launch-bounds.cu <---- this we do not support on incubator, but it boils down in adding attributes or metadata to the kernels and usually you get quite some performance out of it. Nice to have.
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/ptx-kernels.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/surface.cu This one we are not having support on incubator, but I believe @RiverDave provided recently the basic infrastructure to start having such support.
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/texture.cu Same as above
- https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/lambda.cu This one tests dispatching GPU code through lambda capturing. We have not tested this in incubator I am uncertain whether we have support without doing anything extra, I am certain polybench is not using this pattern, I am also certain that any HPC C++ portability layer (https://github.com/kokkos/kokkos, https://github.com/llnl/RAJA) use this pattern.
@bcardosolopes @andykaylor One other note on incubator we structured our tests as:
test/CIR/Codegen/CUDA|HIP
On upstream OG structures them as:
test/CodegenCUDA|HIP
So there is one less nesting. If we want to follow closer the upstream test directory structure we may want to decide this now. I am fine either way.
Lastly, on upstream some tests under test/CodegenCUDA/ also test for HIP support. e.g. here. This avoids some test duplication effort. Especially on the interaction between codegen and the HIP|CUDA APIs the support is very similar.
I guess how do you prefer structuring the tests?
I would prefer to have the tests structured more like OG:
test/CIR/CodeGenCUDA|HIP
This makes it easier to run a subset of tests during development, and it will make things easier to find for developers who have worked mostly with OG.
OG way sounds good to me
With hopes of tracking this with more detail I've opened: https://github.com/llvm/llvm-project/issues/179278