소스 정보
- 저장소
- mindspore-ai/akg
- 최근 소스 활동
- 2026년 3월 2일 02:46
- 감지된 SKILL.md 언어
- 중국어
- 스타
- 259
- 포크
- 48
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
SOC 직업 분류 기준
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/mindspore-ai/akg --skill pypto-case-norm-batchnorm명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? 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-norm-batchnorm |
| description | 模式 C 示例:3D Norm — BatchNorm,展示 3D 降维、连续单轴 sum 多维归约、expand_clone 广播 |
| category | example |
| version | 1.0.0 |
| metadata | {"backend":"ascend","dsl":"pypto","operator_patterns":"norm,reduction,loop,expand_clone"} |
forward 中 reshape(B, C, -1) 降为 3D,kernel 沿 channel 维 loop。
BASIC_CHANNEL = 8
MAIN_CHANNEL_LOOP = 8 # channels / BASIC_CHANNEL
def create_batchnorm_kernel(batch, channels, spatial, eps):
assert channels == MAIN_CHANNEL_LOOP * BASIC_CHANNEL
@pypto.frontend.jit(runtime_options=..., debug_options=...)
def kernel(
x: pypto.Tensor((batch, channels, spatial), pypto.DT_FP32),
) -> pypto.Tensor((batch, channels, spatial), pypto.DT_FP32):
output = pypto.tensor([batch, channels, spatial], pypto.DT_FP32)
inv_total = 1.0 / (batch * spatial)
pypto.set_vec_tile_shapes(1, 1, 16384)
for ci in pypto.loop(0, MAIN_CHANNEL_LOOP, 1, name="LOOP_CH", idx_name="ci"):
ch_off = ci * BASIC_CHANNEL
x_chunk = pypto.view(x, [batch, BASIC_CHANNEL, spatial], [0, ch_off, 0])
# 多轴归约:连续两次单轴 sum
s = pypto.sum(x_chunk, dim=2, keepdim=True)
s = pypto.sum(s, dim=0, keepdim=True) # (1, C, 1)
sq = pypto.sum(x_chunk * x_chunk, dim=2, keepdim=True)
sq = pypto.sum(sq, dim=0, keepdim=True)
mean = s * inv_total
var = sq * inv_total - mean * mean
denom = pypto.sqrt(var + eps)
# expand_clone 广播回 batch 维
mean_b = pypto.expand_clone(mean, [batch, BASIC_CHANNEL, 1])
denom_b = pypto.expand_clone(denom, [batch, BASIC_CHANNEL, 1])
normed = (x_chunk - mean_b) / denom_b
pypto.assemble(normed, [0, ch_off, 0], output)
return output
return kernel
forward:reshape(B, C, -1) → kernel → reshape(x.shape)
RMSNorm 同模式:3D (B, features, spatial),只求 sqrt(mean(x²) + eps) 无需减均值。
pypto.sum(dim=2) 再 pypto.sum(dim=0) — 多轴归约必须分步pypto.expand_clone(mean, [B, C, 1]) — 单轴广播,归约后恢复维度用于运算set_vec_tile_shapes(1, 1, 16384) — 3D,前两维小,最后维大 tile