"vscode:/vscode.git/clone" did not exist on "fdf09748be6bfb14f254084a7eac4275f6eb1fe2"
correctness_evaluation.py 21.3 KB
Newer Older
1
# pytest correctness_evaluation.py -n 32
2
3
4
import pytest
from tilelang import tvm as tvm
import tilelang.testing
5
6
from tilelang import language as T
import torch
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30


def matmul(
    M,
    N,
    K,
    block_M,
    block_N,
    block_K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    accum_dtype,
    num_stages,
    threads,
):
    A_shape = (K, M) if trans_A else (M, K)
    B_shape = (N, K) if trans_B else (K, N)
    A_shared_shape = (block_K, block_M) if trans_A else (block_M, block_K)
    B_shared_shape = (block_N, block_K) if trans_B else (block_K, block_N)

    @T.prim_func
    def main(
31
32
33
        A: T.Tensor(A_shape, in_dtype),
        B: T.Tensor(B_shape, in_dtype),
        C: T.Tensor((M, N), out_dtype),
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    ):
        with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=threads) as (bx, by):
            A_shared = T.alloc_shared(A_shared_shape, in_dtype, scope="shared.dyn")
            B_shared = T.alloc_shared(B_shared_shape, in_dtype, scope="shared.dyn")
            C_local = T.alloc_fragment((block_M, block_N), accum_dtype)
            T.clear(C_local)
            for k in T.Pipelined(T.ceildiv(K, block_K), num_stages=num_stages):
                if trans_A:
                    T.copy(A[k * block_K, by * block_M], A_shared)
                else:
                    T.copy(A[by * block_M, k * block_K], A_shared)
                if trans_B:
                    T.copy(B[bx * block_N, k * block_K], B_shared)
                else:
                    T.copy(B[k * block_K, bx * block_N], B_shared)
49
                T.gemm(A_shared, B_shared, C_local, trans_A, trans_B)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
            T.copy(C_local, C[by * block_M, bx * block_N])

    return main


def _compile_and_check(
    program,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
):
    kernel = tilelang.compile(
        program,
        out_idx=[2],
        pass_configs={
            tilelang.PassConfigKey.TL_DISABLE_TMA_LOWER: True,
            tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True,
            # tilelang.PassConfigKey.TIR_USE_ASYNC_COPY: False,
69
70
        },
    )
71
72
73
74
75
76
77
78
79
80

    print(kernel.get_kernel_source())

    profiler = kernel.get_profiler(tensor_supply_type=tilelang.TensorSupplyType.Normal)

    def ref_program(A, B):
        if trans_A:
            A = A.T
        if trans_B:
            B = B.T
81
        if in_dtype == T.float32:
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
            A = (A.view(torch.int32) - 0x1000).view(torch.float32)
            B = (B.view(torch.int32) - 0x1000).view(torch.float32)
        C = torch.matmul(A.to(torch.float), B.to(torch.float))
        C = C.to(torch.__getattribute__(out_dtype))
        return C

    profiler.assert_allclose(ref_program, atol=1e-2, rtol=1e-2)
    print("assert_allclose")


def run_gemm(
    M,
    N,
    K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    dtypeAccum,
    block_M,
    block_N,
    block_K,
104
    num_stages=2,
105
106
    num_threads=128,
):
107
108
    if block_N >= 256 or block_M >= 256 or block_K >= 256:
        num_stages = 0
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    program = matmul(
        M,
        N,
        K,
        block_M,
        block_N,
        block_K,
        trans_A,
        trans_B,
        in_dtype,
        out_dtype,
        dtypeAccum,
        num_stages,
        num_threads,
    )

    _compile_and_check(program, trans_A, trans_B, in_dtype, out_dtype)


def matmul_rs(
    M,
    N,
    K,
    block_M,
    block_N,
    block_K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    accum_dtype,
    num_stages,
    threads,
):
    A_shape = (K, M) if trans_A else (M, K)
    B_shape = (N, K) if trans_B else (K, N)
    A_shared_shape = (block_K, block_M) if trans_A else (block_M, block_K)
    B_shared_shape = (block_N, block_K) if trans_B else (block_K, block_N)
    A_frag_shape = A_shared_shape

    @T.prim_func
    def main(
151
152
153
        A: T.Tensor(A_shape, in_dtype),
        B: T.Tensor(B_shape, in_dtype),
        C: T.Tensor((M, N), out_dtype),
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    ):
        with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=threads) as (bx, by):
            A_shared = T.alloc_shared(A_shared_shape, in_dtype, scope="shared.dyn")
            B_shared = T.alloc_shared(B_shared_shape, in_dtype, scope="shared.dyn")
            A_frag = T.alloc_fragment(A_frag_shape, in_dtype)
            C_local = T.alloc_fragment((block_M, block_N), accum_dtype)
            T.clear(C_local)
            for k in T.Pipelined(T.ceildiv(K, block_K), num_stages=num_stages):
                if trans_A:
                    T.copy(A[k * block_K, by * block_M], A_shared)
                else:
                    T.copy(A[by * block_M, k * block_K], A_shared)
                if trans_B:
                    T.copy(B[bx * block_N, k * block_K], B_shared)
                else:
                    T.copy(B[k * block_K, bx * block_N], B_shared)
                T.copy(A_shared, A_frag)
                T.gemm_v2(A_frag, B_shared, C_local, trans_A, trans_B)
                # T.gemm(A_frag, B_shared, C_local, trans_A, trans_B)
            T.copy(C_local, C[by * block_M, bx * block_N])

    return main


def run_gemm_rs(
    M,
    N,
    K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    dtypeAccum,
    block_M,
    block_N,
    block_K,
190
    num_stages=2,
191
192
    num_threads=128,
):
193
194
    if block_N >= 256 or block_M >= 256 or block_K >= 256:
        num_stages = 0
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
    program = matmul_rs(
        M,
        N,
        K,
        block_M,
        block_N,
        block_K,
        trans_A,
        trans_B,
        in_dtype,
        out_dtype,
        dtypeAccum,
        num_stages,
        num_threads,
    )
    _compile_and_check(program, trans_A, trans_B, in_dtype, out_dtype)


def matmul_sr(
    M,
    N,
    K,
    block_M,
    block_N,
    block_K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    accum_dtype,
    num_stages,
    threads,
):
    A_shape = (K, M) if trans_A else (M, K)
    B_shape = (N, K) if trans_B else (K, N)
    A_shared_shape = (block_K, block_M) if trans_A else (block_M, block_K)
    B_shared_shape = (block_N, block_K) if trans_B else (block_K, block_N)
    B_frag_shape = B_shared_shape

    @T.prim_func
    def main(
236
237
238
        A: T.Tensor(A_shape, in_dtype),
        B: T.Tensor(B_shape, in_dtype),
        C: T.Tensor((M, N), out_dtype),
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
    ):
        with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=threads) as (bx, by):
            A_shared = T.alloc_shared(A_shared_shape, in_dtype, scope="shared.dyn")
            B_shared = T.alloc_shared(B_shared_shape, in_dtype, scope="shared.dyn")
            B_frag = T.alloc_fragment(B_frag_shape, in_dtype)
            C_local = T.alloc_fragment((block_M, block_N), accum_dtype)
            T.clear(C_local)
            for k in T.Pipelined(T.ceildiv(K, block_K), num_stages=num_stages):
                if trans_A:
                    T.copy(A[k * block_K, by * block_M], A_shared)
                else:
                    T.copy(A[by * block_M, k * block_K], A_shared)
                if trans_B:
                    T.copy(B[bx * block_N, k * block_K], B_shared)
                else:
                    T.copy(B[k * block_K, bx * block_N], B_shared)
                T.copy(B_shared, B_frag)
                T.gemm_v2(A_shared, B_frag, C_local, trans_A, trans_B)
            T.copy(C_local, C[by * block_M, bx * block_N])

    return main


def run_gemm_sr(
    M,
    N,
    K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    dtypeAccum,
    block_M,
    block_N,
    block_K,
274
    num_stages=2,
275
276
    num_threads=128,
):
277
278
    if block_N >= 256 or block_M >= 256 or block_K >= 256:
        num_stages = 0
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    program = matmul_sr(
        M,
        N,
        K,
        block_M,
        block_N,
        block_K,
        trans_A,
        trans_B,
        in_dtype,
        out_dtype,
        dtypeAccum,
        num_stages,
        num_threads,
    )

    _compile_and_check(program, trans_A, trans_B, in_dtype, out_dtype)


