Fix bytes_per_key truncation in random kernels (Metal + CUDA)#3432
Merged
angeloskath merged 1 commit intoApr 21, 2026
Merged
Conversation
C++ passes bytes_per_key as size_t (8 bytes) but the kernels declared it as uint/uint32_t, truncating values above UINT32_MAX. Promote the kernel parameter to ulong/uint64_t so the full 64-bit value is read.
zcbenz
approved these changes
Apr 20, 2026
zcbenz
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for noticing this!
1 task
ekryski
added a commit
to ekryski/mlx
that referenced
this pull request
May 6, 2026
…dLocalStream, linalg.det) Highlights: - ThreadLocalStream in C++ (ml-explore#3405) — joins StreamOrDevice variant - Segmented mm NAX kernel (ml-explore#3419) — new steel/gemm/kernels/steel_gemm_segmented{,_nax} - mlx.core.linalg additions: determinant, sign-log-determinant (ml-explore#3416) - NAX split-K tuning + addmm fix (ml-explore#3422) - gather_mm CUDA + qmm CUDA fixes (ml-explore#3414, ml-explore#3417, ml-explore#3445) - Scheduler::enqueue thread safety (ml-explore#3423) - Random kernel bytes_per_key truncation fix (ml-explore#3432) - Many smaller bug + CI fixes; nanobind 2.12.0 pin Conflict resolution (5 files; all auto-merged cleanly, no manual edits): - mlx/utils.h — `ThreadLocalStream` joins StreamOrDevice; our metal_retain_bound_buffers() helper preserved. - mlx/backend/metal/device.cpp — upstream's "no Metal device available" error message coexists with our signpost/MLX_METAL_PROFILE perf diagnostic + hazard-mode retain logic. - mlx/backend/metal/CMakeLists.txt — upstream's steel_gemm_segmented{,_nax} joins our kernel registrations. - mlx/backend/metal/kernels/CMakeLists.txt — same: upstream segmented + our fused_gate_activation kernel. - tests/scheduler_tests.cpp — upstream's "test thread local stream" joins our scheduler-test alignment for lazy command-encoder init. No disputed conflicts; the auto-merge produced a coherent result with both sides' work intact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
C++ passes bytes_per_key as size_t (8 bytes) but the kernels declared it as uint/uint32_t, truncating values above UINT32_MAX. Promote the kernel parameter to ulong/uint64_t so the full 64-bit value is read.
no measurable performance impact.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes