08812eda58
Implement VA/MMU layer (ADR-0011 Phase 1) enabling Triton kernels to use contiguous virtual addresses on sharded tensors. Key changes: - PE_MMU component: hybrid inbox (MmuMapMsg) + sync translate() for PE_DMA - VirtualAllocator + PEMemAllocator: free-list with coalescing - MmuMapMsg/MmuUnmapMsg fabric path with SIP-level routing - DPPolicy-based mapping: replicate=local, sharded=broadcast - Tensor lifecycle: del + weakref cleanup, context manager - Rename: TensorHandle.pa→addr, DmaReadCmd.src_pa→src_addr, ctx→torch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""QKV GEMM benchmark: Q*K^T projection on all PEs in a cube (multi-PE).
|
|
|
|
Column-parallel GEMM: a is replicated (cube-level), b/out are column-sharded.
|
|
M_CPU fans out KernelLaunchMsg to all 8 PE_CPUs (ADR-0009 D3).
|
|
|
|
Kernel: tl.load(a) + tl.ref(b) + tl.composite(gemm) + tl.wait()
|
|
- Tensor a is loaded into TCM via DMA
|
|
- Tensor b stays in HBM; PE_SCHEDULER streams it per-tile (32x64x32)
|
|
"""
|
|
from kernbench.policy.placement.dp import DPPolicy
|
|
|
|
# GEMM dimensions: (M, K) x (K, N) -> (M, N)
|
|
M, K, N = 128, 256, 128
|
|
DTYPE = "f16"
|
|
|
|
|
|
def _gemm_kernel(a_ptr, b_ptr, out_ptr, M, K, N, tl, DTYPE="f16"):
|
|
"""QKV GEMM kernel: out = a @ b.
|
|
|
|
a is loaded into TCM (DMA_READ).
|
|
b is referenced in HBM (tl.ref, no DMA -- scheduler streams per-tile).
|
|
"""
|
|
a = tl.load(a_ptr, shape=(M, K), dtype=DTYPE)
|
|
b = tl.ref(b_ptr, shape=(K, N), dtype=DTYPE)
|
|
handle = tl.composite(op="gemm", a=a, b=b, out_ptr=out_ptr)
|
|
tl.wait(handle)
|
|
|
|
|
|
def run(torch):
|
|
"""Run the multi-PE QKV GEMM benchmark."""
|
|
# DP placement: a=replicate (cube-level), b/out=column_wise (N-axis split)
|
|
a = torch.zeros((M, K), dtype=DTYPE, dp=DPPolicy(cube="replicate", pe="replicate"), name="a")
|
|
b = torch.zeros((K, N), dtype=DTYPE, dp=DPPolicy(cube="replicate", pe="column_wise"), name="b")
|
|
out = torch.empty(
|
|
(M, N), dtype=DTYPE, dp=DPPolicy(cube="replicate", pe="column_wise"), name="out",
|
|
)
|
|
|
|
# Launch GEMM kernel on all PEs
|
|
torch.launch("qkv_gemm_multi", _gemm_kernel, a, b, out, M, K, N)
|