用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mindspore-ai/akg --skill triton-ascend-memory命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | triton-ascend-memory |
| description | Ascend NPU 内存访问优化策略,包括 UB(统一缓冲区)利用、数据布局优化、合并访存和预取技巧。适用于内存带宽受限、需要优化数据搬运效率、或处理大规模数据的内核代码性能优化场景 |
| category | fundamental |
| version | 1.0.0 |
| metadata | {"backend":"ascend","dsl":"triton_ascend","hardware":"Atlas A2, Atlas A3"} |
块大小需要根据算子类型和硬件存储层级来平衡:
BLOCK_SIZE * sizeof(dtype) 需小于 UB 可用容量,同时兼顾计算并行度。过小并行度不足,过大溢出 UBm0 * k0 * sizeof(A.dtype) ≤ * KB(L0A)k0 * n0 * sizeof(B.dtype) ≤ * KB(L0B)m0 * n0 * sizeof(C.dtype) ≤ * KB(L0C)A_block_ptr = tl.make_block_ptr(
base=A_ptr, shape=(M, K), strides=(stride_am, stride_ak),
offsets=(pid_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_K), order=(1, 0),
)
a = tl.load(A_block_ptr, boundary_check=(0, 1))
# 移动指针
A_block_ptr = tl.advance(A_block_ptr, (0, BLOCK_K))
非连续张量先 .contiguous() 转换,再用一维 ptr + offsets 访问:
class ModelNew(torch.nn.Module):
def forward(self, x):
if not x.is_contiguous():
x = x.contiguous()
out = torch.empty_like(x)
n = x.numel()
grid = (triton.cdiv(n, BLOCK_SIZE),)
kernel[grid](x, out, n, BLOCK_SIZE=1024)
return out
一维访问比 stride 计算效率更高,推荐优先使用。
.contiguous() + 一维访问