Huawei Ascend Backend Optimization Guide#

1. Hardware Architecture & Memory Hierarchy#

The Ascend AI Core features a heterogeneous compute pipeline: the Cube path executes matrix multiplications, the Vector path handles element-wise operations and reductions, and the Scalar path manages address calculations and loop control. Data moves from global memory (GM, typically HBM) into on-chip buffers via the Memory Transfer Engine (MTE). The Cube unit exclusively accesses L1, L0A, L0B, and L0C buffers; the Vector unit operates out of the Unified Buffer (UB).

UB and L0 are completely separate physical memory spaces; L1 is a Cube-dedicated on-chip buffer, NOT a cross-core shared L2 cache. Composite kernels combining tl.dot with a Vector epilogue typically require intermediate data transfers and cross-path synchronization.

The table below lists the on-chip buffer capacities (in KiB) from the Triton-Ascend / AscendNPU-IR specifications across representative architectures. GM/HBM capacity, bandwidth, and L2 cache sizes vary by hardware model and SKU:

Memory SpaceIR Identifier910B / 910_93910_95 / 950 SeriesPrimary Purpose & Alignment
GMgmDevice-specificDevice-specificGlobal memory, cached via L2
L1cbuf512 KiB512 KiBCube input buffer; plan for 32 B alignment
L0A / L0Bca / cb64 KiB each64 KiB eachMatrix A/B operand on-chip input buffers
L0Ccc128 KiB256 KiBMatrix accumulation output; transfers plan for 512 B alignment
UBub192 KiB248 KiB usable (256 KiB nominal, 8 KiB reserved)Vector workspace; plan for 32 B alignment
BT / FP Buffer—1 / 7 KiB1 / 7 KiBBias table / FixPipe intermediate buffer
  • Typical Cube Data Flow: GM → L1 → L0A/L0B → L0C → GM
  • Typical Vector Data Flow: GM → UB → GM

The 910_95/950 family further supports routing L0C accumulation results directly into UB via FixPipe and writing UB data back to L1; the corresponding mixed paths on 910B/910_93 chips generally route through global memory (GM).

1.1 Core Counts & Grid Mapping#

Ascend physical core counts are queried separately by compute unit type. Typical specifications:

  • 910B1 / 910B2: 24 Cube / 48 Vector
  • 910B3 / 910B4: 20 Cube / 40 Vector
  • 910_95 Series: Configured dynamically by SKU

Do NOT sum the Cube and Vector core counts to configure the launch grid of a single kernel.

FlagGems queries num_vectorcore from Triton device properties for Vector kernels, and num_aicore for matrix kernels:

import torch
import torch_npu  # Registers torch.npu
import triton.runtime.driver as driver

device_index = torch.npu.current_device()
props = driver.active.utils.get_device_properties(device_index)
vector_cores = props["num_vectorcore"]
cube_cores = props["num_aicore"]

