Skip to content

jit: discover ROCm via rocm-sdk-devel pip package - #3264

Merged
valarLip merged 3 commits into
mainfrom
matthias.find-rocm-sdk-devel
Jun 15, 2026
Merged

valarLip merged 3 commits into
mainfrom
matthias.find-rocm-sdk-devel

Conversation

@mgehre-amd

@mgehre-amd mgehre-amd commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Make AITER work out of the box with ROCm installed into venv, without needing to set ROCM_PATH or PATH.

Summary

When aiter runs inside a venv with ROCm python packages, _find_rocm_home() fails in two distinct ways:

  1. No PATH — shutil.which("hipcc") returns None, ROCM_HOME falls back to /opt/rocm (or stays unset), and importing aiter crashes at module load:

    File "cpp_extension.py", line 169, in <module>
        HIP_VERSION = get_hip_version()
    RuntimeError: ROCm version file not found
    

    because cpp_extension.py eagerly resolves HIP_VERSION via executable_path("hipconfig") even when no JIT compile is needed.

  2. Venv on PATH — which("hipcc") returns .venv/bin/hipcc, which is a Python wrapper script (from rocm_sdk_core._cli import hipcc; sys.exit(hipcc())), not a real binary. realpath() leaves it in place, so ROCM_HOME = .venv and the linker is invoked with -L.venv/lib, where libamdhip64 does not exist:

    /usr/bin/ld: cannot find -lamdhip64: No such file or directory
    

Reproducer

Requires uv (https://docs.astral.sh/uv/) on a host without a system ROCm install, or one where /opt/rocm is not what you intend to use.

# 1. Fresh venv with rocm-sdk-devel only
uv venv --python 3.12 /tmp/aiter-repro-venv
VENV=/tmp/aiter-repro-venv
uv pip install --python "$VENV/bin/python" \
    --index-url https://rocm.nightlies.amd.com/v2/gfx115X-dgpu/ \
    rocm[devel] torch

# 2. Install aiter (editable from a fresh clone)
git clone https://github.com/ROCm/aiter.git /tmp/aiter-repro
cd /tmp/aiter-repro
git submodule update --init --recursive
uv pip install --python "$VENV/bin/python" -e .

# 3a. Case 1 — PATH unset
"$VENV/bin/python" -c "import aiter"
# Fails with:
#   File ".../cpp_extension.py", line 169, in <module>
#       HIP_VERSION = get_hip_version()
#   RuntimeError: ROCm version file not found

# 3b. Case 2 — PATH set to the venv's bin
PATH="$VENV/bin:/usr/bin:/bin" "$VENV/bin/python" -c "import aiter"
# Fails during JIT build of module_aiter_core with:
#   FAILED: module_aiter_core.so
#   c++ ... -L<VENV>/lib -lamdhip64 -o module_aiter_core.so
#   /usr/bin/ld: cannot find -lamdhip64: No such file or directory

With this PR, both invocations succeed: case 1 picks up the prebuilt .so (or, on first run, builds one); case 2 JIT-builds against <VENV>/lib/python*/site-packages/_rocm_sdk_devel/lib/libamdhip64.so.

Fix

  • cpp_extension.py — new "Guess Pa opt 1121 #2" in _find_rocm_home(): detect _rocm_sdk_devel via importlib.util.find_spec. If it contains a real bin/hipconfig, use the package directory as ROCM_HOME. This runs ahead of the hipcc-on-PATH heuristic so it fixes both cases above without changing behavior on systems with a normal ROCm install at /opt/rocm or ROCM_HOME already set.
  • core.py — hip_flag_checker and check_LLVM_MAIN_REVISION previously invoked bare hipcc via subprocess, relying on PATH. They now use executable_path("hipcc") so JIT-built modules pick up the bundled compiler.

Test plan

  • Reproducer above fails on main and passes with this PR.
  • On a host with a normal /opt/rocm install and no _rocm_sdk_devel package, _find_rocm_home() falls through to the existing hipcc-on-PATH / /opt/rocm heuristics unchanged.

When aiter runs inside a venv whose only ROCm install is the
rocm-sdk-devel pip package, _find_rocm_home() previously failed in two
ways:

1. Without PATH set, `shutil.which("hipcc")` returns None and
   ROCM_HOME falls back to /opt/rocm (or fails outright). Importing
   aiter then crashes at module load because cpp_extension eagerly
   calls `get_hip_version()` -> `executable_path("hipconfig")`.

2. With the venv on PATH, `which("hipcc")` finds .venv/bin/hipcc,
   which is a python wrapper script — not a real binary. realpath()
   leaves it in place, so ROCM_HOME becomes the venv root and the
   linker gets `-L.venv/lib`, where libamdhip64 does not exist.

Detect the rocm-sdk-devel package via
`importlib.util.find_spec("_rocm_sdk_devel")` and, when it contains a
real `bin/hipconfig`, use its package directory as ROCM_HOME. This
runs ahead of the hipcc-on-PATH lookup so it also fixes case (2).

Also route the bare `hipcc` invocations in core.py
(`hip_flag_checker`, `check_LLVM_MAIN_REVISION`) through
`executable_path("hipcc")`, so JIT-built modules pick up the bundled
compiler in the same setups.

Changes:
- cpp_extension.py: new "Guess #2" in _find_rocm_home() that resolves
  ROCM_HOME from the rocm-sdk-devel package before falling back to the
  hipcc-on-PATH heuristic.
- core.py: hip_flag_checker and check_LLVM_MAIN_REVISION now resolve
  hipcc via executable_path (shlex-quoted for the shell pipeline in
  check_LLVM_MAIN_REVISION).

Verified by importing aiter with the venv python and both PATH set
(triggers a clean JIT build) and PATH empty (loads the prebuilt .so);
both succeed.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 3264 --add-label <label>

@mgehre-amd
mgehre-amd marked this pull request as ready for review May 19, 2026 10:23
@mgehre-amd
mgehre-amd requested review from a team and Copilot May 19, 2026 10:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves ROCm toolchain discovery for AITER’s JIT flow when ROCm is installed via Python packages inside a virtual environment (not via a system /opt/rocm install), aiming to remove the need to manually set ROCM_PATH/PATH.

Changes:

  • Enhance _find_rocm_home() to prefer the rocm-sdk-devel pip layout (site-packages/_rocm_sdk_devel) when present.
  • Update JIT-side hipcc invocations to resolve hipcc via executable_path("hipcc") instead of relying on PATH.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
aiter/jit/utils/cpp_extension.py Adds _rocm_sdk_devel-based ROCm root detection ahead of hipcc-on-PATH heuristics.
aiter/jit/core.py Switches hipcc subprocess calls to use executable_path() and adds quoting for the shell pipeline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aiter/jit/utils/cpp_extension.py Resolved
Comment thread aiter/jit/core.py Resolved
Before this change, `check_LLVM_MAIN_REVISION` invoked a shell pipeline
with a bare `hipcc`; when the binary was missing, the shell exited 127
and `subprocess.CalledProcessError` was caught, returning the older
LLVM revision (554785). The previous commit moved `hipcc` resolution
to `executable_path("hipcc")`, but called it while building `cmd`
outside the `try` — so a missing `hipcc` now raises `AssertionError`
ahead of `subprocess` and the fallback never fires.

Move the resolution inside the `try` and also catch `AssertionError`
from `executable_path` so the original fallback semantics are kept.

Raised by Copilot review on PR #3264.
@valarLip
valarLip merged commit 0df57d0 into main Jun 15, 2026
30 checks passed
@valarLip
valarLip deleted the matthias.find-rocm-sdk-devel branch June 15, 2026 14:54
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.

3 participants