Skip to content

Fixed misaligned stores in RandomBits on the CPU - #4886

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
ipazarbasi:random-bits-misaligned-store
Nov 20, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
ipazarbasi:random-bits-misaligned-store

Conversation

@ipazarbasi

Copy link
Copy Markdown
Contributor

Each key's output starts at a byte offset that need not be a multiple of
4. This patch stores the generated uint32_t with memcpy and adds a test.

Note: The new test only verifies the fix under UBSan with halting enabled. Without the patch, the test fails.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: AI not used

@zcbenz
zcbenz marked this pull request as ready for review November 20, 2026 04:11
Each key's output starts at a byte offset that need not be a multiple of
4. This patch stores the generated uint32_t with `memcpy` and adds a
test.
@zcbenz
zcbenz force-pushed the random-bits-misaligned-store branch from 4305996 to 057007b Compare November 20, 2026 04:27
@zcbenz
zcbenz merged commit 70d0d09 into ml-explore:main Nov 20, 2026
24 checks passed
rcfa pushed a commit to cubiculum-ai/mlx that referenced this pull request Nov 26, 2026
Ported: the fork already stores through a std::memcpy store lambda
(osaurus-ai/mlx PR 44), so mlx/backend/cpu/primitives.cpp keeps the
fork's code. Only Apple's test is taken, beside the fork's own.

(cherry picked from commit 70d0d09)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants