Skip to content

Commit c67acdf

Browse files
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 c67acdf

6 files changed

Lines changed: 2178 additions & 8 deletions

File tree

cuda_core/cuda/core/utils.py

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
from cuda.core._memoryview import (
6+
StridedMemoryView,
7+
args_viewable_as_strided_memory,
8+
)
9+
from cuda.core.utils._program_cache import (
10+
FileStreamProgramCache,
11+
ProgramCacheResource,
12+
SQLiteProgramCache,
13+
make_program_cache_key,
14+
)

0 commit comments

Comments
 (0)