Repository navigation
test(cuda): run the CUDA cache-default check in its own process - #2988
Merged
inureyes merged 1 commit intoNov 15, 2026
Merged
Conversation
`native_env_tests::the_cuda_cache_defaults_reach_mlx` is the one test that fails in `make verify-test-cuda` on a host with a CUDA device: `MLX_CUDA_GRAPH_CACHE_SIZE` reads 400 where the test expects the 2000 that `apply_cuda_graph_cache_default` has just set. The read is memoized. lablup#2876 moved the MLX pin to 9f806b36, where a setting is read through `mlx::core::config::get`, which stores the first value it returns for a name and answers from that store from then on. The CUDA device makes that first read with its own default of 400 when a command encoder is constructed. The gate runs the lib suite single threaded in name order, so `ffi_tests::*` have built the device long before `native_env_tests::*` run. Alone, the test passes. The check moves to `tests/cuda_cache_defaults_env.rs`, a test binary of its own in which nothing has touched MLX before the appliers run. That is the order production has: the appliers run once, at the top of `main`, before any MLX op. It also asserts the value in the C runtime, so a failure tells a missing write from a setting MLX had already resolved.
Member
|
Implementation hardening for #2988. Reviewed #2987: the native environment read now happens in a dedicated integration-test process, removing the memoized read/order race without changing production defaults. No additional security or performance defect was found. Validation: the_cuda_cache_defaults_reach_mlx passed in its own process during the combined full CUDA run. Commands: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
native_env_tests::the_cuda_cache_defaults_reach_mlxis the one test that fails inmake verify-test-cudaon a host with a CUDA device. It reads a setting that MLX has memoized since the pin moved to9f806b36(#2876), and in the gate's order the CUDA device has resolved that setting first. This moves the check into a test binary of its own, where nothing has touched MLX before the appliers run. With it the gate passes every test binary.Related issues
Closes #2987.
Type of change
test— tests onlyCause
The test removes
MLX_CUDA_GRAPH_CACHE_SIZE, callsapply_cuda_graph_cache_default()and reads the setting back throughmlx_env_int. Since #2876 that read ismlx::core::config::get, which stores the first value it returns for a name, the caller's default included, and answers from the store from then on (mlx/config.cppat9f806b36). The CUDA backend makes that first read itself, with its own default of 400, when a command encoder is constructed (graph_cache_in thedevice.cppoverlay). The gate runs themlxcel-corelib suite single threaded in name order, soffi_tests::*have built the device long beforenative_env_tests::*run.Before #2876 the same read was
mlx::core::env::get_var, a plaingetenvon every call. Measured on this host, themlxcel-corelib suite with--features cuda -- --test-threads=1:912858435, the parent of #28767ca40033f45a92cc9, #28769f806b36ce6855bc8,main9f806b369f806b36Production is not affected: the binaries call the appliers once at the top of
main, before any MLX op.Change
tests/cuda_cache_defaults_env.rs: the same check, both names through the real appliers and read back throughmlx_env_int, as the only test of its binary. It asserts the value in the C runtime first (native_getenv), so a failure tells an applier that did not write from a setting MLX had already resolved.src/lib/mlxcel-core/src/native_env_tests.rs: the test is removed, with a comment where it was that says why it cannot live there. The other tests in that file useNATIVE_ENV_TEST_*names that nothing else reads, so they are not exposed.Test plan
Run on this PR's commit (
62b6010c7, one commit once6855bc8) on a DGX Spark (GB10).cargo fmt --all -- --checkcargo clippy --workspace --all-targets --features cuda -- -D warnings(the Linux spelling of the template's line)make verify-test-cuda(cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1): all 188 test binaries pass, 15487 tests passed, 0 failed, 496 ignored. Onmainit is 186 of 187 with this test as the one failurecargo test --profile test-fast --features cuda -p mlxcel-core --lib --no-fail-fast -- --test-threads=1: 2260 passed, 0 failed (main: 2260 passed, 1 failed)cargo test --profile test-fast --features cuda --test cuda_cache_defaults_env: 1 passed, also on a second run in a rowMLX_CUDA_GRAPH_CACHE_SIZE as MLX reads it,left: 400,right: 2000. With the write removed fromapply_cuda_graph_cache_default:MLX_CUDA_GRAPH_CACHE_SIZE in the C runtime,left: Noneci.ymljobs a pull request from a fork does not get, run by hand:clippy(cargo clippy -p mlxcel --lib --tests -- -D warnings, default features),cpu-link(both commands; itsnative_envfilter still runs 13 tests, since the moved one was CUDA only),xla-compile(cargo check --features cuda,xla-iree --all-targets,cargo check --no-default-features --features xla-diagnostics --all-targets): all passscripts/ci/check_env_var_docs.py,scripts/ci/check_native_env_writes.py,scripts/insert_apache_header.py --check,scripts/ci/check_cross_repo_refs.py, andpython3 -m unittest discover -s tests -p 'test_*.py'(219 tests): all OKcargo build --releasecompiles neither filecargo deny check: not run and not applicable (no manifest, lockfile ordeny.tomlchange)Notes for reviewers
native_getenv(name) == "2000"in place would be independent of the order too, but it would no longer show that the value reaches MLX, which is what fix(windows): environment set from Rust does not reach MLX's getenv #2803 was about.tests/rocm_fft_cache_env.rsandtests/cpu_device_custom_kernel_gates.rsare the precedents for giving a process-global read a process of its own.MLX_CUDA_SDPA_CACHE_SIZEhas the same exposure and was never reached. The old loop asserted the graph cache first and stopped there. Its cache is built at the first cuDNN attention call. The new test checks both names, in a process where neither has been read.mlxcel_core::native_envfunctions as before. On a build without thecudafeature the file is an empty test binary (#![cfg(feature = "cuda")]).Checklist
docs/: no user-facing behavior or supported-model change// Used by: ...comments: no shared function is modified.envfiles committed