MCPcopy Create free account
hub / github.com/FlashSampling/FlashSampling / matmul_persistent

Function matmul_persistent

src/fused_mm_sampling/persistent_matmul.py:366–395  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

364
365
366def 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
398def matmul_tma_persistent_get_configs(pre_hook=None):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected