"""Kernel used by ``kernbench.tp`` layers (ADR-0027 D4/D5).

Intentionally self-contained inside the ``tp`` package — the ``tp`` package
must not import from ``benches/``. Future work: move to a shared
``kernbench.kernels`` module so benches and TP can share.
"""
from __future__ import annotations


def _gemm_kernel(a_ptr, b_ptr, out_ptr, M, K, N, tl, DTYPE: str = "f16") -> None:
    """Single-PE GEMM: out = a @ b via load → dot → store.

    Uses the ``tl.load + tl.dot + tl.store`` path. Unlike ``tl.composite``
    (which is absorbed by the PE scheduler into TileTokens that don't reach
    the op_log), this path emits explicit ``DmaReadCmd`` / ``GemmCmd`` /
    ``DmaWriteCmd`` records, which DataExecutor replays numerically in
    Phase 2.
    """
    M, K, N = int(M), int(K), int(N)
    a = tl.load(int(a_ptr), shape=(M, K), dtype=DTYPE)
    b = tl.load(int(b_ptr), shape=(K, N), dtype=DTYPE)
    out = tl.dot(a, b)
    tl.store(int(out_ptr), out)
