From fc0656ac836a1635f82cc5a8d011b7ef22b681c1 Mon Sep 17 00:00:00 2001 From: Brett England Date: Tue, 29 Sep 2026 00:26:10 -0400 Subject: [PATCH] Synchronize cross-SIMD WHT reads before shared-memory writes --- Libraries/MLXLMCommon/TurboQuantKernels.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/MLXLMCommon/TurboQuantKernels.swift b/Libraries/MLXLMCommon/TurboQuantKernels.swift index d455f470a5..bf1e963a6e 100644 --- a/Libraries/MLXLMCommon/TurboQuantKernels.swift +++ b/Libraries/MLXLMCommon/TurboQuantKernels.swift @@ -286,12 +286,14 @@ enum TurboQuantMetalKernels { if (pos_in_block < half_block) { a = shared_buf[block_id * block_size + pos_in_block]; b = shared_buf[block_id * block_size + pos_in_block + half_block]; - shared_buf[d] = a + b; } else { a = shared_buf[block_id * block_size + pos_in_block - half_block]; b = shared_buf[block_id * block_size + pos_in_block]; - shared_buf[d] = a - b; } + float next = (pos_in_block < half_block) ? (a + b) : (a - b); + // All groups must finish reading this stage before any overwrite. + threadgroup_barrier(mem_flags::mem_threadgroup); + shared_buf[d] = next; threadgroup_barrier(mem_flags::mem_threadgroup); } wht_val = shared_buf[d];