def matmul_rr(
    M,
    N,
    K,
    block_M,
    block_N,
    block_K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    accum_dtype,
    num_stages,
    threads,
):
    A_shape = (K, M) if trans_A else (M, K)
    B_shape = (N, K) if trans_B else (K, N)
    A_shared_shape = (block_K, block_M) if trans_A else (block_M, block_K)
    B_shared_shape = (block_N, block_K) if trans_B else (block_K, block_N)
    A_frag_shape = A_shared_shape
    B_frag_shape = B_shared_shape

    @T.prim_func
    def main(
322
323
324
        A: T.Tensor(A_shape, in_dtype),
        B: T.Tensor(B_shape, in_dtype),
        C: T.Tensor((M, N), out_dtype),
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
    ):
        with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=threads) as (bx, by):
            A_shared = T.alloc_shared(A_shared_shape, in_dtype, scope="shared.dyn")
            B_shared = T.alloc_shared(B_shared_shape, in_dtype, scope="shared.dyn")
            A_frag = T.alloc_fragment(A_frag_shape, in_dtype)
            B_frag = T.alloc_fragment(B_frag_shape, in_dtype)
            C_local = T.alloc_fragment((block_M, block_N), accum_dtype)
            T.clear(C_local)
            for k in T.Pipelined(T.ceildiv(K, block_K), num_stages=num_stages):
                if trans_A:
                    T.copy(A[k * block_K, by * block_M], A_shared)
                else:
                    T.copy(A[by * block_M, k * block_K], A_shared)
                if trans_B:
                    T.copy(B[bx * block_N, k * block_K], B_shared)
                else:
                    T.copy(B[k * block_K, bx * block_N], B_shared)
                T.copy(A_shared, A_frag)
                T.copy(B_shared, B_frag)
                T.gemm_v2(A_frag, B_frag, C_local, trans_A, trans_B)
            T.copy(C_local, C[by * block_M, bx * block_N])

    return main


def run_gemm_rr(
    M,
    N,
    K,
    trans_A,
    trans_B,
    in_dtype,
    out_dtype,
    dtypeAccum,
    block_M,
    block_N,
    block_K,
362
    num_stages=2,
363
364
    num_threads=128,
):
365
366
    if block_N >= 256 or block_M >= 256 or block_K >= 256:
        num_stages = 0
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
    program = matmul_rr(
        M,
        N,
        K,
        block_M,
        block_N,
        block_K,
        trans_A,
        trans_B,
        in_dtype,
        out_dtype,
        dtypeAccum,
        num_stages,
        num_threads,
    )

    _compile_and_check(program, trans_A, trans_B, in_dtype, out_dtype)


M_VALUES = [64, 128, 256]
387
N_VALUES = [16, 32, 64, 128, 256, 512]
388
389
K_VALUES = [16, 32, 64, 128]
K_VALUES_8Bit = [32, 64, 128]
390
391
392
393
FALSE_TRUE_CASES = (
    [
        pytest.param(
            k,
394
395
396
            T.float16,
            T.float16,
            T.float16,
397
398
399
400
401
402
403
            id=f"K{k}-float16-float16-float16",
        )
        for k in K_VALUES
    ]
    + [
        pytest.param(
            k,
404
405
406
            T.int8,
            T.int32,
            T.int32,
407
408
409
410
411
412
413
            id="K32-int8-int32-int32",
        )
        for k in K_VALUES_8Bit
    ]
    + [
        pytest.param(
            k,
414
415
416
            T.float8_e5m2,
            T.float32,
            T.float32,
417
418
419
420
421
422
423
            id="K32-float8_e5m2-float32-float32",
        )
        for k in K_VALUES_8Bit
    ]
    + [
        pytest.param(
            k,
424
425
426
            T.float8_e4m3fn,
            T.float32,
            T.float32,
427
428
429
430
431
            id="K32-float8_e4m3-float32-float32",
        )
        for k in K_VALUES_8Bit
    ]
)
432
433
434
435
436
437
438
439
440
441
442


def _ensure_torch_dtypes(*dtype_names):
    import torch

    for name in set(dtype_names):
        if not hasattr(torch, name):
            pytest.skip(f"Torch does not expose dtype {name}")


def run_gemm_rs_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
443
    run_gemm_rs(m, n, k * 3, False, True, in_dtype, out_dtype, accum_dtype, m, n, k)
444
445
446


def run_gemm_rs_false_false(m, n, k):
447
    run_gemm_rs(m, n, k * 3, False, False, T.float16, T.float16, T.float16, m, n, k)
448
449
450


def run_gemm_rs_true_false(m, n, k):
451
    run_gemm_rs(m, n, k * 3, True, False, T.float16, T.float16, T.float16, m, n, k)
452
453
454


def run_gemm_rs_true_true(m, n, k):
455
    run_gemm_rs(m, n, k * 3, True, True, T.float16, T.float16, T.float16, m, n, k)
