Skip to content

Problem cache follow-on: pluggable backends, layered cache paths, compile-options API, and offline tooling - #5117

Open
danieyan-amd wants to merge 13 commits into
ROCm:developfrom
danieyan-amd:feature/problem-cache-followon
Open

Problem cache follow-on: pluggable backends, layered cache paths, compile-options API, and offline tooling#5117
danieyan-amd wants to merge 13 commits into
ROCm:developfrom
danieyan-amd:feature/problem-cache-followon

Conversation

@danieyan-amd

Copy link
Copy Markdown
Contributor

Summary

Follow-on to #4835 (hardware-provenance problem cache). This adds the deployment and tooling layer around the problem cache so pre-tuned caches can be shipped, discovered, and combined without environment variables.

  • Pluggable cache backends — a type-erased problem_cache_backend with a JSON backend and an optional SQLite backend (built on system SQLite), selectable through compile_options.
  • Layered cache pathscompile_options gains an ordered list of problem-cache paths (problem_cache_paths, with a single-path convenience). Paths are searched in priority order (first hit wins) and loaded read-only, so an application-provided cache can take precedence over a shipped one without mutating either.
  • Compile-options API (C / C++ / Python)migraphx_compile_options_set_problem_cache_paths and the matching C++/Python wrappers, so the paths can be set programmatically rather than via an environment variable.
  • Offline aggregator — a library API to merge, validate, and convert problem-cache files across devices, with duplicate/conflict detection and configurable conflict policies (error_on_conflict / first_wins / last_wins).
  • Driver subcommands — command-line frontends for the aggregator (merge / validate / convert).

Testing

New GPU unit tests cover the backend abstraction, the SQLite backend round-trip, the layered path override, and the aggregator (merge / validate / convert plus conflict and legacy-device policies), along with an API-level compile-options test.

Notes

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Since this is an external pull request, a maintainer must review PR and add the "ok-to-test" label if it is approved for testing.

Comment thread src/api/include/migraphx/migraphx.h Outdated
Comment thread src/driver/main.cpp Outdated
Comment thread src/targets/gpu/include/migraphx/gpu/context.hpp Outdated
Comment thread src/targets/gpu/include/migraphx/gpu/problem_cache_backend.hpp Outdated
Comment thread src/targets/gpu/include/migraphx/gpu/problem_cache_backend.hpp Outdated
Comment thread src/include/migraphx/compile_options.hpp Outdated
Comment thread src/include/migraphx/compile_options.hpp Outdated
@tperry-amd tperry-amd added the Windows Related changes for Windows Environments label Aug 6, 2026
@danieyan-amd

Copy link
Copy Markdown
Contributor Author

I realized that not all of the runtime functionality is there for the backed abstraction layer is there, thus why it was in a draft so more changes are going to be committed.

@danieyan-amd
danieyan-amd force-pushed the feature/problem-cache-followon branch from 8c119b5 to 6045418 Compare August 7, 2026 00:31
danieyan-amd added 3 commits August 6, 2026 22:53
Introduce a type-erased problem_cache_backend (pluggable storage) with JSON and SQLite implementations; the runtime problem_cache routes has/insert/mark/get/load/save through it and canonicalizes keys so JSON round-trips match shipped caches. Move cache_device_key to its own header and route gpu/ DSL generation via generate.py.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Load an ordered list of read-only caches (first hit wins) alongside a writable cache; compile_ops and the gemm paths query them during tuning.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Read problem_cache_files from the GPU backend options and load them into the context; no dedicated API or environment variable is required.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
@danieyan-amd
danieyan-amd force-pushed the feature/problem-cache-followon branch from 6045418 to 2911a33 Compare August 7, 2026 13:24
danieyan-amd and others added 3 commits August 7, 2026 14:58
Addresses review feedback: the multi-cache priority search lived in the
context (read_only_caches + find_in_problem_caches). Fold it into
problem_cache so has() and get() search the read-only layers (highest
priority first) then the writable cache. The context now just delegates.
Behaviour is unchanged: first hit wins; a single file is writable and
multiple files are a read-only priority list.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
problem_cache::has/get replace raw loops over read_only_backends with std::any_of / std::find_if; gemm_default_solution and hip_gemm_default_solution take context by const&.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
@danieyan-amd
danieyan-amd force-pushed the feature/problem-cache-followon branch from 87e061b to a968bcc Compare August 10, 2026 04:18
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5117   +/-   ##
========================================
  Coverage    93.09%   93.09%           
========================================
  Files          623      623           
  Lines        33073    33073           
========================================
  Hits         30789    30789           
  Misses        2284     2284           
Files with missing lines Coverage Δ
src/include/migraphx/compile_options.hpp 85.71% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danieyan-amd
danieyan-amd marked this pull request as ready for review August 10, 2026 04:30
@danieyan-amd
danieyan-amd requested a review from a team as a code owner August 10, 2026 04:30
Copilot AI lite review requested due to automatic review settings August 10, 2026 04:30
@danieyan-amd
danieyan-amd requested a review from causten as a code owner August 10, 2026 04:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR builds out the “deployment + tooling” layer around the GPU problem cache by introducing a type-erased backend interface, adding layered (priority-ordered) cache paths, and wiring the cache configuration through GPU backend options so applications can ship and override pre-tuned caches.

Changes:

  • Introduces problem_cache_backend type-erasure plus a JSON backend and a new SQLite backend implementation.
  • Adds layered cache loading (multiple read-only caches searched in priority order; single cache is writable) and threads this through GPU target/context/compile paths.
  • Adds GPU unit tests covering backend behavior, SQLite round-trip, and layered-path override; updates generator plumbing and build files.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/include/gpu/problem_cache_backend.hpp te.py DSL definition for the type-erased backend interface.
