From 29c92261ee2a616175041c97cbfddfcd22a681cd Mon Sep 17 00:00:00 2001 From: booth-algo Date: Thu, 28 May 2026 09:05:53 +0100 Subject: [PATCH] Fix PREFETCH_M_AMOUNT assertion failure when MLEN > 64 When MLEN=128 or 256, the TOML default HBM_M_Prefetch_Amount (64) is smaller than MLEN, causing `load_amount % write_amount == 0` to fail in transfer_mx_from_hbm. Each matrix SRAM tile write requires exactly MLEN rows, so PREFETCH_M_AMOUNT must be >= MLEN and a multiple of it. Fix: clamp PREFETCH_M_AMOUNT to the nearest multiple of MLEN at startup, with a warning when adjustment is needed. Fixes the dev console crash at MLEN=128 reported by the GUI backend. Co-Authored-By: Claude Opus 4.6 (1M context) --- transactional_emulator/src/main.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/transactional_emulator/src/main.rs b/transactional_emulator/src/main.rs index ba28e244..4b248b44 100644 --- a/transactional_emulator/src/main.rs +++ b/transactional_emulator/src/main.rs @@ -64,7 +64,28 @@ static MATRIX_WEIGHT_TYPE: LazyLock = LazyLock::new(|| matrix_weight static MATRIX_KV_TYPE: LazyLock = LazyLock::new(|| matrix_kv_type()); static VECTOR_ACTIVATION_TYPE: LazyLock = LazyLock::new(|| vector_activation_type()); static VECTOR_KV_TYPE: LazyLock = LazyLock::new(|| vector_kv_type()); -static PREFETCH_M_AMOUNT: LazyLock = LazyLock::new(|| hbm_m_prefetch_amount()); +static PREFETCH_M_AMOUNT: LazyLock = LazyLock::new(|| { + let raw = hbm_m_prefetch_amount(); + let mlen = mlen(); + // Must be a multiple of MLEN (one full matrix tile per write). + // Round up to the nearest multiple of MLEN if needed. + if raw < mlen { + tracing::warn!( + "HBM_M_Prefetch_Amount ({}) < MLEN ({}); clamping to MLEN", + raw, mlen + ); + mlen + } else if raw % mlen != 0 { + let clamped = ((raw + mlen - 1) / mlen) * mlen; + tracing::warn!( + "HBM_M_Prefetch_Amount ({}) not a multiple of MLEN ({}); rounding up to {}", + raw, mlen, clamped + ); + clamped + } else { + raw + } +}); static PREFETCH_V_AMOUNT: LazyLock = LazyLock::new(|| hbm_v_prefetch_amount()); static STORE_V_AMOUNT: LazyLock = LazyLock::new(|| hbm_v_writeback_amount());