﻿# HIP feature macros: device compilation does not discover the host’s installed GPU

Separate HIP device feature guards, host runtime capability queries and packaged GPU code objects when selecting an architecture-dependent implementation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-hip-feature-macro-host-runtime-query-boundary/
Language: en

## Diagnose the unexpectedly disabled host branch

A program compiles a specialized kernel but its host selection logic always rejects the fast path. Inspect whether the host used a device feature macro as though it represented installed hardware. Building the executable and running it on a machine are separate stages. The build machine may differ from the deployment machine, and a process may select a different GPU from the one a developer assumed while creating its configuration.

## Keep feature macros in their intended compilation pass

The [HIP porting guide](https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/hip_porting_guide.html) documents device feature macros and warns against relying on them in host code. Their host values do not discover available GPUs. The device-compilation marker distinguishes the compilation pass; it is not itself a named hardware capability. Use the appropriate feature guard around the device implementation and keep host selection independent from that preprocessing decision.

## Query the selected device at runtime

Use the documented device-properties or device-attribute query for the capability actually required by the algorithm. Check query results and retain the selected device identity with the dispatch decision. A feature that exists on another installed GPU does not justify launching that path on the current one. The [hardware-feature overview](https://rocm.docs.amd.com/projects/HIP/en/latest/reference/hardware_features.html) also cautions that capability support does not establish expected performance, so correctness selection and timing remain different questions.

## Verify that the executable contains a usable implementation

The [Clang HIP documentation](https://clang.llvm.org/docs/HIPSupport.html) describes device compilation and embedded code objects. A positive runtime property cannot create a missing compatible binary implementation. Preserve the relationship between compiled targets, feature guards and the host dispatch table. A fallback must also have a valid implementation for its selected target, rather than merely an accessible host function name that eventually attempts an unsupported device launch.

## Test mismatches as separate failure cases

Exercise a disabled feature, an unavailable compiled target and a failed runtime query independently. Record which boundary rejected each case before measuring successful dispatch. The existing [HIP launch-portability guide](/journal/learn-hip-launch-portability/) and [software reproducibility material](/journal/software-stack-reproducibility/) give broader context. This approach makes deployment behavior explainable: preprocessing, packaged implementations and selected-device capabilities answer different questions, even when they appear together in the same source file or build configuration.
