Repository navigation
feat(rocm): prefer bundle headers over HIP_PATH, log compiled targets - #2648
Conversation
The AMD HIP SDK installer sets HIP_PATH machine-wide, and HIP_PATH outranked a Windows ROCm runtime bundle's include, so on any machine with a HIP SDK a ROCm 10.1 bundle JIT-compiled kernels against another release's headers. choose_rocm_include_dir() now takes runtime_is_bundle and orders ROCM_HOME, ROCM_PATH, the bundle include (runtime dir source Env or ExeDir, holding hip/hip_runtime.h), HIP_PATH, the runtime include of a Baked source, then the baked include. delayload.cpp exposes rocm_runtime_dir_source(), and the pure rocm_include_dir_notice() in runtime_dir.h prints one line naming both directories when an environment variable and a bundle disagree. Linux passes no bundle and no HIP_PATH, so its -I string is unchanged. The overlay CMake defines MLXCEL_ROCM_ARCHITECTURES from CMAKE_HIP_ARCHITECTURES and device.cpp prints it once after the bound-device line. The bundle script fails with every --arch that lacks .kpack archives or rocBLAS/hipBLASLt entries named, instead of writing a partial bundle. Docs describe the new order, the distributable target list and where its kernel data comes from (the TheRock multiarch tarball). Validated: host include-order test (fails on main), packaging tests, bundle generate and server on gfx1151, a decoy HIP_PATH ignored with the notice, ROCM_PATH still winning. The seven-target build compiled every HIP kernel but did not link on the 32 GB host. Closes #2639
The GPU targets section still said the seven-target link had not completed. It has: rerun with -j 2 after the HIP objects were compiled, the link of mlxcel and mlxcel-server took 7 min 1 s, and the binaries run on gfx1151 and print the compiled target list. The section now gives the binary sizes for seven targets against gfx1151 alone next to the kernel archive and HIP step figures, and tells a ~32 GB host to link at -j 2, since -j 8 failed with link.exe 0xC0000142. Refs #2639
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
|
CMAKE_HIP_ARCHITECTURES comes from the MLX_ROCM_ARCHITECTURES environment variable verbatim and now also lands in the MLXCEL_ROCM_ARCHITECTURES C string literal printed by device.cpp, so a value with a quote could end the literal and splice code into the build. The backend CMakeLists.txt now fails the configure step on any entry that is not a HIP target ID (gfx1151, gfx11-generic and gfx90a:xnack+ pass; quotes, spaces and upper case do not). Every documented form is a semicolon list of plain targets, so no existing build changes. Checked the pattern with cmake -P against valid and invalid entries, overlay drift and records pass, and the gfx1151 build was rebuilt with the change. Refs #2639
|
Security and performance review of the header precedence, notice line, runtime_dir.h helpers, compiled-target log and packaging check. Fixed in d6348c9 (LOW, build-time hardening): No CRITICAL, HIGH or MEDIUM findings. Notes, not changed:
Verification: |
… IDs Add tests/test_rocm_arch_validation.py, which extracts the validation loop from the ROCm overlay CMakeLists.txt and runs it with cmake -P: gfx IDs, feature suffixes and generic targets pass, while native, uppercase, option strings and quote injection fail with "Not a HIP target ID". It skips when cmake is absent. Document the accepted target-ID forms where MLX_ROCM_ARCHITECTURES is described in docs/installation.md (both ROCm sections) and docs/environment-variables.md. Validation: - python3 -m unittest tests/test_rocm_arch_validation.py tests/test_package_windows_rocm_runtime.py: 24 tests OK - cargo fmt --all --check, check_env_var_docs.py, overlay drift and records: OK Refs #2639
Summary
ROCM_HOME,ROCM_PATH, bundle include (runtime dir sourceEnvorExeDirwithhip\hip_runtime.h),HIP_PATH, runtime include for aBakedsource, baked include. A HIP SDK's machine-wideHIP_PATHno longer overrides a bundle. When a variable and a bundle disagree, one line names both:[mlx-rocm] hiprtc headers: <chosen> (<source>); ignoring <other> from <source>. Linux passes no bundle and noHIP_PATH, so its-Istring is unchanged.choose_rocm_include_dir()stays pure and awk-extractable;rocm_runtime_dir_source()(delayload.cpp) and the purerocm_include_dir_notice()live beside it in runtime_dir.h.MLXCEL_ROCM_ARCHITECTUREScomes fromCMAKE_HIP_ARCHITECTURESin the overlay CMake (no build.rs change: build.rs already passes the resolved list as that variable). device.cpp prints[mlx-rocm] compiled HIP targets: ...once after the bound-device line.MLX_ROCM_ARCHITECTURESentry that is not a HIP target ID (gfx1151,gfx11-generic,gfx90a:xnack+forms) withNot a HIP target ID, because the list is now also compiled into a C string literal (security review, LOW).--archwithout.kpackarchives or rocBLAS/hipBLASLt entries.HIP_PATHcaveat, distributable listgfx1100;gfx1101;gfx1102;gfx1150;gfx1151;gfx1200;gfx1201, LOCAL_FIXES item 66.Target facts (ROCm 10.1.0)
gfx1151tarball has kernel data and.kpackforgfx1151only; itshipccand device libs compile all seven targets.therock-dist-windows-multiarch-10.1.0.tar.gz(4.9 GB) covers all seven inbin\rocblas\library,bin\hipblaslt\libraryand.kpack(checked by streamingtar -t, nothing extracted). The per-family tarballs cover only their own family.mlx_rocm_kernels.lib: 716.6 MiB (7 targets) vs 190.1 MiB (gfx1151). HIP kernel step, CMake configure to archive,-j 8: 5 min 8 s (cold tree) vs 3 min 6 s (fresh mlxcel-core build dir in the warm tree). Every HIP object holds all seven code objects.CARGO_TARGET_DIR=C:\t\rw7): the-j 8build compiled every HIP object, then the link failed withlink.exe0xC0000142 under memory pressure on the 32 GB host. Rerunningcargo build -j 2 --bin mlxcel --bin mlxcel-serverlinked both in 7 min 01 s.mlxcel.exe745,592,320 bytes vs 193,465,856 (gfx1151 alone);mlxcel-server.exe735,546,880 vs 183,420,416. On gfx1151 it prints[mlx-rocm] compiled HIP targets: gfx1100,gfx1101,gfx1102,gfx1150,gfx1151,gfx1200,gfx1201and generated "Paris" at 75 tok/s. The docs tell a ~32 GB host to link at-j 2. Non-gfx1151 targets are build-verified only (compile, no hardware).Test plan
rocm_runtime_dir_test.shpasses; the new test fails on main (compile error, and 2 checks fail when main's order gets the new signature)--arch gfx1151 --arch gfx1100 --arch gfx1201exits 1 naming both, writes nothingHIP_PATHset to a decoy whosehip_runtime.his#error: bundle JIT compiles 3 kernels and prints the line; the build-tree binary (Baked) hits the decoy error, as intendedROCM_PATHat run time still wins and prints the linetests/test_rocm_arch_validation.pyruns the real CMake validation block withcmake -P: accepts the seven-target list and target-ID forms, rejects a quote-injection string,native,GFX1151,sm_80; gfx1151 rebuild after the check and a bundle generate ("Paris", 76.8 tok/s)cargo test -p mlxcel-mlx-pin --lib, fmtcargo clippy -p mlxcel-core --release --features rocm -j 8 -- -D warningsclean (4 min 26 s, warmC:\t\rw)Closes #2639