456
457
458


def run_gemm_sr_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
459
    run_gemm_sr(m, n, k * 3, False, True, in_dtype, out_dtype, accum_dtype, m, n, k)
460
461
462


def run_gemm_sr_false_false(m, n, k):
463
    run_gemm_sr(m, n, k * 3, False, False, T.float16, T.float16, T.float16, m, n, k)
464
465
466


def run_gemm_sr_true_false(m, n, k):
467
    run_gemm_sr(m, n, k * 3, True, False, T.float16, T.float16, T.float16, m, n, k)
468
469
470


def run_gemm_sr_true_true(m, n, k):
471
    run_gemm_sr(m, n, k * 3, True, True, T.float16, T.float16, T.float16, m, n, k)
472
473
474


def run_gemm_rr_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
475
    run_gemm_rr(m, n, k * 3, False, True, in_dtype, out_dtype, accum_dtype, m, n, k)
476
477
478


def run_gemm_rr_false_false(m, n, k):
479
    run_gemm_rr(m, n, k * 3, False, False, T.float16, T.float16, T.float16, m, n, k)
480
481
482


def run_gemm_rr_true_false(m, n, k):
483
    run_gemm_rr(m, n, k * 3, True, False, T.float16, T.float16, T.float16, m, n, k)
484
485
486


def run_gemm_rr_true_true(m, n, k):
487
    run_gemm_rr(m, n, k * 3, True, True, T.float16, T.float16, T.float16, m, n, k)
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542


TRANS_CASES = [
    pytest.param(False, False, id="nn"),
    pytest.param(False, True, id="nt"),
    pytest.param(True, False, id="tn"),
    pytest.param(True, True, id="tt"),
]


@pytest.fixture(scope="module", autouse=True)
def _setup_tilelang_environment():
    tilelang.disable_cache()
    tilelang.testing.set_random_seed(42)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k,in_dtype,out_dtype,accum_dtype", FALSE_TRUE_CASES)
def test_gemm_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
    import torch

    required_torch_attrs = {
        in_dtype,
        out_dtype,
        accum_dtype,
    }
    for attr in required_torch_attrs:
        if not hasattr(torch, attr):
            pytest.skip(f"Torch does not expose dtype {attr}")
    run_gemm(
        m,
        n,
        k * 3,
        False,
        True,
        in_dtype,
        out_dtype,
        accum_dtype,
        m,
        n,
        k,
    )


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_false_false(m, n, k):
    run_gemm(
        m,
        n,
        k * 3,
        False,
        False,
543
544
545
        T.float16,
        T.float16,
        T.float16,
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
        m,
        n,
        k,
    )


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_true_false(m, n, k):
    run_gemm(
        m,
        n,
        k * 3,
        True,
        False,
562
563
564
        T.float16,
        T.float16,
        T.float16,
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
        m,
        n,
        k,
    )


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_true_true(m, n, k):
    run_gemm(
        m,
        n,
        k * 3,
        True,
        True,
581
582
583
        T.float16,
        T.float16,
        T.float16,
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
        m,
        n,
        k,
    )


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k,in_dtype,out_dtype,accum_dtype", FALSE_TRUE_CASES)
def test_gemm_rs_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
    _ensure_torch_dtypes(in_dtype, out_dtype, accum_dtype)
    run_gemm_rs_false_true(m, n, k, in_dtype, out_dtype, accum_dtype)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_rs_false_false(m, n, k):
602
    _ensure_torch_dtypes(T.float16)
