### Why Move Beyond PyTorch Native Operators?
Standard deep learning frameworks provide highly optimized cuBLAS calls. However, when combining dequantization, scaling factors, and activation functions, separate kernel launches incur significant memory bandwidth overhead.
Writing fused kernels in OpenAI Triton allows researchers to achieve near-CUDA C++ performance directly in Python without navigating raw PTX assembly.
Memory Coalescing & Block Level Tiling
The primary consideration when writing Triton kernels is aligning memory access patterns with GPU cache line boundaries:
@triton.jit
def fp8_gemm_kernel(
a_ptr, b_ptr, c_ptr,
M, N, K,
stride_am, stride_ak,
stride_bk, stride_bn,
stride_cm, stride_cn,
BLOCK_SIZE_M: tl.constexpr,
BLOCK_SIZE_N: tl.constexpr,
BLOCK_SIZE_K: tl.constexpr,
):
# Kernel code mapping program IDs to matrix tiles
pid = tl.program_id(axis=0)
# Tiled matrix multiplication with fused scale multiplication
Benchmark Findings
- Fused dequantization reduced kernel launch count from 3 to 1.
- Sustained memory throughput reached **82% of peak theoretical bandwidth** on Ada Lovelace architecture.