Skip to content

[JIT] Diagnose missing rocPRIM headers for the selected ROCm toolchain - #5166

Merged
amd-ruitang3 merged 23 commits into
ROCm:mainfrom
Qubitium:fix/rocm-devel-header-discovery
Oct 13, 2026
Merged

amd-ruitang3 merged 23 commits into
ROCm:mainfrom
Qubitium:fix/rocm-devel-header-discovery

Conversation

@Qubitium

@Qubitium Qubitium commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When the selected ROCm compiler cannot resolve rocprim/rocprim.hpp, AITER's JIT build fails without identifying its toolchain or the matching development packages. Coexisting Python SDK and system installations require guidance tied to the selected compiler.

Changes

  • Append installation guidance only after an actual missing-rocPRIM compiler error. Report ROCM_HOME and the selected hipcc, using the same compiler selection as Ninja.
  • Identify SDK compilers through installed wheel records or the SDK tree. Suggest rocm[devel] pinned to the full installed version, including nightly/local suffixes, and initialization/root-selection commands using the current Python interpreter. Users supply the original package index because pip does not retain its URL.
  • For system compilers, read their own .info/version or .info/version-dev and identify development packages to obtain from that release/build repository. Report unknown versions explicitly. Link to official prebuilt-installation and release-artifact documentation.
  • Capture logs in a temporary file. Successful verbose builds forward bounded chunks without retaining the complete log in Python memory; partial writes are retried. Read the full log only on failure, retain the original compiler error and chained exception, tolerate non-UTF-8 output, and kill the child on interruption.
  • Treat metadata inspection as best-effort: malformed SDK records and unexpected diagnostic failures cannot replace the original compiler error.
  • Cover diagnostics, package ownership/version selection, actual Ninja/C++ include resolution, real file-descriptor output including partial writes, memory growth, cancellation, and empty/invalid-byte output. Write malformed fixtures as bytes to avoid locale-dependent failures.

Builds continue to use compiler-configured include paths such as CPATH, CPLUS_INCLUDE_PATH, -I, and -isystem. No automatic cross-install header fallback or header-presence preflight is introduced. This follows the maintainer review.

Validation

  • Python 3.14: python -m pytest -q op_tests/test_cpp_extension_rocm_headers.py op_tests/test_jit_cache_transaction.py — 73 passed, 71 subtests passed.
  • Python 3.10: header suite — 20 passed, 46 subtests passed, both normally and with LC_ALL=C PYTHONCOERCECLOCALE=0 PYTHONUTF8=0.
  • Branch coverage of the five affected functions (_get_hipcc_path, _rocm_sdk_for_compiler, _rocm_devel_install_hint, _rocm_header_build_hint, _run_ninja_build): 74/74 executable statements and 28/28 branches. This is scoped coverage, not repository-wide or platform coverage.
  • Successful 16 MiB verbose-log regression stays below 2 MiB of traced Python allocations during forwarding/capture.
  • Original malformed-record and partial-write review reproducers now pass.
  • Black, Ruff, and git diff --check pass.

Validation ran on Linux CPU. Include-resolution tests use real Ninja and a host C++ compiler with a small stand-in header. Native Windows, HIP kernel compilation, and GPU execution were not performed.

@Qubitium
Qubitium requested a review from a team September 1, 2026 04:00
@github-actions

github-actions Bot commented Sep 1, 2026

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:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
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 5166 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@github-actions github-actions Bot added the JIT label Sep 1, 2026
@zufayu
zufayu requested a review from valarLip September 2, 2026 01:22
@Qubitium

Qubitium commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@valarLip Ran into this bug a second time today. The core issue is hipcc from python pkg (not the hipcc installed by apt) only looks in the python venv local for rocm dev libs but there is no official amd repo or package that actually installs rocm dev libs to the pyhton local dev, they are always installed to /opt/rocm path. This is very strange to me.

hipcc may come from the Python ROCm SDK

image

Query the build compiler instead of trusting a possibly unrelated global
HIP version. Reject failed probes and unreadable headers, remove the
redundant path check, and cover fallback behavior without GPU imports.

Signed-off-by: Codex <[email protected]>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 7, 2026
@zufayu
zufayu requested review from amd-ruitang3 and removed request for valarLip October 10, 2026 03:01
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Oct 11, 2026
@Qubitium

Copy link
Copy Markdown
Contributor Author

not stale

ruff 0.16.0 I001 flagged tests/test_cpp_extension_rocm_headers.py: move
`from contextlib import ExitStack` into the sorted `from`-import block
after the plain stdlib imports.
@amd-ruitang3

Copy link
Copy Markdown
Contributor

@Qubitium thanks your PR to make aiter robust. Pls move [test_cpp_extension_rocm_headers.py] to op_tests directory; otherwise CI won't run it.

@amd-ruitang3

Copy link
Copy Markdown
Contributor

Secondly, please use functools.lru_cache when invoking hipcc --version to avoid repeated calls under the same environment.

Review feedback from @amd-ruitang3 on ROCm#5166:

- Move the header-discovery test to op_tests/. CI only shards and runs
  op_tests/test_*.py (see .github/scripts/split_tests.sh and
  .github/scripts/aiter_test.sh), so the test under tests/ never executed.
  The repo-root lookup in the test is unchanged because both directories sit
  one level below the checkout root.
- Cache the `hipcc --version` probe. include_paths() runs several times per
  build, so the probe spawned a compiler each time just to read its version.
  The new _probe_hipcc_version() is memoized per hipcc path, which is what
  changes when ROCM_HOME selects a different ROCm tree; functools.cache is the
  unbounded form of functools.lru_cache and is what the pinned ruff (UP033)
  requires.

Tests: two new cases cover the caching contract (repeated discovery probes
once; a different hipcc path is probed again), and the existing cases clear
the cache so each still observes its own mocked compiler output.
@Qubitium

Qubitium commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@amd-ruitang3 Please re-review.

1. Test moved to op_tests/ — op_tests/test_cpp_extension_rocm_headers.py. Verified it is now picked up by the shard splitter (find op_tests -maxdepth 1 -name 'test_*.py') and that it runs standalone the way aiter_test.sh invokes it: python3 op_tests/test_cpp_extension_rocm_headers.py → 10 tests pass. The repo-root lookup inside the test is unchanged since both directories sit one level below the checkout root.

2. hipcc --version is now cached — extracted into _probe_hipcc_version(), memoized per hipcc path, so the several include_paths() calls per build probe the compiler once. Two notes on the exact spelling:

  • functools.cache is the unbounded form of functools.lru_cache, and it is what the pinned ruff (UP033) enforces — lru_cache(maxsize=None) fails ruff check ..
  • The cache key is the hipcc path, which is precisely what changes when ROCM_HOME selects a different ROCm tree, so a mixed install still probes its own compiler.

Two new tests pin that contract: repeated discovery probes once, and a different ROCM_HOME probes its own hipcc. The existing cases clear the cache in setUp so each still observes its own mocked compiler output.

Local: ruff check . (0.16.0) clean, black --check clean, python -m unittest and pytest on the moved test both green (10 tests, 14 subtests).

Explain the static /opt/rocm/include fallback: hipcc from the Python ROCm SDK
searches only its own venv-local include tree, while the rocPRIM dev headers
are installed by the system packages under /opt/rocm. Kernels that include
rocprim/rocprim.hpp (directly or through hipcub) otherwise fail with
"'rocprim/rocprim.hpp' file not found". Also note the two guards that keep the
fallback narrow: it applies only when the resolved include paths lack rocPRIM
and the system headers' HIP version matches the selected hipcc.

Comment-only change; no behavior change.
@amd-ruitang3

Copy link
Copy Markdown
Contributor

Hi @Qubitium , based on my understand, your PR will fetch the head files from /opt/rocm when the python env don't have them. And check version match. Could you add a warning to prompt users to install the corresponding components when there is a version mismatch?

@Qubitium

Qubitium commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Side note, AMD needs to publish real pkgs, not empty placeholders which makes this issue less of a problem. Right now, you need to specify a wheel repo url from amd in the pip command to find the "real" pkg. Very strange.

image

@Qubitium

Qubitium commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @Qubitium , based on my understand, your PR will fetch the head files from /opt/rocm when the python env don't have them. And check version match. Could you add a warning to prompt users to install the corresponding components when there is a version mismatch?

Also, if you check my pr descrption, there is no pip pkg from amd that actually install those headers in pyenv. I did not find one. So apt is likely the only option.
Please check on your end.

