Linux Kernel & OS

GSoC 2026 prototype merges host and device ClangIR for cross-boundary CUDA/HIP optimization

Key Takeaway

A prototype ClangIR combine pipeline gives the compiler a single view of host launch sites and GPU kernels, yielding a 1.67x geomean speedup in GPU-region time on PolyBench/GPU via forwarded alias information.

Summary

Google Summer of Code 2026 contributor David Rivera, mentored by Konstantinos Parasyris and Joseph Huber, published results from the Host-Device CIR Combine Pipeline project. The prototype merges the host and device ClangIR modules of a CUDA or HIP translation unit into one MLIR module, runs optimization passes that can see both sides, then splits the module back into the normal per-target compilation pipelines. It is exposed through a --clangir-offload-merge driver flag and a standalone cir-offload-merge tool, with new CIRMergeJobAction and CIRSplitJobAction job actions.

The work builds on months of upstream CUDA and HIP parity work in ClangIR covering calling conventions, kernel registration, NVPTX builtins, address spaces and function attributes. Across 21 PolyBench/GPU programs, CIR matched classic CodeGen at 0.998x runtime on an NVIDIA H100 and 1.008x on an AMD MI300X, with roughly 3% more compile time. The merge prototype itself is not merged upstream yet, but the container foundations have landed following Dinos's RFC, and a roadmap exists for the remaining work.

How the host-device CIR merge pipeline works

  • Compilation model: Clang compiles a CUDA or HIP translation unit as one host cc1 plus one device cc1 per GPU architecture, so no phase ever sees both launch sites and kernels; the merge pipeline stops each compilation after CIR, combines the modules, runs cross-boundary passes, splits, and resumes each cc1.
  • Container representation: The merged module is an ordinary MLIR module with nested host and device modules tagged via cir.offload.kind attributes; after review of PR #206576, the dedicated container op was dropped in favor of verifying invariants in CIRDialect::verifyOperationAttribute, mirroring gpu.container_module.
  • Launch-to-kernel linking: A launch does not call the kernel directly but goes through a Clang-generated __device_stub__ that pushes call configuration and calls cudaLaunchKernel, so the merge must connect stubs and launch sites to the corresponding kernels.
  • Implemented optimizations: Three passes were built on the merged view: kernel argument constant propagation, launch bounds propagation, and alias information forwarded from host launch sites, the last providing the largest gains at a 1.67x geomean in GPU-region time on PolyBench/GPU on an NVIDIA A10.
  • Parity baseline: CIR reached 0.998x runtime on H100 and 1.008x on MI300X versus classic CodeGen across 21 PolyBench/GPU programs, with about 3% compile-time overhead, and 25 PRs from the project were merged upstream.

Why it matters

The prototype targets a long-standing limitation in CUDA and HIP compilation: device code must conservatively assume pointer aliasing between kernel arguments because the host allocation context is invisible. If the merge pipeline lands upstream, Clang could deliver alias and launch-bounds information to GPU kernels without source changes, benefiting HIP code on AMD hardware and CUDA code on NVIDIA hardware alike. The work also strengthens ClangIR as a viable path for GPU compilation, which matters for LLVM downstream consumers and distributions packaging Clang toolchains.

Original reference: blog.llvm.org →