Entry point called by bench.py. Must match reference.layernorm_ref signature.
(
x: torch.Tensor,
weight: torch.Tensor,
bias: torch.Tensor,
eps: float = 1e-5,
)
| 63 | |
| 64 | |
| 65 | def kernel_fn( |
| 66 | x: torch.Tensor, |
| 67 | weight: torch.Tensor, |
| 68 | bias: torch.Tensor, |
| 69 | eps: float = 1e-5, |
| 70 | ) -> torch.Tensor: |
| 71 | """Entry point called by bench.py. Must match reference.layernorm_ref signature.""" |
| 72 | assert x.is_cuda |
| 73 | |
| 74 | # Flatten to 2D for row-parallel processing |
| 75 | orig_shape = x.shape |
| 76 | if x.ndim == 1: |
| 77 | x = x.unsqueeze(0) |
| 78 | elif x.ndim > 2: |
| 79 | x = x.view(-1, x.shape[-1]) |
| 80 | |
| 81 | n_rows, n_cols = x.shape |
| 82 | assert weight.shape[0] == n_cols |
| 83 | assert bias.shape[0] == n_cols |
| 84 | |
| 85 | y = torch.empty_like(x) |
| 86 | |
| 87 | BLOCK_SIZE = triton.next_power_of_2(n_cols) |
| 88 | |
| 89 | grid = (n_rows,) |
| 90 | layernorm_kernel[grid]( |
| 91 | x, y, |
| 92 | weight, bias, |
| 93 | x.stride(0), |
| 94 | y.stride(0), |
| 95 | n_cols, |
| 96 | eps, |
| 97 | BLOCK_SIZE=BLOCK_SIZE, |
| 98 | ) |
| 99 | |
| 100 | return y.view(orig_shape) |
nothing calls this directly
no outgoing calls
no test coverage detected