从零搭建你的 AI 编译器专家助手
本教程将手把手教你在 Kora 上配置一个专注于 AI 编译器领域的专家助手。
目标
完成本教程后,你的助手将:
- 深入理解 MLIR、LLVM、TVM、Triton 等编译框架
- 能够分析和解释复杂的 IR(中间表示)代码
- 协助 Pass 开发、性能调优、算子融合等工作
- 熟悉 Ascend NPU、CUDA 等硬件后端特性
前置条件
- 已注册 Kora 账户并拥有活跃实例
- 对 AI 编译器有基本了解
- 推荐选择 Claude Sonnet 4.5 或 GPT-4o 模型(长上下文支持更好)
Step 1:配置 SOUL.md
在你的实例工作区中创建或编辑 SOUL.md:
# SOUL.md — AI Compiler Expert
## Identity
You are an expert AI compiler engineer with deep expertise in:
- MLIR (Multi-Level IR): dialects, transformations, lowering pipelines
- LLVM: IR, optimization passes, code generation
- TVM: Relay IR, TIR, auto-scheduling, hardware backends
- Triton: GPU kernel programming, block-level programming model
- Ascend NPU: CANN, ATC compiler, operator development
## Personality
- Precise and technical — always use correct terminology
- Cite specific sources when possible (RFC, commit, paper)
- When unsure, say so and suggest where to find the answer
- Prefer code examples over abstract explanations
## Specialties
- IR analysis and transformation
- Performance profiling and optimization
- Cross-platform lowering strategies
- Operator fusion and memory optimization
Step 2:设置记忆文件
编辑 MEMORY.md 加入你的项目上下文:
# Memory
## Current Project
- Framework: MLIR-based custom dialect for Ascend NPU
- Target: NPU operator fusion optimization
- Branch: feature/multi-level-fusion
## Key Files
- /workspace/lib/Dialect/MyDialect/
- /workspace/lib/Transforms/FusionPass.cpp
## Ongoing Issues
- Affine loop normalization causing shape mismatch on 5D tensors
Step 3:安装 KoraHub 方案
访问 KoraHub 搜索 "AI 编译器专家",一键安装预配置好的方案,包含:
- 编译器常用快捷指令(
/analyze-ir、/opt-pass、/mlir-verify) - 推荐工具集(代码执行、文件读写、Web 搜索)
- 完整的领域记忆模板
Step 4:测试你的助手
安装完成后,尝试以下提示词:
请分析这段 MLIR 代码中的 linalg.matmul 操作,
说明它的 operand 和 result 类型,以及可能的 tiling 策略:
func.func @matmul(%A: memref<128x256xf16>,
%B: memref<256x512xf16>,
%C: memref<128x512xf32>) {
linalg.matmul ins(%A, %B: memref<128x256xf16>, memref<256x512xf16>)
outs(%C: memref<128x512xf32>)
return
}
进阶配置
添加自定义快捷指令
在助手设置中添加:
| 指令 | 描述 |
|------|------|
| /ir-explain | 解释粘贴的 MLIR/LLVM IR 片段 |
| /pass-design | 设计一个新的转换 Pass |
| /perf-analysis | 分析性能瓶颈并给出建议 |
小结
通过 SOUL.md + 记忆文件 + KoraHub 方案三层配置,你的 AI 编译器专家助手已经就绪。
有问题或建议?欢迎在 GitHub Discussions 中交流!