feat(cache): unify cache infrastructure + fix AOT cache collision#161
feat(cache): unify cache infrastructure + fix AOT cache collision#161whjthu wants to merge 6 commits into
Conversation
…cache for make.py and migrate cache of auto_tuner.py to unified cache
UpdatePR 概览本 PR 相比 相比
|
| Case | master |
本 PR | 提升 |
|---|---|---|---|
| pad / slice-copy style kernel | 7.087 ms | 0.174 ms | 约 40.7x |
| matmul-style kernel | 45.628 ms | 0.373 ms | 约 122.2x |
平均 repeated make() 耗时:
| Case | master mean |
本 PR mean | 提升 |
|---|---|---|---|
| pad / slice-copy style kernel | 7.153 ms | 0.192 ms | 约 37.3x |
| matmul-style kernel | 48.438 ms | 0.385 ms | 约 125.8x |
JIT handle 复用情况:
| Case | master handle 复用 |
本 PR handle 复用 |
|---|---|---|
| pad / slice-copy style kernel | 0 / 99 | 99 / 99 |
| matmul-style kernel | 0 / 99 | 99 / 99 |
性能结果解读
本 PR 的主要性能收益来自重复 JIT handle 构建路径,而不是已经构建完成后的 GPU kernel runtime。
这类收益会体现在:
- 测试
- benchmark
- 交互式开发
- 重复模型 / 算子初始化
- 多次创建相同 shape / config 算子的场景
对于简单 kernel,repeated make() 开销从约 7 ms 降到约 0.17 ms。
对于 matmul 这类更复杂的 symbolic arrangement,repeated make() 开销从约 45 ms 降到约 0.37 ms。
验证情况
本 PR 已在服务器环境中按 workflow 等价命令完成验证。
Pytest
275 passed, 1 skipped in 1038.83s
背景
ninetoothed 此前有 4 套独立 cache, 行为不一致, 各自维护:
调研下来发现 cache_source 这个 key 算式有 collision bug: 同一 arrangement 在不同 block_size config 下产生一模一样的 Triton source 文本 (block_size 只流到 kernel name 后缀, 不流到 source body), sha256 出同一个 digest, 多个子进程并发 race-write 同一个 .py 文件, 结果 triton.tools.compile 用 loser's --kernel-name 找 winner's def 找不到, 报
AttributeError: module '...' has no attribute 'conv2d_...'。这个 bug 之前没被报告是因为可能是因为 .so 缓存已经在 ~/.ninetoothed/ 里, build._load_cached 命中, 根本不走 aot 路径, collision 不触发。新 clone 或 PR CI 是 cold cache, 才会踩到。
本 PR 包含
新增: 统一 cache 基础设施 (src/ninetoothed/_cache.py)
迁移: JIT handle cache (src/ninetoothed/make.py)
迁移: auto_tuner cache (src/ninetoothed/auto_tuner.py)
修复 AOT cache collision (src/ninetoothed/generation.py)
测试清理
新增测试
验证
GPU env:
CPU env (CPU-only, 无 CUDA driver):
向后兼容 / 迁移注意
Checklist
pytestoutput: