MCPcopy Create free account
hub / github.com/OpenGVLab/EfficientQAT / dequant_kernel_dim0

Function dequant_kernel_dim0

quantize/triton_utils/kernels.py:83–123  ·  view source on GitHub ↗

dequant the quantized tensor to fp tensor B is of shape (M/(32//bits), N) int32 C is of shape (M, N) float16

(
    b_ptr, c_ptr,
    M, N,
    bits, maxq,
    stride_bk, stride_bn,
    stride_cm, stride_cn,
    BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr
)

Source from the content-addressed store, hash-verified

81)
82@triton.jit
83def dequant_kernel_dim0(
84 b_ptr, c_ptr,
85 M, N,
86 bits, maxq,
87 stride_bk, stride_bn,
88 stride_cm, stride_cn,
89 BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr
90):
91 """
92 dequant the quantized tensor to fp tensor
93 B is of shape (M/(32//bits), N) int32
94 C is of shape (M, N) float16
95 """
96
97 bits_per_feature = 32 // bits
98
99 pid = tl.program_id(axis=0)
100 num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)
101 num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)
102
103 pid_m = pid // num_pid_n
104 pid_n = pid % num_pid_n
105
106 offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)
107 offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)
108
109
110 b_ptrs = b_ptr + ((offs_am[:, None] // bits_per_feature) * stride_bk + offs_bn[None, :] * stride_bn)
111
112 shifter = (offs_am[:, None] % bits_per_feature) * bits
113
114
115
116 b = tl.load(b_ptrs)
117 b = (b >> shifter) & maxq
118
119 c = b
120
121 c_ptrs = c_ptr + stride_cm * offs_am[:, None] + stride_cn * offs_bn[None, :]
122 c_mask = (offs_am[:, None] < M) & (offs_bn[None, :] < N)
123 tl.store(c_ptrs, c, mask=c_mask)
124
125@custom_autotune.autotune(
126 configs=[

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected