Skip to content

Commit 40d93c4

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``: * ``ProgramCacheResource`` — abstract Mapping-like base class with a context manager, ``get``/``close``, and a ``pickle``-safety warning. * ``SQLiteProgramCache`` — single-file sqlite3 backend (WAL mode, autocommit) with LRU eviction against an optional size cap. * ``FileStreamProgramCache`` — directory of atomically-written entries (staged tmp file + ``os.replace``) for concurrent multi-process use, with best-effort size enforcement by mtime. Windows ``PermissionError`` from ``os.replace`` is treated as a non-fatal cache miss. * ``make_program_cache_key`` — stable 32-byte blake2b key derived from code, code_type, ProgramOptions, target_type, name expressions, cuda core/driver/NVRTC versions, and NVVM-specific fields (``extra_sources``, ``use_libdevice``) that would otherwise collide. ``sqlite3`` is imported lazily so the rest of the package is usable on interpreters built without libsqlite3. Includes single-process CRUD, LRU/size-cap, corruption-handling, and multiprocess stress tests, plus an end-to-end test that compiles a real CUDA C++ kernel, stores it in each backend, reopens the cache, and verifies ``get_kernel`` still works on the deserialised ``ObjectCode``. Public API is documented in ``cuda_core/docs/source/api.rst``.
1 parent 56b53ca commit 40d93c4

File tree

6 files changed

+1543
-8
lines changed

6 files changed

+1543
-8
lines changed

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)