基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mindspore-ai/akg --skill pypto-case-reduction-sum命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
矩阵乘法矩阵乘法 A[M, K] @ B[K, N] = C[M, N]中,大K维度矩阵乘法(K>>M,N)优化:针对M/N较小但K极大(如M=N=256,K=131072)的场景,Split-K切分K维度并行化、Workspace+Reduce替代全局同步,实现显著性能提升
Triton Ascend hard API restrictions and forbidden syntax. MUST-follow rules that apply to every kernel: forbidden control flow (return/break/continue/lambda/while), tensor slice/index restrictions, scalar conversion rules, BLOCK_SIZE upper bound. Violating any of these produces a compile or runtime error on Ascend.
Triton Ascend 性能优化通用策略: BLOCK_SIZE 选择 (1024-2048 for elementwise, must be <65536), grid configuration (use VEC_CORE_NUM / CUBE_CORE_NUM, 2D/3D grid for matmul / conv / reduce, 1D grid + inner loop for elementwise / pointwise), 256B alignment for memory transfers, autotune block-size patterns, fp16 / fp32 precision conversion. Bind via keywords like matmul, elementwise, reduce, block_size, grid, autotune, alignment, fp16, fp32, tile, interleaved-loop, cube-core, vec-core.
| name | pypto-case-reduction-sum |
| description | 单轴归约示例:3D Sum reduction — 保持原始维度,最简 kernel |
| category | example |
| version | 1.0.0 |
| metadata | {"backend":"ascend","dsl":"pypto","operator_patterns":"reduction"} |
最简单的模式——不需要 loop/view/assemble,kernel 只有 3 行。
def create_sum_reduction_kernel(in_shape, out_shape):
@pypto.frontend.jit(runtime_options=..., debug_options=...)
def kernel(
x: pypto.Tensor(in_shape, pypto.DT_FP32),
) -> pypto.Tensor(out_shape, pypto.DT_FP32):
output = pypto.tensor(list(out_shape), pypto.DT_FP32)
pypto.set_vec_tile_shapes(1, 16, 256)
output[:] = pypto.sum(x, dim=1, keepdim=True)
return output
return kernel
forward:保持原始维度,不降维。
def forward(self, x):
assert x.dim() == 3
assert tuple(x.shape) == (16, 256, 256)
assert self.dim == 1
x = x.contiguous()
batch, _, dim2 = x.shape
return create_sum_reduction_kernel(
tuple(x.shape), (batch, 1, dim2)
)(x)
set_tile + sum + return,无需 loop/view/assemblepypto.amin / pypto.amax 同理,只换 APIsum * (1.0 / size)(无内建 mean API)(16, 256, 256), dim=1 的 3D 单轴归约,默认首选从 (1, 16, 256) 起步,再按 32/64 对照实测。(1, 16, 256) 作为默认实现。(1, 32, 256) 与 (1, 64, 256) 不作为默认模板,仅作为对照候选。get_init_inputs() 返回值是本次固定参数(例如 dim=1)。Example, change to desired dimension 是题库说明,不是当前实现目标。ModelNew.__init__(dim) 签名;forward 中 assert self.dim == <固定值>;dim=<固定值>,不要写 if dim == ... 分支;create_*_kernel 不再接收 dim 运行时参数。反例(不要这样写):
def create_xxx_kernel(in_shape, out_shape, dim):
...
output[:] = pypto.amin(x, dim=dim, keepdim=True)
正例(固定 dim 写死):
FIXED_DIM = 1
def create_xxx_kernel(in_shape, out_shape):
...
output[:] = pypto.amin(x, dim=FIXED_DIM, keepdim=True)