Repository navigation
Description
Problem
On Windows, std::env::set_var calls SetEnvironmentVariableW, while the C runtime's getenv reads its own copy of the environment. A probe measured getenv returning NULL after SetEnvironmentVariableW. MLX's env::get_var uses std::getenv (mlx/utils.cpp).
PR #2799 found this for MLX_PTX_CACHE_DIR and fixed that one variable by reading it with GetEnvironmentVariableW in the overlay.
Other startup writes from Rust that native code reads with getenv are therefore likely inert on Windows.
- Reader confirmed:
MLX_USE_CUDA_GRAPHS(src/loading/mod.rs:688, read in the CUDAdevice.cpp). - Readers not yet checked:
MLX_CUDA_GRAPH_CACHE_SIZEandMLX_CUDA_SDPA_CACHE_SIZE(src/lib/mlxcel-core/src/hardware.rs),MLX_ENABLE_TF32(src/lib.rs,src/lib/mlxcel-core/src/lib.rs),cuda_graph_budget.rs,autotune/ops/cuda_kernel_knobs.rs,MLX_MAX_OPS_PER_BUFFERinhardware.rs.
Possible failure, not reproduced: a long-lived Windows mlxcel-server keeps MLX's graph cache capacity of 400 instead of mlxcel's 2000 and reaches the fatal "Cache thrashing" abort from #818. The per-model graph capture disable and the autotuner's kernel knobs may also do nothing on Windows.
Work
Do all of this in one PR, with one verification pass at the end and as few pushes as possible.
- Audit every production write of an environment variable that native code reads, and list it in the PR.
- Add one helper in
mlxcel-corethat sets (and unsets) a variable for both Rust and the C runtime on Windows, and route those writes through it. No behavior change on other platforms. Failing test first: after the helper, a nativegetenvthrough the bridge sees the value. - Add a guard, so a new direct write of an
MLX_*variable read natively fails CI or a test. - Because this changes which settings take effect on Windows, measure serving on an RTX Spark N1X before and after, and record any change.
Acceptance Criteria
- The effective values are confirmed at run time on Windows for the audited variables, in
mlxcelandmlxcel-server. - Docs that describe these defaults stay true on Windows.
Activity
fix(windows): make environment set from Rust reach MLX's getenv (labl…
test(cuda): run the CUDA cache-default check in its own process (#2988)