Repository navigation
feat(ir): add on-disk compile cache for kernels and implement caching… - #769
Conversation
☂️ Code Coverage
Overall Coverage
New Files
Modified Files
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| if code.source is not None and code.source.lineno_begin != mt.lineno_begin: | ||
| file, saved = code.source.file, code.source.lineno_begin | ||
| for stmt in code.walk(): | ||
| source = stmt.source | ||
| if source and source.file == file and source.lineno_begin == saved: | ||
| source.lineno_begin = mt.lineno_begin |
There was a problem hiding this comment.
I think this work now, but I think we should really redesign the ir.Method and how SourceInfo is. this seems like crazy we need to re-walk the whole IR just to update the lineno offset @Roger-luo @zhenrongliew.
There was a problem hiding this comment.
Ideally source info is stored in an areana and we only point certain IR node to the arena ID, so you can shift the lineno by iterating a piece of continuous memory without walking the IR. But this is not super beneficial in Python's object model because you don't really have a continuous memory anyways.
|
can we improve the coverage a bit to get this PR in? @copilot |
Co-authored-by: Roger-luo <8445510+Roger-luo@users.noreply.github.com>
Added direct tests for cache directory selection and fingerprinting; |
Backport results for a6481d6Succeeded:
|
Add an opt-in on-disk cache for compiled kernels
Kernel decorators compile when a module is imported: they lower the function and
run the dialect group's passes, again in every new process, even when nothing
changed. With
KIRIN_COMPILE_CACHE_DIRset, each compiled kernel is now saved,and a later process loads it instead of running the passes, as long as nothing it
depends on has changed. Without the variable, behaviour is unchanged.
Key. A SHA-256 over the lowered IR (which holds the values of the globals the
function reads), the keys of the kernels it calls, the dialect names and
run_passsource, the decorator options, the function's file and line, and thePython and package versions. Any change gives a new key, so a stale entry is
never found.
Storage. The compiled code is pickled. The kernel itself, its callees and its
dialect group are saved as references and relinked to the live objects on load;
singleton types are rebuilt as the same objects. Files are written atomically.
Limitations
changing library code.
Testing
test/ir/test_compile_cache.py: four runs in fresh processes (empty cache,nothing changed, callee changed, global changed) check which kernels recompile
and their results.
cache and 0.03 s with a warm cache.
🤖 Generated with Claude Code