llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-repl][TRACKING] Bringing HIP Support to clang-repl

Open AdityaSinha149 opened this issue 2 months ago • 2 comments

Bringing HIP Support to clang-repl

This tracks the effort to enable HIP compilation and execution in clang-repl (Clang's incremental C++ interpreter), targeting the AMDGPU backend. It follows the same shape as the existing CUDA support: compile each incremental input for both host and device, and make the device code available to the host so kernels can run.

Overview

Part 1: Foundational Compiler Support

Independent compiler fixes that the rest of the work relies on. These can land first, on their own.

  • #218659 Why: In clang-repl a kernel launch (kernel<<<>>>()) is typed at the top level, so there is no enclosing function. Normal compilation always has a caller, and Sema assumed one existed so a top-level launch tripped an assertion/error. This relaxes that assumption so REPL-style launches are accepted.

  • #217228 Why: HIP emits a per-compilation-unit __hip_cuid_ global. clang-repl compiles each input as its own module, so this global would be emitted repeatedly and collide at JIT link time (duplicate symbol). Skipping it in incremental mode avoids those clashes.

  • #218784 Why: Each REPL input is a separate, unlinked device module. A __device__ helper defined in an earlier input is only a declaration in a later input's module, so an internal/weak helper has nothing to link against and fails at runtime. This re-emits the needed definition into the module that uses it. Standalone compiler change; does not depend on the clang-repl PRs.

Part 2: HIP Environment Initialization

  • #231133 Adds the abstract IncrementalDeviceParser base class so CUDA and HIP share one device-parsing flow instead of separate copies. NFC, no functional changes. Dependencies: none.

  • #231391 Adds the OffloadType enum (Detect, CUDA, HIP), Interpreter::createWithDevice() and the IncrementalHIPDeviceParser skeleton. The parser constructor checks the AMDGPU target triple, and binary generation is a stub that returns an unsupported error for now. Dependencies: #231133.

  • #231783 Adds the -hip option: builds the HIP host and device compilers, creates the HIP device parser and loads the HIP runtime. It also connects the HIP device parser to the interpreter. On its own it only sets up the environment and reports that binary generation isn't supported yet. Dependencies: #231391.

Part 3: HIP Device Compilation

  • #225049 Moves normalizeForBundler from HIPUtility.cpp into OffloadBundler so the bundle target-name policy (triple normalization + hipv4) can be shared by both the AOT compiler and clang-repl instead of being duplicated. Pure refactor, no functional changes (NFC). Dependencies: none.

  • The PRs for the HIP device parser (HSACO generation and bundling) are left.

AdityaSinha149 avatar Sep 08 '26 17:09 AdityaSinha149

Hi all, thank you for working on this.

There are several design points I think our community should discuss. For example, if we can consolidate that better with the existing cuda and how difficult would it be to add SYCL support.

Can you open an RFC before proceeding forward?

vgvassilev avatar Sep 30 '26 14:09 vgvassilev

Hi all, thank you for working on this.

There are several design points I think our community should discuss. For example, if we can consolidate that better with the existing cuda and how difficult would it be to add SYCL support.

Can you open an RFC before proceeding forward?

Hi @vgvassilev , I have opened this RFC relating to this issue.

AdityaSinha149 avatar Oct 05 '26 16:10 AdityaSinha149