Commit d5f8c19
committed
feat(core.utils): add persistent program caches (sqlite + filestream)
Convert cuda.core.utils to a package and add persistent, on-disk caches
for compiled ObjectCode produced by Program.compile.
Public API (cuda.core.utils):
* ProgramCacheResource -- abstract bytes|str -> ObjectCode mapping
with context manager and pickle-safety warning. Path-backed
ObjectCode is rejected at write time (would store only the path).
* SQLiteProgramCache -- single-file sqlite3 backend (WAL mode,
autocommit) with LRU eviction against an optional size cap. A
threading.RLock serialises connection use so one cache object is
safe across threads. wal_checkpoint(TRUNCATE) + VACUUM run after
evictions so the size cap bounds real on-disk usage, not just
logical payload. Schema-version mismatch on open wipes entries.
* FileStreamProgramCache -- directory of atomically-written entries
(tmp + os.replace) safe across concurrent processes, with
best-effort size enforcement by mtime. Windows-only PermissionError
from os.replace is swallowed as a cache miss; other platforms
re-raise. Schema-version mismatch on open wipes entries.
* make_program_cache_key -- stable 32-byte blake2b key over code,
code_type, ProgramOptions (including options.name), target_type,
name expressions (normalised str/bytes), cuda core/driver/NVRTC
versions, linker backend+version for PTX inputs, NVVM-specific
fields (extra_sources, use_libdevice), and an optional extra_digest
that callers MUST supply when options pull in external file content
(include_path, pre_include, pch, use_pch, pch_dir).
sqlite3 is imported lazily so the package is usable on interpreters
built without libsqlite3.
Tests: single-process CRUD, LRU/size-cap (logical and on-disk),
corruption, schema-mismatch, threaded access (SQLite), multiprocess
stress (FileStream), Windows vs POSIX PermissionError behaviour, and
an end-to-end test that compiles a real CUDA C++ kernel, stores the
ObjectCode, reopens the cache, and calls get_kernel on the deserialised
copy. Public API is documented in cuda_core/docs/source/api.rst.1 parent 56b53ca commit d5f8c19
File tree
6 files changed
+2402
-8
lines changed- cuda_core
- cuda/core
- utils
- docs/source
- tests
6 files changed
+2402
-8
lines changedThis file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments