Entry point called by bench.py. Must match reference.softmax_ref signature.
(x: torch.Tensor)
| 243 | |
| 244 | |
| 245 | def kernel_fn(x: torch.Tensor) -> torch.Tensor: |
| 246 | """Entry point called by bench.py. Must match reference.softmax_ref signature.""" |
| 247 | assert x.is_cuda |
| 248 | |
| 249 | # Preserve original shape and dtype |
| 250 | orig_shape = x.shape |
| 251 | orig_dtype = x.dtype |
| 252 | |
| 253 | # Ensure contiguous layout |
| 254 | x = x.contiguous() |
| 255 | |
| 256 | # Flatten to 2-D: (n_rows, n_cols) -- softmax along last dim |
| 257 | if x.ndim == 1: |
| 258 | x = x.unsqueeze(0) |
| 259 | elif x.ndim > 2: |
| 260 | x = x.view(-1, x.shape[-1]) |
| 261 | |
| 262 | # The CUDA launcher handles fp16/bf16/fp32 internally. |
| 263 | # For unsupported dtypes, cast to fp32 round-trip. |
| 264 | needs_cast = orig_dtype not in (torch.float16, torch.bfloat16, torch.float32) |
| 265 | if needs_cast: |
| 266 | x = x.to(torch.float32) |
| 267 | |
| 268 | mod = _get_module() |
| 269 | out = mod.softmax_cuda(x) |
| 270 | |
| 271 | # Cast back if we had to promote |
| 272 | if needs_cast: |
| 273 | out = out.to(orig_dtype) |
| 274 | |
| 275 | return out.view(orig_shape) |
nothing calls this directly
no test coverage detected