Skip to content

feat: self-contained Windows ROCm runtime and server validation #2602

Closed

Description

@inureyes

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 Windows link_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.rs add DELAYLOAD_DLL_PREFIXES (amdhip64_, rocblas, libhipblaslt, hipfft, hiprtc) and select_delayload_dlls(file_names) -> Vec<String> with the exact semantics of windows_cuda::select_delayload_dlls (windows_cuda.rs:117): case-insensitive, .dll only, 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 from dumpbin /dependents target\release\mlxcel.exe after 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 like windows_cuda::emit_delayload_link_args (windows_cuda.rs:197-212): list layout.bin_dir, emit /DELAYLOAD:<dll> for each selected name, link delayimp.lib, and /INCLUDE:__pfnDliNotifyHook2. Call it from link_rocm() in mlxcel-core/build.rs and from the root build.rs next to the CUDA call (build.rs:50-58), because a dependency's rustc-link-arg does not reach the final binaries.
  • Notify hook: a ROCm overlay delayload.cpp (Windows only, added to target_sources(mlx ...) under if(WIN32)), modeled on overlays/cuda/mlx/backend/cuda/delayload.cpp: on dliNotePreLoadLibrary load the DLL with LoadLibraryExW(<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 call AddDllDirectory(<bin>) once so rocBLAS finds its Tensile library directory beside rocblas.dll. <bin> is a compile definition MLXCEL_ROCM_BIN_DIR set from the CMake ROCM_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_dlls picks exactly the five imported names from a listing that also holds hiprand.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 bin absent from PATH, mlxcel generate starts and runs on the GPU; dumpbin /imports shows the five DLLs in the delay-load section.

2. Build-time include-dir fallback for hiprtc

  • In src/lib/mlxcelverse/CMakeLists.txt, beside MLXCEL_CUDA_INCLUDE_DIR (:320-336), under if(WIN32 AND MLX_BUILD_ROCM) define MLXCEL_ROCM_INCLUDE_DIR="<ROCM_PATH>/include" (via file(TO_CMAKE_PATH), only when hip/hip_runtime.h exists there).
  • jit_module.cpp rocm_home()/include resolution order becomes: ROCM_HOME, ROCM_PATH, HIP_PATH (from feat: build and run mlxcel natively on Windows with ROCm (gfx1151) #2601), then MLXCEL_ROCM_INCLUDE_DIR if 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 hipMalloc can exceed hipMemGetInfo total on Windows. If it cannot, under _WIN32 the integrated limit is total * 0.8 with no sys_ram term; record the probe result in LOCAL_FIXES.md.
  • Rust: add a Windows step-4 probe (GlobalMemoryStatusEx ullAvailPhys through a minimal extern "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 returning None still yields 0.
  • Acceptance: mlxcel generate --estimate-memory on 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 plain cmd.exe as 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.exe with neither the ROCm bin directory on PATH nor ROCM_PATH/HIP_PATH set, mlxcel generate and mlxcel-server run 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-pin and the memory_estimate tests.
  • 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 by jit_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

  1. added
    status:blocked
    type:enhancement
    priority:medium
    platform:windows
    area:core
    on Oct 25, 2026
  2. added
    status:ready
    status:in-progress
    status:review
    and removed
    status:blocked
    status:ready
    status:in-progress
    on Oct 25, 2026
  3. added
    status:done
    and removed
    status:review
    on Oct 25, 2026
  4. added a commit that references this issue on Oct 26, 2026
    01047d7
  5. added this to the 0.8 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreplatform:windowspriority:mediumstatus:donetype:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions