Tensara Logo

tensara

All Problems

NVFP4 GEMV

HARD

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

yi==0K1Adequant,ixdequant,.y_i = \sum_{\ell=0}^{K-1} A_{\mathrm{dequant},i\ell} \, x_{\mathrm{dequant},\ell}.

This is equivalent to y=Adequantxdequanty = A_{\mathrm{dequant}} x_{\mathrm{dequant}} with:

  • AdequantRM×KA_{\mathrm{dequant}} \in \mathbb{R}^{M \times K}
  • xdequantRKx_{\mathrm{dequant}} \in \mathbb{R}^{K}
  • yRMy \in \mathbb{R}^{M}

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
  • sf_g_asf\_g\_a: global NVFP4 encode factor for AA
  • qxq_x: packed NVFP4 E2M1 payload bytes for vector xx, represented as logical shape 1×K1 \times K
  • scalexscale_x: NVFP4 per-block FP8 scale bytes for xx, logical shape 1×K/161 \times K/16
  • sf_g_xsf\_g\_x: global NVFP4 encode factor for xx
  • MM, KK: dimensions (KK divisible by 16)

Output

  • yy: FP16 vector of shape MM

Notes

  • The reference implementation dequantizes NVFP4 inputs with FlashInfer decode semantics, then computes GEMV as matmul in FP32 before casting to FP16 output.
  • scale_ascale\_a and scale_xscale\_x are already in NVFP4 swizzled scale layout expected by the decode path, do not apply an additional swizzle.

Test Case Sizes

  • 1024 x 1024
  • 2048 x 2048
  • 4096 x 4096
  • 8192 x 4096
  • 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.