Repository navigation
Binary cache sql backend - #5232
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Release-mode validation holes, statement cleanup issues, and the missing promised provenance table remain unresolved.
Review effort: Balanced
Findings: 3
Open (6)
Reset statement before rethrowing initial step exception · New Reject empty SQL when sqlite3_prepare returns no statement · New A failed write leavesstore_stmtvalid, so every later kernel retries the same unusable database.… Implement or revise missing cache_info_v1 provenance table · New This removes the directory-backed disk-hit, corruption, compile-twice, and verified-reuse… The new extension-based backend selection is not reflected in the binary-cache documentation:…
Comment on lines
+58
to
+59
| constexpr const char* schema_sql = R"__migraphx__( | ||
| CREATE TABLE IF NOT EXISTS cache_v1 ( |
…re leaves the database read-only instead of retrying.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Prepared statements mishandle underbinding and empty BLOBs, while existing database schemas are insufficiently validated.
7 open findings
Release builds allow statement argument-count mismatches · New Empty BLOB conversion performs pointer arithmetic on null · New Existing cache table schema is not validated · New A failed write leavesstore_stmtvalid, so every later kernel retries the same unusable database.… Implement or revise missing cache_info_v1 provenance table This removes the directory-backed disk-hit, corruption, compile-twice, and verified-reuse… The new extension-based backend selection is not reflected in the binary-cache documentation:…
2 resolved since last review
🧠 Review effort: Balanced
| { | ||
| if(not valid()) | ||
| MIGRAPHX_THROW("sqlite: calling a statement that was never prepared"); | ||
| assert(sizeof...(Ts) == parameter_count()); |
| std::size_t size = data == nullptr ? 0 : bytes; | ||
| if(type == SQLITE_TEXT) | ||
| return value::pair(name, size == 0 ? std::string{} : std::string(data, size)); | ||
| return value::pair(name, value::binary{data, size}); |
Comment on lines
+135
to
+136
| r.db.execute(schema_sql); | ||
| r.store_stmt = r.db.prepare(store_sql); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5232 +/- ##
===========================================
+ Coverage 92.72% 92.73% +0.02%
===========================================
Files 635 635
Lines 36203 36314 +111
===========================================
+ Hits 33566 33675 +109
- Misses 2637 2639 +2
🚀 New features to boost your workflow:
|
pnikolic-amd
marked this pull request as ready for review
October 8, 2026 12:24
TedThemistokleous
self-requested a review
October 8, 2026 14:12
pfultz2
approved these changes
Oct 9, 2026
TedThemistokleous
approved these changes
Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Motivation
Adds a SQLite storage backend to the GPU binary cache introduced in #5100, as an alternative to the
directory of
.mxrfiles. A single database file is easier to copy between machines and to share,needs no per-entry files or renames, and records each kernel's operator name, problem and solution
in queryable columns so a cache can be inspected and pruned with the
sqlite3shell.Setting
MIGRAPHX_BINARY_CACHE(or thebinary_cacheoption) to a path ending in.dbor.sqliteselects the database; any other path keeps the existing directory cache. There is no newconfiguration.
Technical Details
migraphx::sqlite. The existing wrapper wassqlite3_exec-based,text-only and had no parameter binding, so it could not carry BLOBs. Added
sqlite_stmt, createdby
sqlite::prepare: calling it with arguments resets the statement, binds them and returns arange of rows, each converted to a
value(BLOB columns become binary values). Binding, steppingand resetting are private. Also added
sqlite::try_write, which does not throw, plusset_busy_timeoutandread_only, andvalue::pairfor building keyed values. Existingsqliteusers are unchanged, andsqlite3.hstays out of the GPU target.binary_cache_backend, generated fromtools/include/gpu/binary_cache_backend.hpplikeproblem_cache_backend, withload(version, device, key)andstore(version, device, vector<binary_cache_entry>).binary_cache::entrymoved intobinary_cache_entry.hpp, and the existing directory code movedunchanged into
file_binary_cache. Each backend serializes entries its own way and checks thefull key on load, so a hash collision is a miss rather than a wrong kernel.
binary_cache::inserttakes a vector of entries, andcompile_opsstoresevery result of a compile round in one call, so the database commits them in a single
transaction instead of one commit per kernel.
sqlite_binary_cache. Onecache_v1table with primary key(version, device, key_hash)and columns
key,op_name,problem/solution(JSON),code(msgpack BLOB) andtimestamp.versionholds the full version id (format, HIP compiler, kernel-header digest, rocMLIR), sorows from different builds can share a file and old builds can be pruned with one range delete.
The schema version is in the table name, so an incompatible change becomes a new table rather
than a migration. Statements are prepared once and reused. Stores run in one
BEGIN IMMEDIATEtransaction usingINSERT OR REPLACE, which plays the role of the filebackend's publish-by-rename. Cross-process safety relies on
busy_timeout(5000).unexpected layout, disables persistence with a warning. A read-only database (write-protected
file or read-only mount) still serves lookups. A failed store is rolled back and makes the cache
read-only for the rest of the process instead of retrying against a busy or broken database.
Missing parent directories are created, so a
.dbpath behaves like a directory path on a freshmachine.
make_problem_cache_backend. Storage opens onthe first lookup or insert, not in the constructor, so a context that never compiles never
touches the disk or probes the compiler.
docs/dev/triage-migraphx.rstcovers the database mode, inspecting and pruning withsqlite3, and read-only behaviour. The CHANGELOG binary-cache entry is updated.