بنقرة واحدة
triton-ascend-error-fix
triton-ascend 验证、编译或运行失败后的常见错误修复:UB/CBUF溢出、BiShengIR编译失败、语法限制违反、数值正确性、多维索引分解错误、张量连续性
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
triton-ascend 验证、编译或运行失败后的常见错误修复:UB/CBUF溢出、BiShengIR编译失败、语法限制违反、数值正确性、多维索引分解错误、张量连续性
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
AscendC direct-invoke 崩溃/挂起修复索引:Kernel timeout、hang、Segmentation Fault、aic error、buffer 死锁、plog/memcheck 调试。
AscendC direct-invoke 精度失败修复索引:输出全 0/随机值、DataCopy 对齐、EnQue/DeQue 同步、FP16/FP32 精度、Cast RoundMode、DumpTensor 分段定位。
AscendC direct-invoke 工程契约:WA 使用 kernel.py + ascendc_op/,ModelNew 调用 torch.ops.npu.*,adapter 负责复制工程、CMake 构建和 npu-arch patch。适用于 dsl=ascendc 的 autoresearch 任务。
把注册式 AscendC 算子迁移为 direct-invoke 工程的保真原则:kernel 算法和 tiling 公式不乱改,只替换注册框架胶水、入口 ABI、host launch 与 PyTorch extension。
CATLASS TileShape 与 on-chip 缓存容量约束:L1/L0A/L0B/L0C 预算公式、fp16/fp32 Pingpong 双缓冲、512B 对齐与排布对 Tile 选型的影响。调参前必读。
CATLASS Gemm 性能调优:DispatchPolicy、Tile 与分核负载均衡、Swizzle、何时用 padding/Split-K/Preload。面向 AR 修改 catlass_kernel.asc 中的类型别名。
| name | triton-ascend-error-fix |
| description | triton-ascend 验证、编译或运行失败后的常见错误修复:UB/CBUF溢出、BiShengIR编译失败、语法限制违反、数值正确性、多维索引分解错误、张量连续性 |
| category | fix |
| version | 1.0.0 |
| metadata | {"case_type":"fix","backend":"ascend","dsl":"triton_ascend","hardware":"Atlas A2, Atlas A3, Atlas A5"} |
cbuf overflow# 错误:分块过大导致 UB overflow
BLOCK_M, BLOCK_N, BLOCK_K = 128, 256, 256
# 修复:安全起始点
# CUBE (matmul fp16): BLOCK_M=64, BLOCK_N=64, BLOCK_K=32
# CUBE (matmul fp32): BLOCK_M=32, BLOCK_N=32, BLOCK_K=32
# VEC (elementwise): BLOCK_SIZE=1024~2048
BLOCK_M, BLOCK_N, BLOCK_K = 64, 64, 32
4D tensor 矩阵乘法中 batch 维度额外占用 UB 空间,建议将 batch 展开到 grid 维度而非内层循环。
hivm.hir.vsel: Unsupported op for finding the root alloc、Failed to run BiShengHIR pipeline# 错误
tl.store(c_ptr + off_m[:, None] * stride_cm + off_n[None, :] * stride_cn, acc, mask=mask)
# 修复:拆分为中间变量
c_ptrs = c_ptr + off_m[:, None] * stride_cm + off_n[None, :] * stride_cn
tl.store(c_ptrs, acc, mask=mask)
tl.where + 复杂 mask 导致 vsel 错误# 错误:嵌套 mask + tl.where 触发 hivm.hir.vsel 错误
a_tri_mask = a_offsets_k[None, :] >= a_offsets_m[:, None]
a_valid_mask = a_mask_m & a_mask_k
a = tl.where(a_tri_mask & a_valid_mask, a, 0.0)
# 修复:改用乘法替代 tl.where(将 bool mask 转为 float 后相乘)
a_tri_mask = (a_offsets_k[None, :] >= a_offsets_m[:, None]).to(tl.float16)
a_valid_mask = (a_mask_m).to(tl.float16) * (a_mask_k).to(tl.float16)
a = a * a_tri_mask * a_valid_mask
continue / break / return# 错误:unsupported AST node type: Continue
for i in range(N):
if condition:
continue
do_work()
# 修复:用 if-else 包裹
for i in range(N):
if not condition:
do_work()
# 错误:ValueError('unsupported tensor index: constexpr[0]')
result = tl.sum(data, axis=0)
tl.atomic_add(out_ptr, result[0])
# 修复:tl.sum 已返回标量,直接使用
result = tl.sum(data, axis=0)
tl.atomic_add(out_ptr, result)
# 错误:cast incompatible shapes
result = tl.dot(a_fp16, b_fp16)
# 修复:显式指定 fp32 累加器
result = tl.dot(a_fp16, b_fp16, acc=tl.zeros([M, N], dtype=tl.float32))
| 报错/现象 | 常见根因 | 修改方向 |
|---|---|---|
unsupported AST node type: Continue | continue / break / return | 改成 if-else 包裹有效分支 |
| while 相关编译失败 | Ascend 后端不支持动态 while | 改成静态上限 for + 循环体内 if |
unsupported tensor index | Python 切片或 reduction scalar [0] | 用 tl.extract_slice / 直接使用 scalar |
hivm.hir.vsel | tl.where 选择复杂 mask、指针或 offset | 拆分静态分支,或将 mask 转 dtype 后乘数据 |
cast incompatible | 隐式 dtype/shape 推导失败 | 显式 accumulator dtype 和 .to(dtype) |
AssertionError: 输出不一致, err_cnt=XXXX# 上三角: 确保 col >= row 的区域非零
row_idx = block_m * BLOCK_M + tl.arange(0, BLOCK_M)
col_idx = block_k * BLOCK_K + tl.arange(0, BLOCK_K)
tri_mask = col_idx[None, :] >= row_idx[:, None]
a = tl.load(a_ptr + ..., mask=tri_mask & bounds_mask, other=0.0)
# 正确的 batch 维度分解
pid = tl.program_id(0)
batch_idx = pid // num_blocks_per_batch
block_idx = pid % num_blocks_per_batch
b0 = batch_idx // dim1
b1 = batch_idx % dim1
# fp32 累加器避免 fp16 精度丢失
acc = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)
for k in range(0, K, BLOCK_K):
a = tl.load(...) # fp16
b = tl.load(...) # fp16
acc += tl.dot(a, b) # fp32 累加
result = acc.to(tl.float16)
# 易错:复杂的一维展平映射
total_tasks = N * G
for task_idx in range(pid, total_tasks, CORE_NUM):
n_idx = task_idx // G
g_idx = task_idx % G
c_local = offsets // S # 含义不清晰,容易写错
hw = offsets - c_local * S
# 推荐:显式的多层嵌套 + 清晰的局部索引
for n in range(pid, N, CORE_NUM):
for g_idx in range(num_groups):
for i in range(0, group_elems, BLOCK_SIZE):
local_idx = i + tl.arange(0, BLOCK_SIZE)
c_local = local_idx // hw_size
spatial_idx = local_idx % hw_size
在 kernel wrapper 入口处强制 .contiguous():
if not x.is_contiguous():
x = x.contiguous()