返回博客
教程教程MLIRLLVMAI编译器高级

从零搭建你的 AI 编译器专家助手

手把手教你在 Kora 上配置一个深度掌握 MLIR、LLVM、TVM 的 AI 编译器专家助手,帮助你加速 AI 编译器开发工作。

从零搭建你的 AI 编译器专家助手


本教程将手把手教你在 Kora 上配置一个专注于 AI 编译器领域的专家助手。


目标


完成本教程后,你的助手将:



前置条件



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 编译器专家",一键安装预配置好的方案,包含:



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 中交流!


查看所有文章