﻿# HIP relocatable device code: host linking does not resolve a cross-file device call

Distinguish HIP host objects, relocatable device code, architecture-specific device linking and bundled artifacts when a device function crosses translation-unit boundaries.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-hip-rdc-cross-tu-device-link-stage/
Language: en

## Identify which processor makes the call

A project moves a device helper into another source file and adds that file to the host linker. The [Clang HIP documentation](https://clang.llvm.org/docs/HIPSupport.html) distinguishes host linking from device-code compilation modes. A host call across files and a device function calling another device function are different link relationships. First draw the actual caller and callee. Adding a library to a normal host link command does not automatically establish the required device-side relationship.

## Select a compatible device compilation mode

Relocatable device code supports linking device code across translation units through a later device-link step. The compilation mode must be consistent with the intended call graph and build pipeline. Do not fix a missing device symbol by merely adding a host declaration or changing a filename extension. Preserve declarations, definitions, target architectures and the options used for each contributing object. A declaration makes a function visible to compilation; it does not supply its implementation to the final device artifact.

## Follow the compiler driver's actual stages

The [HIP compiler guide](https://rocm.docs.amd.com/projects/HIP/en/latest/understand/compilers.html) explains HIP compiler and driver context. Inspect verbose build output to identify host compilation, device compilation and the final device-link stage rather than treating one successful command as an opaque proof. Static archives and generated objects must reach the correct stage. Keep a minimal cross-file helper example available so that build-system changes can be distinguished from errors in a much larger numerical kernel.

## Do not confuse bundling with resolution

The [Clang offload bundler documentation](https://clang.llvm.org/docs/ClangOffloadBundler.html) describes packaging offload artifacts. Packaging code for targets and resolving references between device compilation units are different jobs. An artifact containing several target images does not prove that a particular image contains the resolved helper needed by its kernel. Check the selected architecture and built artifact, especially when a mixed build directory contains outputs from earlier compiler configurations.

## Validate the cross-file behavior

Use a small kernel whose result visibly depends on the separately defined device function. Rebuild from the declared inputs and check completed output on the intended target. Related guides explain [HIP portability](/journal/learn-hip-launch-portability/) and [reproducible stacks](/journal/software-stack-reproducibility/). This establishes the tested cross-unit call and build contract. It does not imply that a device function can dynamically call arbitrary host code or that shared-library loading makes every form of device linking automatic.
