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

Function gemv_simt

testing/python/kernel/test_tilelang_kernel_gemv_simt.py:14–112  ·  view source on GitHub ↗
(
    M: int,
    N: int,
    K: int,
    in_dtype: str,
    out_dtype: str,
    accum_dtype: str,
    trans_A: bool,
    trans_B: bool,
    with_bias: bool = False,
    n_partition: Optional[int] = 4,
    reduce_thread: Optional[int] = 32,
)

Source from the content-addressed store, hash-verified

12
13
14def gemv_simt(
15 M: int,
16 N: int,
17 K: int,
18 in_dtype: str,
19 out_dtype: str,
20 accum_dtype: str,
21 trans_A: bool,
22 trans_B: bool,
23 with_bias: bool = False,
24 n_partition: Optional[int] = 4,
25 reduce_thread: Optional[int] = 32,
26):
27 assert n_partition is not None, "n_partition must be provided"
28 assert reduce_thread is not None, (
29 "reduce_thread must be provided currently, as related bitblas.gpu.gemv.GEMVsch_outer_reduction_with_config is not implemented"
30 )
31
32 assert isinstance(N, int) and isinstance(K, int), "Do not support dynamic N and K Currently"
33
34 assert trans_A is False, "Dequantize only implement for trans_A=False currently"
35 assert trans_B is True, "Dequantize only implement for trans_B=TRue currently"
36
37 MAX_TRANSACTION_SIZE_IN_BITS = 128
38 micro_size_k = MAX_TRANSACTION_SIZE_IN_BITS // DataType(in_dtype).bits
39
40 block_K = reduce_thread * micro_size_k
41
42 A_shape = (M, K)
43 B_shape = (N, K)
44 Bias_shape = (N,)
45 C_shape = (M, N)
46
47 dp4a_size = 4
48 use_dp4a = in_dtype == T.int8 and accum_dtype == T.int32
49
50 @T.prim_func
51 def main(
52 A: T.Tensor(A_shape, in_dtype),
53 B: T.Tensor(B_shape, in_dtype),
54 Bias: T.Tensor(Bias_shape, out_dtype),
55 C: T.Tensor(C_shape, out_dtype),
56 ):
57 with T.Kernel(T.ceildiv(N, n_partition), M, threads=(reduce_thread, n_partition)) as (
58 bx,
59 by,
60 ):
61 A_local = T.alloc_local((micro_size_k,), in_dtype)
62 B_local = T.alloc_local((micro_size_k,), in_dtype)
63 accum_res = T.alloc_local((1,), accum_dtype)
64 reduced_accum_res = T.alloc_local((1,), accum_dtype)
65
66 kr = T.get_thread_binding(0)
67 ni = T.get_thread_binding(1)
68
69 T.clear(accum_res)
70 for ko in T.serial(T.ceildiv(K, block_K)):
71 for v in T.vectorized(micro_size_k):

Callers 1

evaluate_gemv_simtFunction · 0.85

Calls 1

apply_simplifyFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…