Repository navigation
Description
Depends on #2601 (native Windows ROCm build). Start only after #2601 merges: it adds
build_support/windows_rocm.rs(RocmLayout { root, bin_dir, lib_dir, hipcc, amdgpu_arch },layout_from_env()), the Windowslink_rocm()branch, and the "Windows with AMD ROCm (experimental)" docs section this issue edits.
Problem / Background
After #2601, a Windows --features rocm binary only runs when the ROCm SDK bin directory (e.g. C:\rocm\10.1.0\bin) is on PATH and ROCM_PATH is set. Without PATH the process fails to start: the binaries import amdhip64_7.dll, rocblas.dll, libhipblaslt.dll, hipfft.dll, hiprtc0716.dll (versioned names; the linker drops hiprand). Without ROCM_PATH the first fused-kernel JIT fails with "Environment variable ROCM_HOME or ROCM_PATH is not set." because rocm_home() in overlays/rocm/mlx/backend/rocm/jit_module.cpp:115-126 supplies the hiprtc -I<rocm>/include (:334). #2599 solved the same two problems for CUDA; this issue mirrors that design. mlxcel-server on Windows ROCm has also not been exercised.
Proposed Solution
Do all five items in a single PR, run the local gate once at the end, and keep pushes to a minimum. Overlay changes get a overlays/rocm/LOCAL_FIXES.md entry naming the files. Linux behavior must not change.
1. Delay-load the ROCm DLLs from the build-time SDK bin
- In
build_support/windows_rocm.rsaddDELAYLOAD_DLL_PREFIXES(amdhip64_,rocblas,libhipblaslt,hipfft,hiprtc) andselect_delayload_dlls(file_names) -> Vec<String>with the exact semantics ofwindows_cuda::select_delayload_dlls(windows_cuda.rs:117): case-insensitive,.dllonly, sorted, deduped. Exclude names that match a prefix but are not imported (e.g.hiprtc-builtins*.dll) so link.exe does not warn LNK4199; decide the exclusion list fromdumpbin /dependents target\release\mlxcel.exeafter feat: build and run mlxcel natively on Windows with ROCm (gfx1151) #2601 and encode it in the function. emit_delayload_link_args(layout: &RocmLayout), shaped likewindows_cuda::emit_delayload_link_args(windows_cuda.rs:197-212): listlayout.bin_dir, emit/DELAYLOAD:<dll>for each selected name, linkdelayimp.lib, and/INCLUDE:__pfnDliNotifyHook2. Call it fromlink_rocm()inmlxcel-core/build.rsand from the rootbuild.rsnext to the CUDA call (build.rs:50-58), because a dependency'srustc-link-argdoes not reach the final binaries.- Notify hook: a ROCm overlay
delayload.cpp(Windows only, added totarget_sources(mlx ...)underif(WIN32)), modeled onoverlays/cuda/mlx/backend/cuda/delayload.cpp: ondliNotePreLoadLibraryload the DLL withLoadLibraryExW(<bin>\<name>, nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)so its own imports (e.g.rocm_kpack.dll) resolve beside it, and callAddDllDirectory(<bin>)once so rocBLAS finds its Tensile library directory besiderocblas.dll.<bin>is a compile definitionMLXCEL_ROCM_BIN_DIRset from the CMakeROCM_PATH(forward slashes, converted to wide at run time). Never resolve from CWD or PATH. If the DLL is missing there, return null so the loader raises its normal error naming the DLL. - Tests:
select_delayload_dllspicks exactly the five imported names from a listing that also holdshiprand.dll,rocm_kpack.dll,hiprtc-builtins0716.dll,HIPFFT.DLL(mixed case kept), and non-DLL files; returns them sorted and deduped. These fail today because the function does not exist. - Acceptance: with the SDK
binabsent from PATH,mlxcel generatestarts and runs on the GPU;dumpbin /importsshows the five DLLs in the delay-load section.
2. Build-time include-dir fallback for hiprtc
- In
src/lib/mlxcelverse/CMakeLists.txt, besideMLXCEL_CUDA_INCLUDE_DIR(:320-336), underif(WIN32 AND MLX_BUILD_ROCM)defineMLXCEL_ROCM_INCLUDE_DIR="<ROCM_PATH>/include"(viafile(TO_CMAKE_PATH), only whenhip/hip_runtime.hexists there). jit_module.cpprocm_home()/include resolution order becomes:ROCM_HOME,ROCM_PATH,HIP_PATH(from feat: build and run mlxcel natively on Windows with ROCm (gfx1151) #2601), thenMLXCEL_ROCM_INCLUDE_DIRif it exists on disk, else today's error. Keep the include-dir decision in a small pure function (inputs: the three env values and whether the baked dir exists) so the order is readable; the end-to-end check is the run below.- Acceptance: with no
ROCM_PATH/HIP_PATH/ROCM_HOME, the first hiprtc JIT compile succeeds.
3. Memory estimate and allocator limit on a Windows UMA APU
resolve_available_memory_from (src/execution/memory_estimate.rs:881-898) returns the MLX allocator limit when nonzero, so on ROCm the /proc/meminfo probe (Linux only, None on Windows, :858-866) is never reached. The allocator limit for integrated devices (allocator.cpp:328-334) is max(total * 0.8, sys_ram * 0.8), which assumes the Linux model where the APU pool draws from system RAM. On Windows WDDM the carve-out is the device pool (spike: hipMalloc reached 92 GiB of 107.87 GiB reported; host shadows from #2601 additionally consume OS RAM).
- Verify on the host whether
hipMalloccan exceedhipMemGetInfototal on Windows. If it cannot, under_WIN32the integrated limit istotal * 0.8with nosys_ramterm; record the probe result inLOCAL_FIXES.md. - Rust: add a Windows step-4 probe (
GlobalMemoryStatusExullAvailPhysthrough a minimalextern "system"declaration, no new crate) so CPU-only and unknown-backend Windows estimates are not 0. - Tests in
memory_estimate.rs's test module (next to the existing cases at:2920-2975): a nonzero allocator limit (86 GiB) wins over a smaller OS-RAM figure (31 GiB); with the allocator limit 0 the Windows probe value is used; a probe returningNonestill yields 0. - Acceptance:
mlxcel generate --estimate-memoryon the Windows host reports available memory matching the allocator limit, and a model that fits the carve-out is admitted.
4. Server validation
mlxcel-server --features rocm on Windows serves /v1/chat/completions (streaming and non-streaming) and /v1/messages correctly on the GPU. The Windows limits from #2599 (no distributed, no UDS listen, router-mode download refusals) apply unchanged. Fix any Windows ROCm-specific failure found; record the requests and responses in the PR.
- Acceptance: all three request kinds return correct greedy text for
mlx-community/Qwen3-0.6B-4bit, served from a plaincmd.exeas in item 1.
5. Docs
In docs/installation.md's "Windows with AMD ROCm (experimental)" section: remove the PATH/ROCM_PATH run-time limit, describe DLL resolution (delay-loaded from the SDK bin recorded at build time, never CWD or PATH), and state that running on another machine still needs the ROCm DLLs at that path or bundled (packaging out of scope, as for CUDA). Update docs/environment-variables.md to say ROCM_PATH/HIP_PATH are build-time only on Windows.
Out of scope
Packaging and DLL bundling, Windows CI, distributed inference on Windows.
Acceptance Criteria
- Items 1-5 each meet their own acceptance line above.
- From a plain
cmd.exewith neither the ROCmbindirectory on PATH norROCM_PATH/HIP_PATHset,mlxcel generateandmlxcel-serverrun on the GPU, including the first hiprtc JIT compile. - Unit tests for DLL selection and the memory-resolution order pass in
cargo test -p mlxcel-mlx-pinand thememory_estimatetests. - Linux ROCm build and run unchanged. (Changes are Windows-gated; not re-run, no Linux ROCm host or CI, see feat: run Windows ROCm builds without the SDK on PATH or ROCM_PATH #2604.)
- Integrated into the real build and run path (link args from both build scripts, hook compiled into
mlx, fallback used byjit_module.cpp), not standalone helpers.
Verification
No Windows CI runner exists; the Windows checks are manual and recorded in the PR.
cargo test -p mlxcel-mlx-pin
cargo test --lib execution::memory_estimate
make fmt-check
make clippy
python3 scripts/mlxcelverse/rocm_overlay.py drift
# Windows, VS x64 developer prompt (build):
set ROCM_PATH=C:\rocm\10.1.0
cargo build --release --features rocm
# Windows, new plain cmd.exe (run), ROCm bin not on PATH, no ROCM_PATH/HIP_PATH:
target\release\mlxcel generate -m mlx-community/Qwen3-0.6B-4bit -p "What is the capital of France?" -n 60 --temp 0
target\release\mlxcel-server -m mlx-community/Qwen3-0.6B-4bit
Activity
feat: build and run mlxcel natively on Windows with ROCm (#2603)
docs: require an admin-only ROCm SDK directory on Windows
fix(build): fail closed on a relative ROCm root or a missing HIP runt…
feat: run Windows ROCm builds without the SDK on PATH or ROCM_PATH (l…