tools/generate.py Routes tools/include/gpu/* generated headers into the GPU target include tree.
test/gpu/problem_cache_backend.cpp Tests type-erased backend forwarding and any_cast for JSON backend.
test/gpu/sqlite_problem_cache.cpp Tests SQLite backend round-trip and type-erasure integration.
test/gpu/problem_cache_path_override.cpp Tests explicit path override and layered (priority) cache behavior.
src/targets/gpu/include/migraphx/gpu/problem_cache_backend.hpp Generated type-erased backend wrapper header.
src/targets/gpu/include/migraphx/gpu/json_problem_cache.hpp Declares JSON backend (including legacy migration support).
src/targets/gpu/json_problem_cache.cpp Implements JSON backend load/save + legacy-format migration + key normalization.
src/targets/gpu/include/migraphx/gpu/sqlite_problem_cache.hpp Declares SQLite backend.
src/targets/gpu/sqlite_problem_cache.cpp Implements SQLite backend load/save and in-memory operations.
src/targets/gpu/include/migraphx/gpu/cache_device_key.hpp Extracts cache_device_key into its own header.
src/targets/gpu/include/migraphx/gpu/problem_cache.hpp Reworks problem_cache to use backend + layered read-only backends + path override.
src/targets/gpu/problem_cache.cpp Implements layered lookup semantics and path override behavior.
src/targets/gpu/include/migraphx/gpu/context.hpp Adds layered cache configuration and narrow cache get/insert/mark/save API.
src/targets/gpu/target.cpp Adds problem_cache_files backend option and configures cache loading from it.
src/targets/gpu/compile_ops.cpp Uses layered cache lookup and writes only to the writable cache.
src/targets/gpu/include/migraphx/gpu/gemm_impl.hpp Adjusts default-solution API to take const context&.
src/targets/gpu/gemm_impl.cpp Uses new context cache API for gemm solution load/store.
src/targets/gpu/include/migraphx/gpu/hip_gemm_impl.hpp Adjusts default-solution API to take const context&.
src/targets/gpu/hip_gemm_impl.cpp Uses new context cache API for hipBLASLt solution load/store.
src/targets/gpu/CMakeLists.txt Adds new backend implementation sources to GPU library build.
src/include/migraphx/compile_options.hpp Adds <vector> include (compile options now transport path lists elsewhere in the PR).
CHANGELOG.md Notes the new layered cache priority list delivered via GPU backend options.
Suppressed comments (1)

src/targets/gpu/sqlite_problem_cache.cpp:157

  • sqlite_problem_cache::get()/has() perform lookups using the raw key value, which requires callers to already canonicalize the key. Normalizing the lookup key here keeps behavior aligned with json_problem_cache and with problem_cache (which normalizes problems before querying).
optional<value> sqlite_problem_cache::get(const cache_device_key& dk, const value& key) const
{
    auto bucket_it = cache.find(dk);
    if(bucket_it == cache.end())
        return nullopt;
    auto it = bucket_it->second.find(key);
    if(it == bucket_it->second.end())
        return nullopt;
    return it->second;
}

bool sqlite_problem_cache::has(const cache_device_key& dk, const value& key) const
{
    auto bucket_it = cache.find(dk);
    if(bucket_it == cache.end())
        return false;
    return contains(bucket_it->second, key);
}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/targets/gpu/sqlite_problem_cache.cpp
Comment thread src/targets/gpu/problem_cache.cpp Outdated
Comment thread src/targets/gpu/sqlite_problem_cache.cpp
Comment thread src/targets/gpu/problem_cache.cpp
@danieyan-amd
danieyan-amd marked this pull request as draft August 10, 2026 05:43
danieyan-amd added 2 commits August 10, 2026 12:38
sqlite_problem_cache: normalize keys on load/insert/mark/get/has for parity with json_problem_cache (JSON type erasure otherwise causes round-trip lookup misses). problem_cache::load(paths): clear path_override in multi-file mode so read-only layering cannot write back through a stale override. json_problem_cache: remove the never-wired legacy flat-object migration (set_migration_device_key had no callers and the flat format never shipped). Test erases by the normalized key to match the backend key convention.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
@danieyan-amd
danieyan-amd marked this pull request as ready for review August 11, 2026 02:29
@danieyan-amd
danieyan-amd requested a review from pfultz2 August 11, 2026 16:15
Comment thread src/targets/gpu/include/migraphx/gpu/context.hpp Outdated
Comment thread src/targets/gpu/include/migraphx/gpu/context.hpp Outdated
Comment thread src/targets/gpu/include/migraphx/gpu/problem_cache.hpp
Comment thread src/targets/gpu/problem_cache.cpp
Comment thread src/targets/gpu/problem_cache.cpp
Comment thread src/targets/gpu/problem_cache.cpp Outdated
danieyan-amd pushed a commit to danieyan-amd/AMDMIGraphX that referenced this pull request Aug 18, 2026
Release cherry-pick of the problem-cache follow-on: pluggable JSON/SQLite backends, cache_device_key, layered multi-cache priority (app>local>shipped, first-hit-wins) delivered via the problem_cache_files GPU backend option. Reviewed on ROCm#5117 -- release-branch merge, not for re-review.

Conflicts vs 2610: target.cpp resolved as union with the compile_mode feature; tools/generate.py kept at 2610 (generated header is committed; ROCm#5117 generate.py routing assumes newer develop).
- Select the storage backend by file type (SQLite for .db/.sqlite, else JSON)
- Search the writable cache before the read-only layers
- Remove the context problem-cache facade methods in favor of get_problem_cache() (add a const overload for const-context callers)

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
tperry-amd added a commit that referenced this pull request Aug 20, 2026
…2610

[Release merge - no review] Problem cache (#5117) -> gpuep-rel-2610
danieyan-amd added 3 commits August 20, 2026 09:55
Expose separate read-only problem_cache_files (shipped gpuep/ISV caches, never written back) and writable_problem_cache_files (the developer cache that new tuning solutions save back to). Addresses review feedback to offer distinct read-only and read/write cache configuration.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
…view-fixes

# Conflicts:
#	src/targets/gpu/target.cpp
Cover the two-tier scenarios end to end: writable-only and no-cache configs, a byte-for-byte check that read-only caches are never rewritten on save, and backend-option parsing that keeps the read-only and writable options distinct.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
@danieyan-amd
danieyan-amd force-pushed the feature/problem-cache-followon branch from b8c059d to fabcd93 Compare August 20, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Windows Related changes for Windows Environments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants