triton-ascend-kahan-precision-fix

Fixes large-K reduction precision errors in Triton-Ascend kernels using Kahan compensated summation.

6|1|Updated Apr 19, 2026
One-click install
npx skills add https://github.com/xchang1121/op-autoresearch --skill triton-ascend-kahan-precision-fix-xchang1121
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: triton-ascend-kahan-precision-fix
Source: https://github.com/xchang1121/op-autoresearch/tree/main/skills/triton-ascend/evolved-fix/triton-ascend-kahan-precision-fix
Command: npx skills add https://github.com/xchang1121/op-autoresearch --skill triton-ascend-kahan-precision-fix-xchang1121

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Triton-Ascend matmul and reduction kernels with large K dimensions (K ≥ 4096) fail verification because simple FP32 accumulation loses low-order bits, causing divergence between the NPU Cube engine path and the Triton sequential accumulation path. ## Core Features & Use Cases - Kahan Compensated Summation: Replaces naive accumulation with a compensation variable that tracks and recovers rounding error, reducing error from O(K × eps) to O(eps). - Trigger Diagnosis: Identifies the failure signature (hard_fail > 0 with mare > 1e-2 but mere < 1e-4) that indicates accumulation error rather than logic bugs. - Use Case: A matmul kernel on Atlas A2 hardware fails verification at K = 8192 with a few extreme error points; applying the Kahan pattern to the accumulation loop brings NPU-vs-NPU results into agreement. ## Quick Start Apply the Kahan compensated summation pattern to my Triton-Ascend matmul kernel that fails verification at large K dimensions.

Frequently Asked Questions about triton-ascend-kahan-precision-fix

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix precision errors in Triton matmul kernels with large K?▼

Replace simple accumulation with Kahan compensated summation: maintain a compensation variable that captures the low-order bits lost in each addition and adds them back in the next iteration. This reduces accumulation error from O(K × eps) to O(eps).

What is Kahan compensated summation and how does it work?▼

Kahan summation is an algorithm that tracks rounding error in floating-point accumulation using a compensation variable. Each iteration computes y = partial - comp, t = acc + y, then comp = (t - acc) - y, recovering the precision lost when adding a small value to a large accumulator.

Why does my Ascend NPU kernel fail verification only at large K dimensions?▼

Floating-point addition is not associative, so error grows with the number of accumulation steps. At K ≥ 4096, simple FP32 accumulation loses enough low-order bits that the Triton sequential path diverges from the NPU Cube engine path, producing hard_fail results.

When should I not use Kahan summation in a kernel?▼

Skip Kahan for matmul with K < 4096, where simple accumulation is accurate enough, and for elementwise kernels with no reduction, where no accumulation error exists. The extra operations add overhead without benefit in these cases.

Does Kahan summation fix all NPU verification failures?▼

No. Kahan only addresses accumulation rounding error. If hard_fail persists between NPU runs after applying Kahan, the kernel likely has a logic bug rather than a precision issue and needs functional debugging.