← All problems
#32 INT8 Quantized Matmul Medium

Implement a quantized matrix multiplication program for 8-bit signed integer matrices. Given two input matrices A of dimensions \(M \times K\) and B of dimensions \(K \times N\), quantization scales scale_A, scale_B, output scale scale_C, zero-points zero_point_A, zero_point_B, zero_point_C, compute: \[ C_{\text{quant}}(i, j) = \mathrm{clamp}\left( \mathrm{round}\left( \frac{ \sum_{k=0}^{K-1} (A_{ik} - z_A)(B_{kj} - z_B) \cdot s_A s_B }{s_C} \right) + z_C,\ -128,\ 127 \right) \] where s_A = scale_A, z_A = zero_point_A, etc.

Implementation Requirements

Example 1:

     Input:
     A = [[1, 2],
          [3, 4]]
     B = [[5, 6],
          [7, 8]]
     M = 2, N = 2, K = 2
     scale_A = 0.1, scale_B = 0.2, scale_C = 0.05
     zero_point_A = 0, zero_point_B = 0, zero_point_C = 0

     Output:
     C = [[19, 22],
          [43, 50]]
     

Example 2:

     Input:
     A = [[1, 2]]
     B = [[3],
          [4]]
     M = 1, N = 1, K = 2
     scale_A = 1.0, scale_B = 1.0, scale_C = 1.0
     zero_point_A = 1, zero_point_B = 3, zero_point_C = 5

     Output:
     C = [[6]]
     

Constraints

Guided walkthrough coming soon. Below is the official starter signature in each language; the clickable line-by-line explanation hasn't been authored yet.
Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.