(a, b)
| 364 | |
| 365 | |
| 366 | def matmul_persistent(a, b): |
| 367 | # Check constraints. |
| 368 | assert a.shape[1] == b.shape[0], "Incompatible dimensions" |
| 369 | assert a.dtype == b.dtype, "Incompatible dtypes" |
| 370 | NUM_SMS = torch.cuda.get_device_properties("cuda").multi_processor_count |
| 371 | M, K = a.shape |
| 372 | K, N = b.shape |
| 373 | dtype = a.dtype |
| 374 | # Allocates output. |
| 375 | c = torch.empty((M, N), device=a.device, dtype=dtype) |
| 376 | # 1D launch kernel where each block gets its own program. |
| 377 | grid = lambda META: ( |
| 378 | min(NUM_SMS, triton.cdiv(M, META["BLOCK_SIZE_M"]) * triton.cdiv(N, META["BLOCK_SIZE_N"])), |
| 379 | ) |
| 380 | matmul_kernel_persistent[grid]( |
| 381 | a, |
| 382 | b, |
| 383 | c, # |
| 384 | M, |
| 385 | N, |
| 386 | K, # |
| 387 | a.stride(0), |
| 388 | a.stride(1), # |
| 389 | b.stride(0), |
| 390 | b.stride(1), # |
| 391 | c.stride(0), |
| 392 | c.stride(1), # |
| 393 | NUM_SMS=NUM_SMS, # |
| 394 | ) |
| 395 | return c |
| 396 | |
| 397 | |
| 398 | def matmul_tma_persistent_get_configs(pre_hook=None): |
nothing calls this directly
no outgoing calls
no test coverage detected