From 80434d02846ab457bc2d600b0d0eaf24e612e90a Mon Sep 17 00:00:00 2001 From: biondizzle Date: Sat, 23 May 2026 06:03:27 +0000 Subject: [PATCH] =?UTF-8?q?D1.1:=20Fix=20PV=20A-operand=20construction=20?= =?UTF-8?q?=E2=80=94=20compile-time=20branch=20for=20TMEM=20vs=20SMEM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dsv4/kernels/attention/fmha.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dsv4/kernels/attention/fmha.py b/dsv4/kernels/attention/fmha.py index 4cb3682c..dedaa0d1 100644 --- a/dsv4/kernels/attention/fmha.py +++ b/dsv4/kernels/attention/fmha.py @@ -166,14 +166,20 @@ class FmhaKernel: tOtO = pv_thr.make_fragment_C(pv_as) tOtO0 = cute.make_tensor(tOtO.iterator + self.tmem_o0_offset, tOtO.layout) - # PV A-operand: always define both TMEM and SMEM paths (CuTeDSL scoping) - tP = cute.make_tensor(tStS.iterator, p_tmem_s.outer) - tOrP_base = pv_thr.make_fragment_A(tP) - tOrP = tOrP_base[(None,None,None,0)] - tOrP0 = cute.make_tensor( - tOrP.iterator + self.qk_acc_dtype.width // self.q_dtype.width * max(self.tmem_p0_offset, 0), - tOrP.layout) - tCrP = pv_mma.make_fragment_A(sP) + # PV A-operand: constructed based on use_smem_p (compile-time branch) + if not self.use_smem_p: + # TMEM-P: PV reads P from TMEM alias of QK C-fragment + tP = cute.make_tensor(tStS.iterator, p_tmem_s.outer) + tOrP_base = pv_thr.make_fragment_A(tP) + tOrP = tOrP_base[(None,None,None,0)] + tOrP0 = cute.make_tensor( + tOrP.iterator + self.qk_acc_dtype.width // self.q_dtype.width * self.tmem_p0_offset, + tOrP.layout) + tCrP = pv_mma.make_fragment_A(sP) # dummy, never used + else: + # SMEM-P: PV reads P from SMEM + tOrP0 = cute.make_tensor(tStS.iterator, tStS.layout) # dummy, never used + tCrP = pv_mma.make_fragment_A(sP) tCtO_fake = pv_mma.make_fragment_C(cute.append(pv_as, self.num_acc_stage)) pipeline.pipeline_init_wait(cluster_shape_mn=cl_vmnk)