(
M,
N,
K,
trans_A,
trans_B,
in_dtype,
out_dtype,
dtypeAccum,
block_M,
block_N,
block_K,
num_stages=0,
num_threads=128,
)
| 50 | |
| 51 | |
| 52 | def run_gemm( |
| 53 | M, |
| 54 | N, |
| 55 | K, |
| 56 | trans_A, |
| 57 | trans_B, |
| 58 | in_dtype, |
| 59 | out_dtype, |
| 60 | dtypeAccum, |
| 61 | block_M, |
| 62 | block_N, |
| 63 | block_K, |
| 64 | num_stages=0, |
| 65 | num_threads=128, |
| 66 | ): |
| 67 | program = matmul( |
| 68 | M, |
| 69 | N, |
| 70 | K, |
| 71 | block_M, |
| 72 | block_N, |
| 73 | block_K, |
| 74 | trans_A, |
| 75 | trans_B, |
| 76 | in_dtype, |
| 77 | out_dtype, |
| 78 | dtypeAccum, |
| 79 | num_stages, |
| 80 | num_threads, |
| 81 | ) |
| 82 | |
| 83 | kernel = tilelang.compile(program, out_idx=[2]) |
| 84 | print(kernel.get_kernel_source()) |
| 85 | profiler = kernel.get_profiler() |
| 86 | |
| 87 | def ref_program(A, B): |
| 88 | import torch |
| 89 | |
| 90 | if trans_A: |
| 91 | A = A.T |
| 92 | if trans_B: |
| 93 | B = B.T |
| 94 | if in_dtype == T.tfloat32: |
| 95 | # Convert float32 to tfloat32 because tfloat32 mma cannot truncate |
| 96 | # float32 automatically, -0x1000 meas |
| 97 | A = (A.view(torch.int32) - 0x1000).view(torch.float32) |
| 98 | B = (B.view(torch.int32) - 0x1000).view(torch.float32) |
| 99 | C = torch.matmul(A.to(torch.float), B.to(torch.float)) |
| 100 | C = C.to(torch.__getattribute__(out_dtype)) |
| 101 | return C |
| 102 | |
| 103 | profiler.assert_allclose(ref_program, atol=1e-2, rtol=1e-2) |
| 104 | |
| 105 | |
| 106 | @tilelang.testing.requires_cuda |
no test coverage detected
searching dependent graphs…