Skip to content

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

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

Problem cache follow-on: pluggable backends, layered cache paths, compile-options API, and offline tooling#5117
danieyan-amd wants to merge 9 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

danieyan-amd added 7 commits August 5, 2026 16:48
Introduce a type-erased problem_cache_backend so cache storage is interchangeable without inheritance. Add json_problem_cache as the default concrete backend and route the runtime problem_cache through it; a static_assert confirms the backend satisfies the concept.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Add sqlite_problem_cache as a second concrete backend using system SQLite via migraphx::sqlite (no vendored amalgamation). It persists the device-keyed cache to a solutions table and satisfies the problem_cache_backend concept.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Load a list of problem caches as a read-only priority list: search them in order and return the first hit (highest priority first, e.g. application-provided, then shipped). Shipped caches are immutable. compile_ops and the gemm paths look up through find_in_problem_caches so the priority applies across the pipeline.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Add problem_cache_path and the ordered problem_cache_paths to compile_options, wired into the gpu target so callers can supply cache locations without the env var. Expose problem_cache_paths through the C and C++ APIs for the ONNX Runtime EP.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Add an offline aggregator that merges per-GPU caches into a master, validates a cache, and converts between backends. Storage is selected through the type-erased backend via a make_backend(json/sqlite) factory; reads enumerate the concrete backend. Supports conflict policies and legacy empty-device handling.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Add aggregate_cache, validate_cache, and convert_cache driver subcommands wrapping the offline aggregator, reporting errors cleanly instead of crashing.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
@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
MIGRAPHX_C_EXPORT migraphx_status migraphx_compile_options_set_advance_backend_options(
migraphx_compile_options_t compile_options, const char* options_json, ...);

MIGRAPHX_C_EXPORT migraphx_status migraphx_compile_options_set_problem_cache_paths(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The problem cache should be set as a backend option since this is a GPU-only option. So there shouldn't be an API changes.

Comment thread src/driver/main.cpp
}
};

#ifdef HAVE_GPU

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I dont think we should be putting a lot of GPU-only code into the driver. The offline aggregation could be done as a python script.


/// Search all caches in priority order (read-only first, then writable).
/// Returns the first hit. This is what compile_ops should call.
optional<value> find_in_problem_caches(const std::string& name, const value& problem) const

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be in the context method. This should be handled by problem_cache::has.

//
// te.py DSL input for migraphx::gpu::problem_cache_backend.
//
// REGENERATION (until tools/generate.py learns gpu/ subdir routing):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The tools/generate.py needs to be updated to handle the gpu/subdir. This should not be done manual as this will not be checked by CI.

void insert(const cache_device_key& dk, const value& key, const value& solution);

/// Insert a sentinel (null value) for `key` to record "we've tried
/// this problem and there is no solution". Distinguished from a hit

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not what mark is for. Its for a pending solution. This comment is completely wrong.

* new solutions are written to the last (writable) path. Empty falls back
* to the MIGRAPHX_PROBLEM_CACHE environment variable.
*/
std::vector<std::string> problem_cache_paths;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There should be only one path. The path for the system level db or user level db should be compiled into migraphx.

/**
* Problem cache file paths, searched in priority order (first hit wins);
* new solutions are written to the last (writable) path. Empty falls back
* to the MIGRAPHX_PROBLEM_CACHE environment variable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With the backend option the MIGRAPHX_PROBLEM_CACHE variable should be removed.

Route include/gpu te.py inputs through generate.py (moving the DSL into tools/include/gpu/), and fix the mark() comment to describe a pending solution rather than a missing one.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
@tperry-amd tperry-amd added the Windows Related changes for Windows Environments label Aug 6, 2026
…one API and env var

Problem cache file paths now arrive through the GPU backend_options (problem_cache_files) instead of a dedicated compile_options API, and the MIGRAPHX_PROBLEM_CACHE environment variable is removed. A single file is writable; multiple are a read-only priority list.

Signed-off-by: danieyan-amd <daniel.anieyan@amd.com>
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.

3 participants