From 328f9b00804083ab06038550afa15ef6dfac3106 Mon Sep 17 00:00:00 2001 From: biondizzle Date: Fri, 22 May 2026 21:36:22 +0000 Subject: [PATCH] Test n=384 --- tests/unit/test_384.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/unit/test_384.py diff --git a/tests/unit/test_384.py b/tests/unit/test_384.py new file mode 100644 index 00000000..8b8741fe --- /dev/null +++ b/tests/unit/test_384.py @@ -0,0 +1,31 @@ +"""Test n=384 pipeline cycling""" +import torch, math, cutlass, cutlass.cute as cute, cutlass.torch as ct, cuda.bindings.driver as cuda +from cutlass import Float32, BFloat16, Int32 +from test_fmha_v3_stage_c import FmhaV3StageCMulti + +n = 384; HEAD_DIM = 64 +torch.manual_seed(42) +q = torch.randn(128, HEAD_DIM, 1, dtype=torch.bfloat16, device='cuda') +k = torch.randn(n, HEAD_DIM, 1, dtype=torch.bfloat16, device='cuda') +v = torch.randn(n, HEAD_DIM, dtype=torch.bfloat16, device='cuda') +c = torch.zeros(128, HEAD_DIM, 1, dtype=torch.bfloat16, device='cuda') +qf = q[:,:,0].float(); kf = k[:,:,0].float() +ref = torch.softmax(qf @ kf.T * (1.0/math.sqrt(HEAD_DIM)), dim=-1) @ v.float() +mQ = ct.from_dlpack(q).mark_layout_dynamic(leading_dim=ct.get_leading_dim(q)) +mK = ct.from_dlpack(k).mark_layout_dynamic(leading_dim=ct.get_leading_dim(k)) +mV = ct.from_dlpack(v.unsqueeze(-1)).mark_layout_dynamic(leading_dim=ct.get_leading_dim(v.unsqueeze(-1))) +mC = ct.from_dlpack(c).mark_layout_dynamic(leading_dim=ct.get_leading_dim(c)) +stream = cuda.CUstream(torch.cuda.current_stream().cuda_stream) +kernel = FmhaV3StageCMulti(s_k=n) +print(f'n={n}: Compiling...', flush=True) +try: + compiled = cute.compile(kernel, mQ, mK, mV, mC, stream) + compiled(mQ, mK, mV, mC, stream) + torch.cuda.synchronize() + out = c[:,:,0].float() + cos = torch.nn.functional.cosine_similarity(out.flatten().unsqueeze(0), ref.flatten().unsqueeze(0)).item() + print(f'n={n} (3 tiles): cos {cos:.6f} {"PASS" if cos >= 0.99 else "FAIL"}') + if cos < 0.99 and cos > 0.5: + print(f' ratio: {(out[0,:4]/ref[0,:4]).mean().item():.4f}') +except Exception as e: + print(f'n={n}: ERROR: {type(e).__name__}: {str(e)[:300]}')