603
604
605
606
607
608
609
    run_gemm_rs_false_false(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_rs_true_false(m, n, k):
610
    _ensure_torch_dtypes(T.float16)
611
612
613
614
615
616
617
    run_gemm_rs_true_false(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_rs_true_true(m, n, k):
618
    _ensure_torch_dtypes(T.float16)
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
    run_gemm_rs_true_true(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k,in_dtype,out_dtype,accum_dtype", FALSE_TRUE_CASES)
def test_gemm_sr_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
    _ensure_torch_dtypes(in_dtype, out_dtype, accum_dtype)
    run_gemm_sr_false_true(m, n, k, in_dtype, out_dtype, accum_dtype)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_sr_false_false(m, n, k):
634
    _ensure_torch_dtypes(T.float16)
635
636
637
638
639
640
641
    run_gemm_sr_false_false(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_sr_true_false(m, n, k):
642
    _ensure_torch_dtypes(T.float16)
643
644
645
646
647
648
649
    run_gemm_sr_true_false(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_sr_true_true(m, n, k):
650
    _ensure_torch_dtypes(T.float16)
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
    run_gemm_sr_true_true(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k,in_dtype,out_dtype,accum_dtype", FALSE_TRUE_CASES)
def test_gemm_rr_false_true(m, n, k, in_dtype, out_dtype, accum_dtype):
    _ensure_torch_dtypes(in_dtype, out_dtype, accum_dtype)
    run_gemm_rr_false_true(m, n, k, in_dtype, out_dtype, accum_dtype)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_rr_false_false(m, n, k):
666
    _ensure_torch_dtypes(T.float16)
667
668
669
670
671
672
673
    run_gemm_rr_false_false(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_rr_true_false(m, n, k):
674
    _ensure_torch_dtypes(T.float16)
675
676
677
678
679
680
681
    run_gemm_rr_true_false(m, n, k)


@pytest.mark.parametrize("m", M_VALUES, ids=lambda v: f"M{v}")
@pytest.mark.parametrize("n", N_VALUES, ids=lambda v: f"N{v}")
@pytest.mark.parametrize("k", K_VALUES, ids=lambda v: f"K{v}")
def test_gemm_rr_true_true(m, n, k):
682
    _ensure_torch_dtypes(T.float16)
683
684
685
686
687
688
689
690
691
692
693
    run_gemm_rr_true_true(m, n, k)


if __name__ == "__main__":
    tilelang.testing.main()

    # # Test Pass
    # for m in [64, 128, 256]:
    #     for n in [16, 32, 64, 128]:
    #         for k in [16, 32, 64, 128]:
    #             print(f"======================= Test {m} {n} {k} False True =============================")
694
    #             run_gemm(m, n, k * 3, False, True, T.float16, T.float16, T.float16, m, n, k, 2, 128)
695
696
697
698
699
700
701
    #             print(f"Test {m} {n} {k} Pass")

    # # Test Pass
    # for m in [64, 128, 256]:
    #     for n in [16, 32, 64, 128]:
    #         for k in [16, 32, 64, 128]:
    #             print(f"======================= Test {m} {n} {k} False False =============================")
702
    #             run_gemm(m, n, k * 3, False, False, T.float16, T.float16, T.float16, m, n, k, 2, 128)
703
704
705
706
707
708
709
    #             print(f"Test {m} {n} {k} Pass")

    # # Test Pass
    # for m in [64, 128, 256]:
    #     for n in [16, 32, 64, 128]:
    #         for k in [16, 32, 64, 128]:
    #             print(f"======================= Test {m} {n} {k} True False =============================")
710
    #             run_gemm(m, n, k * 3, True, False, T.float16, T.float16, T.float16, m, n, k, 2, 128)
711
712
713
714
715
716
717
718
    #             print(f"Test {m}, {n} {k} Pass")
    #         print(f"Test {n} Pass")

    # # Test Pass
    # for m in [64, 128, 256]:
    #     for n in [16, 32, 64, 128]:
    #         for k in [16, 32, 64, 128]:
    #             print(f"======================= Test {m} {n} {k} True True =============================")
719
    #             run_gemm(m, n, k * 3, True, True, T.float16, T.float16, T.float16, m, n, k, 2, 128)
720
721
722
723
724
725
726
727
    #             print(f"Test {m}, {n} {k} Pass")
    #         print(f"Test {n} Pass")

    # Test Pass
    # for m in [64, 128, 256]:
    #     for n in [16, 32, 64, 128]:
    #         for k in [16, 32, 64, 128]:
    #             print(f"======================= Test {m} {n} {k} False True =============================")
728
    #             run_gemm_rs(m, n, k * 3, False, True, T.float16, T.float16, T.float16, m, n, k, 2, 128)
729
    #             print(f"Test {m} {n} {k} Pass")
730
731
732

    # for n in [16, 32, 64, 128]:
    #     for k in [16, 32, 64, 128]:
733
    #         run_gemm_rs(64, n, k, False, False, T.float16, T.float16, T.float16, 64, n, k, 0, 256)
734
735
736
737
    #         print(f"Test {64} {n} {k} Pass")

    # for n in [16, 32, 64, 128]:
    #     for k in [16, 32, 64, 128]:
738
    #         run_gemm(64, n, k, False, False, T.float16, T.float16, T.float16, 64, n, k, 0, 256)
739
    #         print(f"Test {64} {n} {k} Pass")