ascendc-api-best-practices

Provides correct usage patterns and constraints for Ascend C kernel development APIs.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill ascendc-api-best-practices-wangwindow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ascendc-api-best-practices
Source: https://github.com/WangWindow/CANN-BatchMatMulMaxsum/tree/main/.agents/skills/ascendc-api-best-practices
Command: npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill ascendc-api-best-practices-wangwindow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Ascend C kernel developers frequently hit API misuse issues such as alignment violations, repeatTimes overflow, precision loss in half-precision arithmetic, and cross-core synchronization races. This Skill supplies verified usage patterns, parameter constraints, and platform-specific differences for the Ascend C API surface so kernels are written correctly the first time. ## Core Features & Use Cases - API Category Index: Covers arithmetic (Add/Sub/Mul/Div), reductions (ReduceMax/ReduceSum), data movement (DataCopy/DataCopyPad), Cube Matmul/GMM high-level APIs, buffer management (TBuf/TQue), precision casting, pipeline synchronization, cross-core flags, Hcomm point-to-point communication, HCCL host APIs, and DMA atomic operations. - Scenario-Based Guidance: Maps common operator scenarios (Softmax, LayerNorm, MatMul, GroupedMatmul, RoPE splitting, non-aligned data, mixed precision) to the right API patterns and pitfalls. - API Blacklist and Restrictions: Documents banned APIs (GlobalTensor::SetValue/GetValue in production), restricted APIs (DataCopy requiring strict 32-byte alignment), and platform-specific limits (DAV_2201 vs DAV_3510). - Use Case: When implementing a fused BatchMatmul + ReduceMax + ReduceSum operator on Ascend NPU, consult the Matmul, reduce, and cross-core sync references to coordinate Cube and Vector pipelines correctly. ## Quick Start Ask how to correctly use a specific Ascend C API such as DataCopyPad or ReduceMax, including its alignment constraints and platform limitations.

Frequently Asked Questions about ascendc-api-best-practices

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

FAQPage Schema
How do I use DataCopyPad for non-aligned data in Ascend C?

Use DataCopyPad with DataCopyExtParams and DataCopyPadExtParams for any copy where alignment is uncertain. It handles non-32-byte-aligned lengths automatically, while plain DataCopy requires strict 32-byte alignment and produces wrong data otherwise.

How do I enable double buffering with TQue in Ascend C?

Call InitBuffer with num=2 on a TQue<VECIN> or TQue<VECOUT> queue; the template depth parameter stays at 1. Double buffering overlaps MTE2/MTE3 data transfers with Vector computation in a single CopyIn-Compute-CopyOut loop.

Does the Ascend C Matmul high-level API work on all NPU platforms?

The MatmulImpl and GMM high-level APIs documented here target Atlas A2/A3 series (DAV_2201) only. Ascend 950 (DAV_3510) uses a different implementation path, so these patterns must not be applied there directly.

Why does my FP16 Add or Sub lose precision in Ascend C kernels?

Half-precision addition drops the smaller operand when magnitudes differ by roughly 2^10 (FP16) or 2^7 (BF16). Unless inputs are known to be same-magnitude, cast to FP32, perform the Add or Sub in-place, then cast back.

What is the repeatTimes limit for Ascend C vector APIs?

The repeatTimes parameter is limited to 255 per call. Larger workloads must be split into batches, for example processing rows in groups of 64 with BinaryRepeatParams broadcast patterns.

Why is GlobalTensor SetValue or GetValue forbidden in production Ascend C code?

SetValue and GetValue move single elements at extremely low efficiency and are blacklisted for production use. Replace them with DataCopyPad bulk transfers; they remain acceptable only for single-point debug printf verification.