In Triton-Ascend, launch grids use 1D, 2D, or 3D tuples. Under the default pipeline, coreDim = x * y * z must not exceed 65535 (otherwise a coreDim ... can't be greater than UINT16_MAX error is triggered).

When processing large tensor shapes, limit the grid to the physical core count and employ a grid-stride loop inside each program stepping by tl.num_programs(0):

import triton
import triton.language as tl


@triton.jit
def kernel(x, y, N, BLOCK_SIZE: tl.constexpr):
    for block in range(
        tl.program_id(0), tl.cdiv(N, BLOCK_SIZE), tl.num_programs(0)
    ):
        offsets = block * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
        values = tl.load(x + offsets, mask=offsets < N, other=0)
        tl.store(y + offsets, values, mask=offsets < N)


grid = (min(triton.cdiv(N, BLOCK_SIZE), vector_cores),)
kernel[grid](x, y, N, BLOCK_SIZE)

1.2 Tile Capacity & Memory Alignment#

  • UB Budgeting: If a single tile occupied the 910B's 192 KiB UB, its theoretical capacity would be 98,304 FP16/BF16 elements or 49,152 FP32 elements. However, in practice, simultaneously live inputs, outputs, temporaries, alignment padding, and multibuffering all consume space. If a ub overflow compilation error occurs (often reported in bits), reduce BLOCK_* or use an internal BLOCK_SIZE_SUB loop.
  • Cube Alignment: The Cube path requires careful attention to row-width and trailing-axis alignment. A 512 B row corresponds to 256 FP16/BF16 or 128 FP32 elements; unaligned dimensions may trigger compiler padding and redundant memory transfers.

1.3 910C and 950DT Hardware Specifications#

Core counts, frequencies, and memory configurations vary across SKUs. Always verify against device-specific configurations via platform_config/<SoC_version>.ini (or using acl.get_soc_name() / npu-smi) rather than inferring them from chip family names. The tables below summarize common SKU configurations found in CANN platform_config.

Ascend910C (A3 architecture, dual-die package, categorized under ascend910b_list in CANN, SIMD-only) includes six common Ascend910_93xx SKUs. All share ai_cpu_cnt=6 and l1_size=512 KiB, while HBM capacity and L2 cache scale with the Vector core count:

SoC VersionAI Core (Cube)Vector CoreCube ClockHBM CapacityL2 CacheUB / AI Core
Ascend910_936220401.5 GHz32 GiB168 MiB192 KiB
Ascend910_937220401.8 GHz64 GiB192 MiB192 KiB
Ascend910_938124481.8 GHz64 GiB192 MiB192 KiB
Ascend910_938224481.8 GHz64 GiB192 MiB192 KiB
Ascend910_939124481.85 GHz64 GiB192 MiB192 KiB
Ascend910_939224481.85 GHz64 GiB192 MiB192 KiB
  • Ascend910_9362 / _9372: 20 Cube cores; _9362 has a smaller 32 GiB HBM capacity.
  • Ascend910_9381 / _9382: 24 Cube cores at 1.8 GHz with identical configurations; _9382 is the most common SKU in production.
  • Ascend910_9391 / _9392: 24 Cube cores with an increased clock of 1.85 GHz.

Ascend950DT (A5 architecture, decode-oriented, sharing silicon with 950PR with up to 36 AI subsystems). In CANN 9.0.0/9.1.0, the Ascend950DT_9582 configuration (platform_config/Ascend950DT_9582.ini) reports:

ParameterValueDescription
cube_core_cnt / vector_core_cnt32 / 64Cube / Vector core count
l1_size512 KiBL1 cache size
l2_size128 MiBL2 cache size
ub_size248 KiB (253,952 B)Usable Unified Buffer size
cube_freq / vec_freq1.65 GHzCube / Vector operating frequency
memory_size96 GiBHBM capacity

Ascend950DT_9582 Theoretical Peak vs. Measured Performance#

Ascend950DT_9582 corresponds to the 32-Cube-core tier. The table below compares the theoretical peak performance against measured single-node throughput for Ascend950DT_9582 (measured using CANN 9.1.0 and torch_npu):

MetricTheoretical PeakMeasuredBenchmark / Notes
matmul (Cube+Vector BF16 / FP16)486 TFLOP/s430.4 TFLOP/storch.matmul, 8192³, median of 30 runs
matmul (Cube+Vector TF32)243 TFLOP/s27.0 TFLOP/sFP32 without HF32 path, 8192³
matmul (Cube+Vector FP8 / HiF8 / MXFP8)919 TFLOP/s——
matmul (Cube+Vector MXFP4)1784 TFLOP/s——
matmul (Cube+Vector INT8)919 TOPS——
Memory Bandwidth4 TB/s≈2.7–3.1 TB/s≥1024 MiB copy / triad / read (large buffers)
Memory Capacity96 GB96 GiBplatform_config/Ascend950DT_9582.ini (memory_size)
conv2d FP16—353–364 TFLOP/sF.conv2d, large 1x1 convolutions
conv2d FP32 (HF32 on / off)—176–183 / 26.9 TFLOP/storch.npu.conv.allow_hf32
  1. Data Source: Theoretical peaks are derived from the Ascend 950 NPU Architecture Whitepaper (p13, Table 3-1, 950DT 32-core configuration).
  2. Measurement Scope: Measured results depend on host environment, drivers, and software stack versions; they serve as empirical benchmarks rather than strict hardware ceilings.
  3. Bandwidth Profiling: Small buffer transfers (e.g., 64 MiB copy) can show inflated bandwidth (~1.8× higher) due to cache effects; large buffer transfers (≥1024 MiB) should be used to measure sustained memory bandwidth.
  4. Operator Differences: Different operators (e.g., conv2d vs. matmul) utilize hardware pipelines and execution units differently; their saturation throughputs should not be directly equated.

2. Triton Compiler & Launch Options#

FlagGems designates Ascend as an NPU backend (device_name="npu"), utilizing the installed Triton-Ascend / FlagTree extension. Options can be passed as keyword arguments to kernel[grid](...) or through a triton.Config:

OptionTargetTuning Recommendations
BLOCK_SIZE, BLOCK_M/N/KCompile-time tile sizes (tl.constexpr)Balance core occupancy, UB/L1 buffer budget, and masked tail overhead
num_warpsCompiler parallelization & layout choiceMeasure alongside tile sizes; SIMD semantics differ from GPU warp scheduling
num_stagesSoftware pipeline depthRegulates asynchronous prefetching; confirm with your installed compiler version
compile_modeCompiler path selection (simd / simt_only etc.)Default to simd; experiment with SIMT only for suitable workloads after verifying accuracy
multibufferOverlap data movement and computeTest on looped kernels after checking local buffer budgets; watch for doubled UB usage
enable_flattenLoop structure flatteningUseful for simple Vector kernels to eliminate branching overhead
enable_mixed_cv, sync_solverCube & Vector synchronizationEnable only for composite kernels that combine matrix multiplication and vector ops
enable_fp_fusionFloating-point operation fusionRe-verify numerical tolerances when toggling this option

The reference compiler defaults multibuffer to disabled for the 910_95/950 family. When exploring double buffering, pass multibuffer=True explicitly. Be aware that double buffering almost doubles live on-chip memory usage.

3. Common Performance Bottlenecks & Troubleshooting#

Performance IssueDiagnosis & Mitigation
High aiv_scalar_ratioCheck generated IR for scalar loops. On 910B, int64 vector math and integer comparisons may degrade to scalar mode; cast to int32 where values fit in range.
Mask load blocks compute overlapOnly test tl.load(..., care_padding=False) if padding data will never participate in reductions or unmasked stores; otherwise keep standard masked loads.
Non-contiguous strided accessRestructure tensor indices or tiling to enforce coalesced memory access. Avoid unnecessary .contiguous() copies which often erase kernel gains.
L2 cache thrashing on large matricesImplement grouped scheduling (Grouped Launch); avoid directly calling unsupported tl.swizzle2d on Ascend.
Low-precision accumulation overflowFor FP16/BF16 inputs, ensure reductions and matrix multiplication accumulate into FP32 accumulators to prevent numerical drift.
  1. Classify the Compute Path: Determine whether the kernel is purely Vector, purely Cube, or mixed; establish accuracy and latency baselines with representative shapes.
  2. Ensure Coalesced Access: Align strides and pointer offsets to maximize memory bandwidth utilization.
  3. Budget On-chip Memory: Fit tiles strictly within UB (192 KiB / 248 KiB) and L1 (512 KiB) physical limits to prevent register spills and UB overflows.
  4. Explore Overlap & Pipelining: For looped kernels, evaluate multibuffer=True and tune num_stages.
  5. Profile on Device: Use the Ascend Profiler to inspect Cube vs. Vector MTE utilization, validating that latency speedups pass strict numerical verification gates.

5. References#