Skip to content

Early RDC for HIP - #774

Open
robinson96 wants to merge 27 commits into
developfrom
feature/probinso/earlyRDC_5
Open

Early RDC for HIP#774
robinson96 wants to merge 27 commits into
developfrom
feature/probinso/earlyRDC_5

Conversation

@robinson96

Copy link
Copy Markdown
Contributor

Overview

This change extends BLT’s target helpers with support for HIP relocatable device code (RDC) and early device linking.

It allows projects to identify the subset of sources that require RDC, compile those sources separately with -fgpu-rdc, perform the HIP device link before the final
application link, and propagate the resulting archive through normal CMake target dependencies.

The ALE3D merge request updates the cmake/blt submodule reference to the corresponding BLT implementation.

Motivation

Large HIP applications can incur substantial work during the final device-link step when every RDC object is deferred until executable linking. Performing device linking
earlier at the library boundary can:

  • Reduce the amount of device code processed during the final executable link.
  • Encapsulate device-link requirements within the library that owns the HIP sources.
  • Allow mixed targets containing both ordinary and RDC-enabled sources.
  • Avoid propagating both the original RDC archive and its device-linked replacement, which can cause duplicate host symbols.
  • Preserve normal BLT behavior for CUDA and non-HIP configurations.

BLT interface changes

blt_add_library() and blt_add_executable() now accept these HIP-specific arguments:

  • RDC: Enables HIP RDC compilation and linking.
  • RDC_SOURCES: Identifies the sources that require RDC.
  • EARLY_RDC: Enables early device linking for the RDC sources.
  • EARLY_RDC_SUFFIX: Overrides the generated-target suffix. The default is _earlyrdc.

These options are effective only when BLT_ENABLE_HIP is enabled.

Target behavior

Configuration Result
Ordinary target Existing BLT behavior is preserved.
RDC TRUE RDC sources are compiled into a host archive using -fgpu-rdc and linked transitively.
Partial-library EARLY_RDC TRUE Non-RDC sources remain in the base library. RDC sources produce private _host and device-linked _device archives.
Full-library EARLY_RDC TRUE The public base becomes an interface target. A private host archive is transformed into the _device archive propagated to consumers.
Partial-executable EARLY_RDC TRUE Ordinary sources remain in the executable while RDC sources are transformed into supporting _host and _device libraries.

Full-RDC executables are not supported by this implementation; early-RDC executables must retain at least one non-RDC source.

Implementation details

Source partitioning

BLT separates RDC_SOURCES from the target’s ordinary sources. This prevents the same source from being compiled into both the base target and the RDC archive.

The RDC sources are compiled with -fgpu-rdc, while ordinary sources in a mixed target retain their normal compilation flags. Executables that require RDC use the HIP
linker for the final link.

Early device-link helper

A new blt_setup_hip_early_rdc_target() helper:

  1. Builds the RDC source subset into a host archive.
  2. Determines the requested ROCm architecture flags.
  3. Invokes the new scripts/erdc.sh helper.
  4. Produces a combined uber.o containing device-linked code and its associated host code.
  5. Wraps that object in a generated _device static library.
  6. Propagates the device archive through the base target’s link interface.

Dependencies that expose an early-RDC host archive can also be supplied to the device-link operation. If a dependency already exposes a generated device archive, its host
input archive is not added again. This avoids duplicate host objects and duplicate-symbol failures.

erdc.sh

The new script uses ROCm’s LLVM tools to:

  • Extract one or more input archives while preserving archive order.
  • Keep identically named objects from separate archives in distinct directories.
  • Remove duplicate archive-member entries.
  • Run the HIP relocatable device link with the selected offload architectures.
  • Remove CLANG_OFFLOAD_BUNDLE sections that are invalid during later partial-RDC links.
  • Emit either a combined object or a static archive.
  • Support explicit output names, temporary directories, retained intermediates, and verbose execution.

Generated-target metadata

BLT now exposes variables describing the targets produced by each macro.

For libraries:

  • _TARGETS
  • _INTERFACE_TARGETS
  • _NONINTERFACE_TARGETS
  • _EARLY_RDC_HOST_TARGET
  • _EARLY_RDC_DEVICE_TARGET

For executables:

  • _TARGETS
  • _EXEC_TARGETS
  • _LIB_TARGETS

These variables allow downstream install and export logic to handle all generated targets without duplicating BLT’s naming rules.

Compatibility

  • The new behavior is gated by BLT_ENABLE_HIP.
  • Existing targets that do not request RDC or EARLY_RDC retain their prior behavior.
  • CUDA and non-HIP target setup is unchanged.
  • Header-only libraries remain interface targets and do not participate in early RDC.
  • The generated device archive replaces the corresponding host input archive in consumer link interfaces to prevent duplicate symbols.

robinson96 and others added 27 commits August 31, 2026 14:14
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