MCPcopy Create free account
hub / github.com/tile-ai/tilelang / run_gemm

Function run_gemm

testing/python/kernel/test_tilelang_kernel_gemm.py:52–103  ·  view source on GitHub ↗
(
    M,
    N,
    K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    dtypeAccum,
    block_M,
    block_N,
    block_K,
    num_stages=0,
    num_threads=128,
)

Source from the content-addressed store, hash-verified

50
51
52def 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

Callers 14

test_gemm_f16f16f16_nnFunction · 0.70
test_gemm_f16f16f32_nnFunction · 0.70
test_gemm_bf16bf16f32_nnFunction · 0.70
test_gemm_f32f32f32_nnFunction · 0.70
test_gemm_f16f16f16_tnFunction · 0.70
test_gemm_f16f16f16_ntFunction · 0.70
test_gemm_i8i8i32_ntFunction · 0.70
test_gemm_i8i8i32_tnFunction · 0.70
test_gemm_f64f64f64_ntFunction · 0.70
test_gemm_f32f32f32_ntFunction · 0.70
test_gemm_f32f32f32_tnFunction · 0.70

Calls 6

printFunction · 0.85
get_profilerMethod · 0.80
assert_allcloseMethod · 0.80
matmulFunction · 0.70
compileMethod · 0.45
get_kernel_sourceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…