ascendc-ub-budget

Calculates AscendC Unified Buffer byte budgets to prevent UB out-of-bounds kernel failures.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? AscendC kernels compile successfully but crash at runtime with UB out-of-bounds errors (errno 507035) when the total bytes requested via InitBuffer exceed the physical Unified Buffer capacity. This Skill teaches you to compute the UB byte ledger before writing code, so BUFFER_NUM, TILE_LENGTH, and calcBuf combinations are chosen within hardware limits. ## Core Features & Use Cases - Per-device UB capacity reference: Documents UB sizes for 910B (192 KB), 910B3 (192 KB), 910B4 (128 KB), and 310B/310P, plus L0A/L0B/L0C/L1 budgets for Cube+Vector fused kernels. - Byte ledger formulas: Provides exact accounting for TQue (bytes × BUFFER_NUM), TBuf, calcBuf slicing, and compiler scratch headroom, with an 80%-of-UB safety rule. - Safe configuration tables and diagnostics: Lists recommended BUFFER_NUM/TILE_LENGTH combinations per operator pattern and a step-by-step diagnostic path for UB OOB crashes. - Use Case: You want to raise BUFFER_NUM from 2 to 3 on an fp16 elementwise kernel with TILE_LENGTH=8192 and three fp32 scratch buffers. The ledger shows 192 KB total usage, leaving no headroom on 910B3, so you instead compress scratch live ranges to reuse buffers before increasing queue depth. ## Quick Start Ask the assistant to check whether my AscendC kernel's InitBuffer configuration with BUFFER_NUM, TILE_LENGTH, and calcBuf sizes fits within the UB budget of my target Ascend device.

Frequently Asked Questions about ascendc-ub-budget

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

FAQPage Schema
How do I calculate UB usage for an AscendC kernel?▼

Sum every InitBuffer allocation: TQue buffers cost bytes-per-buffer times BUFFER_NUM, TBuf costs its byte size once, plus 2-4 KB compiler scratch. Keep the total under 80% of the device's physical UB, which is 192 KB on 910B/910B3 and 128 KB on 910B4.

What BUFFER_NUM and TILE_LENGTH combinations are safe on Ascend 910B3?▼

For fp32 elementwise kernels use BUFFER_NUM=2 with TILE_LENGTH up to 8192; fp16/bf16 allows up to 16384. Reduce-broadcast kernels like softmax should stay at TILE_LENGTH 4096 with one or two buffers to preserve headroom.

Why does my AscendC kernel fail with errno 507035 vector core exception?▼

Errno 507035 with a UB address out-of-bounds message means total InitBuffer allocations exceeded physical UB, or a runtime-offset subview escaped its buffer. Recompute the byte ledger, check subview offsets, and bisect compute code to locate the failing intrinsic.

Does raising BUFFER_NUM always improve AscendC kernel performance?▼

No. BUFFER_NUM multiplies UB consumption, and gains beyond 2 are marginal unless DMA dominates compute. Profile whether MTE2 and vector compute actually overlap before increasing queue depth, and consider compressing calcBuf live ranges first.

Can I allocate UB memory dynamically at runtime in AscendC?▼

No. UB is statically allocated through InitBuffer at kernel setup; calling aclrtMalloc inside a kernel breaks pipe synchronization scheduling. Design buffer layouts with compile-time constant offsets instead.