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 3 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 3 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
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 Outdated
}
};

#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.

@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 added 3 commits August 6, 2026 20:29
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 8c119b5 to 6045418 Compare August 7, 2026 00:31
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