I think that’s enough. We can fetch from /opt/rocm and output a prompt message.

Done. The prompt message should now output correct install pip commands as single warn level log.

@amd-ruitang3

Copy link
Copy Markdown
Contributor

@Qubitium Which ROCm version are you using? ROCm 10 or ROCm 7?

@Qubitium

Qubitium commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@Qubitium Which ROCm version are you using? ROCm 10 or ROCm 7?

Latest 10.x that was available in early Sept.

@Qubitium

Copy link
Copy Markdown
Contributor Author

@amd-ruitang3 I do not currently have access to a MI350/MI300X system right now to test. Please trigger CI and test on your end. This PR was first crated in early Sep when I had rented the single gpu vms.

@amd-ruitang3

Copy link
Copy Markdown
Contributor

yes @Qubitium . Meanwhile, I’m reaching out to the ROCm installation team. The root cause might be that rocm-sdk-devel cannot be installed via pip, which is why you need to fetch headers from /opt/rocm. We should try to address this problem at the root cause.

@Qubitium

Copy link
Copy Markdown
Contributor Author

yes @Qubitium . Meanwhile, I’m reaching out to the ROCm installation team. The root cause might be that rocm-sdk-devel cannot be installed via pip, which is why you need to fetch headers from /opt/rocm. We should try to address this problem at the root cause.

Correct. Both this and root issue botth needs to be fixed. But even if source is fixed, we still need to support apt packages co-existing with pyenv packages. Right now, the code expect perfect pyenv which is often not the case. I installed my env from scratch, not using docker image, using official Ubuntu and install yet I encountered these problems. All future lib/header search should default to pyenv local and if not found, go one env higher and check the system apt installed paths which is /opt/rocm.

@amd-ruitang3

Copy link
Copy Markdown
Contributor

Starting from ROCm 10, AMD intends ROCm to be installed via pyenv instead of apt.
We should be able to install ROCm properly.

Hi @mgehre-amd @iassiour @zufayu ,
@Qubitium installed ROCm from scratch, rocm-sdk-devel is missing within the pyenv. Could you help take a look?

Comment thread aiter/jit/utils/cpp_extension.py Resolved
@mgehre-amd

Copy link
Copy Markdown
Contributor

I don't think we should mix ROCm from different sources. Instead of doing this, could we just error out and tell people to install the rocm correctly (as described on https://rocm.docs.amd.com/en/latest/install/rocm.html?fam=ryzen&w=compute&gpu=amd-ryzen-ai-max-pro-495&os=ubuntu&ubuntu-ver=26.04.1&i=pip&gfx=gfx1151, including rocm-sdk init)?

@Qubitium

Copy link
Copy Markdown
Contributor Author

I don't think we should mix ROCm from different sources. Instead of doing this, could we just error out and tell people to install the rocm correctly (as described on https://rocm.docs.amd.com/en/latest/install/rocm.html?fam=ryzen&w=compute&gpu=amd-ryzen-ai-max-pro-495&os=ubuntu&ubuntu-ver=26.04.1&i=pip&gfx=gfx1151, including rocm-sdk init)?

Even if both sources are from AMD directly? Both the apt and pip must make use of amd supplied repo paths. Once the software is in user land, we need to be compatbile, to a certain extend. How the user want to use the sdk and how devs want the user to use the sdk might needs re-eval.

@amd-ruitang3

Copy link
Copy Markdown
Contributor

@Qubitium, do you exec rocm-sdk init during installation? I checked rocm_10.0.0rc4 which include rocm-sdk-devel. But rocm-sdk-devel just a tar wheel in rocm. Need run rocm-sdk init to unpack. I am testing in our MI35X machine.

@amd-ruitang3

amd-ruitang3 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

result:
image

So the issue can be addressed by running rocm-sdk init during installation.

@Qubitium

Qubitium commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

result: image

So the issue can be addressed by running rocm-sdk init during installation.

@amd-ruitang3 Thank you for finding the disconnect!

The install I used is apt: https://rocm.docs.amd.com/en/docs-10.0.0/install/rocm.html?fam=instinct&w=compute&gpu=amd-instinct-mi300x&os=ubuntu&ubuntu-ver=26.04&i=pkgman&gfx=gfx942

It is a valid path for rocm 10.x install and you are correct that I did not run rocm-sdk init. I didn't think I need to, per apt doc. There are pypi specific (requires init) doc and apt which does not requires this step.

