Write int8 quantized kernel

From tensormux/kernel-skills · View interactive version

Write int8 quantized kernel is an AI agent skill from the GitHub repository tensormux/kernel-skills. Guide the agent through designing and implementing an INT8 quantized matrix multiplication or linear layer kernel for inference, covering quantization scheme selection, scale computation, int32 accumu

How to use this skill

Skill file

Skill: Write an INT8 Quantized Kernel

Purpose

Guide the agent through designing and implementing an INT8 quantized matrix multiplication or linear layer kernel for inference, covering quantization scheme selection, scale computation, int32 accumulation, dequantization epilogue, and the decision between custom code and library solutions.

Use this when

Do not use this when

Inputs the agent should gather first

Required reasoning process

  1. Choose the quantization scheme and verify it is implemented correctly. Clarify the formula:
  1. Understand the INT32 accumulation math. For a dot product of length K with INT8 inputs and INT32 accumulation:
  1. Decide between dp4a (custom CUDA), CUTLASS, or cuBLAS.
  1. Design the dequantization epilogue. After INT32 accumulation, convert to the output dtype:
  1. Design the kernel structure. For a custom dp4a GEMM:
  1. Handle the quantization boundary. K must be a multiple of 4 for dp4a. If K is not a multiple of 4, pad the input to the next multiple of 4 or use scalar fallback for the remaining elements.
  1. Verify accuracy. Compare INT8 kernel output to fp32 reference using mean absolute error (MAE) and max absolute error as fractions of the quantization scale. For well-calibrated symmetric per-channel quantization, the max error should be bounded by roughly 0.5 * (scale / 127) per element.

Kernel design rules

Correctness requirements

Performance requirements

Output format

The agent should produce:

  1. Quantization scheme specification: explicit formulas for quantization (forward and inverse), granularity, zero-point handling, and scale dtype, written in mathematical notation before any code.
  2. Scale computation code: the offline or online code that computes scales from fp32 input tensors.
  3. INT8 GEMM kernel: complete, compilable kernel code using dp4a or CUTLASS, with the dequantization epilogue.
  4. Dequantization epilogue code: the scale application logic, labeled with which scale vector corresponds to which dimension.
  5. Accuracy test: compare INT8 kernel output to fp32 reference, reporting MAE and max absolute error.
  6. Library alternative assessment: explicit statement of whether cuBLAS or CUTLASS was considered and why a custom kernel was or was not chosen.

Common failure modes

Review checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.