Provides AscendC SIMT best practices and API navigation for SIMT operator kernel development. Covers VF function declaration/calling, thread layout patterns, index calculation APIs, data transfer, compute instruction mapping, multi-core sync, shared memory, TensorList, debug interfaces, built-in macros, and compilation.
Ships in ops-direct-invoke-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
本 skill 提供基于实际算子开发经验提炼的 SIMT 编程范式总结,以及 SIMT 专有 API 的分类索引和速查。SIMT 基础概念(核函数、线程架构、内存层级)请通过
ascendc-docs-searchskill 查阅$ASC_DEVKIT_DIR/docs/zh/guide/programming_guide/programming_model/ai_core_simt_programming/。
| 类别 | $ASC_DEVKIT_DIR 目录 | 功能概述 | 头文件 |
|---|---|---|---|
| 总览与核函数 | SIMT-API/overview.md | VF启动机制、头文件、混合编程辅助函数 | common_functions.h |
| 同步与内存栅栏 | SIMT-API/sync_and_memory_fence/ | asc_syncthreads/asc_threadfence/asc_threadfence_block | device_sync_functions.h |
| 数学函数 | SIMT-API/math_functions/ | 三角/指数/对数/幂/误差/特殊/基础算术/整数工具 | math_functions.h |
| 原子操作 | SIMT-API/atomic_operations/ | add/sub/exch/max/min/inc/dec/cas/and/or/xor | device_atomic_functions.h |
| Warp函数 | SIMT-API/Warp_functions/ | all/any/ballot/activemask/shfl/shfl_up/down/xor/reduce | device_warp_functions.h |
| 地址空间谓词 | SIMT-API/address_space_predicate_functions/ | __isGlobal/__isShared/__isConstant/__isLocal | asc_simt.h |
| 地址空间转换 | SIMT-API/address_space_conversion_functions/ | __cast_to_xxx 地址空间转换 | asc_simt.h |
| 访存函数 | SIMT-API/memory_access_functions/ | asc_ldcg/asc_ldca/asc_stcg/asc_stwt | device_functions.h |
| 协作组 | SIMT-API/cooperative_groups/ | 协作组编程模型 | asc_simt.h |
| SIMT编程简介 | SIMT-API/SIMT_programming_intro/ | SIMT编程概念和入门 | asc_simt.h |
| 混合编程简介 | SIMT-API/SIMD_SIMT_hybrid_programming_intro/ | SIMD/SIMT混合编程指导 | asc_simt.h |
查阅完整 API 文档:使用
ascendc-docs-searchskill 查阅 SIMT API 官方文档(find "$ASC_DEVKIT_DIR/docs/zh/api/SIMT-API/" -name "{APIName}*.md")。
| 编程阶段 | 核心主题 | 参考文档 | 关键要点 |
|---|---|---|---|
| 函数定义 | VF 函数声明 | vf-declaration.md | __simt_vf__ 标记、LAUNCH_BOUND、参数类型、三层结构 |
| 函数调用 | VF_CALL 启动 | vf-call.md | Dim3 线程数、Add 完整示例、参数传递 3 方式、GM_ADDR 直接转换 |
| 线程排布 | 两种排布模式 | thread-stride-pattern.md | 模式一全局 grid-stride、模式二核内分块+线程步进、索引分解、3 种线程↔数据映射粒度(含每 warp 一输出/warp 协作) |
| 索引计算 | API 与全局索引 | index-calculation.md | GetThreadIdx/GetBlockIdx 系列、全局索引与 stride、magic 快除与官方 magic/shift 公式、索引位宽 32/64 自适应 |
| 数据搬运 | GM 直接 / UB 中转 | data-transfer.md | 选型决策流、GM 直读/UB 中转/缓存复用;首要判据是访存粒度而非是否逐元素:连续 / 规则访问可直接 GM 直读(硬件合并),GM 经 Data Cache 以 128B 扇区为最小传输单位,读放大 = 128B/单元素字节(int8 128x、fp16/bf16 64x、int32 32x、int64 16x);单次随机访问连续字节 e≥128B 可直读、e<128B 读放大 128/e,不应默认逐元素 GM 直读;调线程数/迭代序/缓存提示不能改变放大倍数 |
| 随机访存 | 写侧(散写)策略 | random-access-patterns.md | 同址写冲突(数据竞争,无原子时可能丢更新);写侧首要目标是减少同址写次数而非优化单次写;按 dtype 原子能力 + 确定性需求 选原子直写 / workspace 升位宽三段式(目标 dtype 无原子指令或低精度:cast→宽类型原子→cast 回) / 排序归并单写(需确定性或重复度高时,每唯一目标只写一次) / 按目标分区(按核/槽位切分且无跨核同址);重复度高时不应裸用原子直写——原子在目标地址排队,重复度越高串行化越重;可用分层归约(线程块私有 UB 局部归约 → 整块汇总 GM)进一步降竞争 |
| 计算指令 | C++ 运算符映射 | compute-operators.md | 优先运算符写法、显式 API 仅特殊需求 |
| 多核同步 | workspace + SyncAll | multi-core-sync.md | 多核 workspace 交换、VF 间同步、同步原语全景、event 依赖链、SetScheduleMode(1) |
| 核内共享 | UB buffer 共享 | intra-core-shared.md | TBuf VECCALC、ubuf/local_mem 指针、线程间竞争与原子、UB 使用约束 |
| 动态输入 | TensorList 解析 | tensorlist-handling.md | ListTensorDesc 布局、Host 侧获取、Device 侧两种解析方式、选型建议 |
// 1. VF 声明
template <typename T>
__simt_vf__ __aicore__ LAUNCH_BOUND(512) inline void OpSimt(
uint64_t count, __gm__ T* x, __gm__ T* y);
// 2. VF 调用
AscendC::Simt::VF_CALL<OpSimt<T>>(AscendC::Simt::Dim3(512), count, (__gm__ T*)x, (__gm__ T*)y);
// 3. 线程排布 for 循环
for (uint64_t i = AscendC::Simt::GetBlockIdx() * AscendC::Simt::GetThreadNum() + AscendC::Simt::GetThreadIdx();
i < count; i += AscendC::Simt::GetThreadNum() * AscendC::Simt::GetBlockNum()) { ... }
| 维度 | SIMT | SIMD |
|---|---|---|
| 编程模型 | 多线程并行,每线程独立执行 | 单核向量指令,整块数据并行 |
| 函数标记 | __simt_vf__ | 无特殊标记 |
| 启动方式 | Simt::VF_CALL<VF>(Dim3(N), args) | 直接在 kernel 内调用 |
| 线程索引 | GetThreadIdx / GetBlockIdx | 无线程概念,靠 tile 循环 |
| 数据访问 | GM 直接读写(__gm__ T*) | DataCopyPad 搬到 UB/L0C |
| 计算方式 | C++ 运算符(y[i]=x[i]+1) | 向量 API(Add(xLocal, yLocal, zLocal)) |
| 核内共享 | UB buffer + __ubuf__ 指针 | TQue 流水线 queue |
| 多核同步 | SyncAll() + SetScheduleMode(1) | 流水线 set/wait flag |
| 适用场景 | 离散 / 不规则访存、数据依赖的逐元素迭代(循环轮数依赖元素自身值:GCD 收敛循环 / 位扫描 ctz·ffs 等——SIMD 无法提前确定向量指令循环轮数) | 规则向量、高吞吐归约(含单次数据依赖 Select / 掩码) |
实现载体选型时按以下两个维度逐条评估,命中任一维度且目标芯片支持 SIMT(DAV_3510)时,建议推荐 SIMT:
SIMT 适用场景:
单次的数据依赖分支 / 选择(
?:、除零特判Select等)SIMD 掩码即可表达,不构成命中;访存是否规则(连续 / 离散)本身也不构成排除 SIMT 的理由。
references/ 按需加载:
编程最佳实践:
__simt_vf__ 标记、__simt_callee__→__simt_vf__→__aicore__ 三层结构、参数类型支持表、LAUNCH_BOUND 编译期常量约束(线程数分档见 tiling-design)__ubuf__/__local_mem__ 指针传递与等价性、按索引写 UB 示例、线程间竞争与原子 dtype 注意事项API 导航与速查:
<<<...>>> 内核调用符完整 API 文档:
ascendc-docs-search skill 查阅 SIMT API 文档evals/evals.json (opens in a new tab)references/compute-operators.md (opens in a new tab)references/data-transfer.md (opens in a new tab)references/debug-api.md (opens in a new tab)references/index-calculation.md (opens in a new tab)references/intra-core-shared.md (opens in a new tab)references/macro-api.md (opens in a new tab)references/multi-core-sync.md (opens in a new tab)references/overview.md (opens in a new tab)references/random-access-patterns.md (opens in a new tab)references/tensorlist-handling.md (opens in a new tab)references/thread-stride-pattern.md (opens in a new tab)references/vf-call.md (opens in a new tab)references/vf-declaration.md (opens in a new tab)references/编译与运行.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ascendc, simt, operator-development, ai-core, kernel-programming
/ops-direct-invoke-skills:ascendc-simt-best-practicesfrom ops-direct-invoke-skills
npx claudepluginhub hicann/cannbot-skills --plugin ops-direct-invoke-skills25 skills in this plugin
/ascendc-api-best-practicesAscend C API 使用最佳实践。提供算术、归约、数据搬运、Buffer管理、精度转换、通信接口等 API 的正确用法和限制说明。触发:用户询问具体 API 用法(如"DataCopy 怎么用"、"ReadNbi 怎么用")、遇到 API 参数错误或限制报错(如 repeatTimes、对齐问题)、需要查看 API 最佳实践或避坑指南、算子性能疑似受标量访问/单元素读写影响时。/ascendc-blaze-best-practice在 Ascend 950 / DAV_3510 平台上,基于 Blaze/tensor_api 开发 Basic、Batch、Grouped、Quantized、MX 等 MatMul 类算子或相关的融合算子时使用。不适用于纯 Vector 算子或 A2/A3 平台。/ascendc-blaze-migration评估并将 ops-nn、ops-transformer 等仓中 Ascend 950 / DAV_3510 的 AscendC Kernel 分支等价迁移到 ops-tensor Blaze/Tensor API。适用于 CMCT、CGMCT、单体或自定义分层 Kernel,以及 Cube、Vector、MIX、高阶 Matmul、手工 Buffer、数据搬运、自定义调度、VF 和同步路径;在隔离迁移工程中串行完成迁移合同冻结、Blaze 开发、验证资产生成、原始基线、Blaze 验收和双仓本地提交交付。Other plugins' skills for the same job