The situation is pretty clear now but still unresolved.

A) This PR: allow shared system (compatible) rocm paths to pyenv. Deduplication if you have many pyenvs.

B) Make sure pyenv has complete copy of isolated rocm libs and make user aware of this.

I personally prefer option A but it's up to AMD now.

Also, is there a technical reason why the archive is not decompressed on pip setup.py? That would be even better solution?

zufayu
zufayu previously requested changes Oct 13, 2026

@zufayu zufayu 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.

Thanks for the detailed investigation and for clarifying that the reported environment was set up using the official apt-based ROCm installation instructions. The missing-header failure is real, and this PR has exposed a genuine gap in how AITER selects and diagnoses ROCm development files. The regression coverage added here is also valuable.

As the AITER maintainer, I want to clarify the support boundary. A JIT build should use a documented, coherent ROCm toolchain composition whose compiler, ROCm headers, and runtime libraries are known to be compatible. AITER should not independently create a new composition by combining a Python SDK hipcc with the full header tree discovered under /opt/rocm.

The HIP major/minor check is a useful safeguard, but we do not have an upstream compatibility contract stating that a matching HIP major/minor is sufficient for rocPRIM, hipCUB, rocThrust, HIP headers, and runtime components drawn from separate installations. AITER is therefore not in a position to certify or maintain that cross-install combination.

To be clear, this does not make the apt installation path invalid. A system installation should be usable as a coherent system toolchain, and a Python SDK installation should likewise be usable as a coherent SDK toolchain. If the coexistence of multiple installations causes AITER to select an unintended toolchain, we should make that selection explicit or improve the discovery logic to select one complete, supported toolchain composition—not merge components from both.

Could you please rework this PR along the following lines?

  • Remove the automatic /opt/rocm/include fallback.
  • Improve the failure path so that, when the selected compiler cannot resolve rocprim/rocprim.hpp, the diagnostic reports the selected ROCM_HOME, the hipcc path, and the missing header, and directs the user to the appropriate official installation or initialization guidance.
  • Do not reject an otherwise valid environment solely because the header is absent directly under ROCM_HOME; standard compiler mechanisms such as CPATH, CPLUS_INCLUDE_PATH, or explicit build flags may already make it resolvable.
  • Retain regression coverage for the diagnostic behavior and for valid explicitly configured include paths.

The request to share system development headers across Python environments is reasonable. However, if such a composition is intended to be officially supported, its compatibility and discovery contract should be defined by the ROCm SDK/installation layer through a supported sysroot, initialization process, or configuration mechanism. AITER can then consume that contract without independently maintaining cross-install compatibility rules.

The use case remains valid; this decision defines which layer should own and guarantee the compatibility of the resulting ROCm toolchain. Thank you again for identifying the gap and for the substantial work put into investigating and validating it. I would be glad to review a revision along the direction above.

@Qubitium

Qubitium commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Could you please rework this PR along the following lines?

  • Remove the automatic /opt/rocm/include fallback.
  • Improve the failure path so that, when the selected compiler cannot resolve rocprim/rocprim.hpp, the diagnostic reports the selected ROCM_HOME, the hipcc path, and the missing header, and directs the user to the appropriate official installation or initialization guidance.
  • Do not reject an otherwise valid environment solely because the header is absent directly under ROCM_HOME; standard compiler mechanisms such as CPATH, CPLUS_INCLUDE_PATH, or explicit build flags may already make it resolvable.
  • Retain regression coverage for the diagnostic behavior and for valid explicitly configured include paths.

@zufayu Will do! AMD just gave me some dev cloud credits so I am able to test the PRs again locally on a real vm (single MI300X).

@Qubitium Qubitium changed the title [JIT] Discover matching system ROCm headers for Python SDK compilers [JIT] Diagnose missing rocPRIM headers for the selected ROCm toolchain Oct 13, 2026
@Qubitium
Qubitium requested a review from zufayu October 13, 2026 08:27
@zufayu
zufayu dismissed their stale review October 13, 2026 09:46

The requested changes have been addressed in the current revision.

@zufayu zufayu 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.

The requested changes have been addressed. Thanks.

@amd-ruitang3

Copy link
Copy Markdown
Contributor

The requested changes have been addressed. Thanks.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants