Tensara Logo

tensara

All Problems

NVFP4 GEMM

HARD

Compute matrix multiplication where both matrix AA and matrix BB are stored in NVFP4 format. The equation below defines conceptual dequantization semantics for correctness:

cij==0K1Adequant,iBdequant,j.c_{ij} = \sum_{\ell=0}^{K-1} A_{\mathrm{dequant},i\ell} \, B_{\mathrm{dequant},j\ell}.

Note: BB is stored in row-major as N×KN \times K (i.e. BdequantB_{\mathrm{dequant}} is N×KN \times K), so the multiplication is effectively

C=AdequantBdequantT.C = A_{\mathrm{dequant}} \, B_{\mathrm{dequant}}^T.

Input

  • qaq_a: packed NVFP4 E2M1 payload bytes for matrix AA of logical shape M×KM \times K
  • scaleascale_a: NVFP4 per-block FP8 scale bytes for AA, logical shape M×K/16M \times K/16
  • qbq_b: packed NVFP4 E2M1 payload bytes for matrix BB of logical shape N×KN \times K
  • scalebscale_b: NVFP4 per-block FP8 scale bytes for BB, logical shape N×K/16N \times K/16
  • MM, NN, KK: matrix dimensions (KK divisible by 16)
  • sf_g_asf\_g\_a: global NVFP4 scale factor for AA
  • sf_g_bsf\_g\_b: global NVFP4 encode factor for BB

Output

  • cc: FP16 matrix of shape M×NM \times N, with c=AdequantBdequantTc = A_{\mathrm{dequant}}B_{\mathrm{dequant}}^T

Notes

  • The reference implementation in this problem calls torch.nn.functional.scaled_mm and does not materialize AdequantA_{\mathrm{dequant}} or BdequantB_{\mathrm{dequant}}.
  • The scale_a and scale_b inputs are already in swizzled 32×4×432 \times 4 \times 4 layout; do not apply an additional swizzle.

Test Case Sizes

  • 1024 x 1024 x 1024
  • 2048 x 1024 x 2048
  • 4096 x 2048 x 4096
  • 4096 x 4096 x 4096
  • 8192 x 4096 x 8192
Console

Sample Run Results

Hit "Run" to test your code with sample inputs

Loading...

Loading editor...

CUDA C++ environment

Desktop Required for Code Submission

For the best coding experience, please switch to a desktop device to write and submit your solution.