Skip to content

Extend problem cache with hardware provenance metadata#4835

Open
danieyan-amd wants to merge 5 commits into
ROCm:developfrom
danieyan-amd:feature/problem-cache-schema-extension
Open

Extend problem cache with hardware provenance metadata#4835
danieyan-amd wants to merge 5 commits into
ROCm:developfrom
danieyan-amd:feature/problem-cache-schema-extension

Conversation

@danieyan-amd
Copy link
Copy Markdown

@danieyan-amd danieyan-amd commented Apr 30, 2026

Two changes to problem_cache.cpp:

  1. load(): Project deserialized keys to only {name, problem} so that extra metadata fields in the JSON don't break cache key matching. Previously, the full JSON object (all fields) was used as the map key, causing 100% cache misses when metadata was present.

  2. save(): Enrich each key with hardware provenance before writing: gpu_arch, cu_count, graphics_clock_mhz, memory_clock_mhz, memory_bus_bits, vram_bytes, wavefront_size, regs_per_block, max_threads_per_cu. Queried once via hipGetDeviceProperties at session end — negligible performance cost.

The in-memory map always uses {name, problem} keys for O(1) lookups. The on-disk JSON carries additional hardware context for traceability. On load, the extra fields are projected away, preserving fast matching.

Motivation

Adding hardware info to the problem cache, and added handling of the hardware data when doing cache lookups for solutions.

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

Two changes to problem_cache.cpp:

1. load(): Project deserialized keys to only {name, problem} so that
   extra metadata fields in the JSON don't break cache key matching.
   Previously, the full JSON object (all fields) was used as the map
   key, causing 100% cache misses when metadata was present.

2. save(): Enrich each key with hardware provenance before writing:
   gpu_arch, cu_count, graphics_clock_mhz, memory_clock_mhz,
   memory_bus_bits, vram_bytes, wavefront_size, regs_per_block,
   max_threads_per_cu. Queried once via hipGetDeviceProperties at
   session end — negligible performance cost.

The in-memory map always uses {name, problem} keys for O(1) lookups.
The on-disk JSON carries additional hardware context for traceability.
On load, the extra fields are projected away, preserving fast matching.
@danieyan-amd danieyan-amd marked this pull request as ready for review April 30, 2026 19:44
@danieyan-amd danieyan-amd requested a review from causten as a code owner April 30, 2026 19:44
Copilot AI review requested due to automatic review settings April 30, 2026 19:44
@danieyan-amd danieyan-amd marked this pull request as draft April 30, 2026 19:44
@danieyan-amd
Copy link
Copy Markdown
Author

Sorry Chris, I didnt mean to hit ready for review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the GPU problem cache persistence format to remain resilient to extra on-disk metadata while also recording hardware provenance for traceability.

Changes:

  • In load(), deserialize into a temporary map and project keys down to {name, problem} to prevent metadata fields from breaking cache-key matching.
  • In save(), enrich persisted keys with HIP device properties (e.g., arch, CU count, clocks, VRAM) before writing the JSON file.

Comment thread src/targets/gpu/problem_cache.cpp Outdated
// Enrich keys with hardware provenance metadata on write.
// This runs once at session end — negligible cost.
hipDeviceProp_t props{};
auto status = hipGetDeviceProperties(&props, get_device_id());
Comment thread src/targets/gpu/problem_cache.cpp Outdated
Comment on lines +61 to +67
std::unordered_map<value, value> raw;
from_value(from_json_string(read_string(pc_path)), raw);
for(auto& [k, v] : raw)
{
auto projected = create_key(k.at("name").to<std::string>(), k.at("problem"));
cache[projected] = v;
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread src/targets/gpu/problem_cache.cpp
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4835      +/-   ##
===========================================
+ Coverage    92.86%   92.88%   +0.01%     
===========================================
  Files          586      587       +1     
  Lines        30287    30331      +44     
===========================================
+ Hits         28126    28170      +44     
  Misses        2161     2161              

see 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@danieyan-amd danieyan-amd marked this pull request as ready for review May 7, 2026 19:34
{
auto projected = create_key(k.at("name").to<std::string>(), k.at("problem"));
cache[projected] = v;
}
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.

Make an extra copy can get slow with larger problem caches.

@pfultz2
Copy link
Copy Markdown
Collaborator

pfultz2 commented May 8, 2026

I think the metadata should be managed externally. In the future, we may use sqlite dbs to manage problem caches which may not be efficient to insert metadata like this.

@tperry-amd
Copy link
Copy Markdown
Contributor

I think the metadata should be managed externally. In the future, we may use sqlite dbs to manage problem caches which may not be efficient to insert metadata like this.

Do you mind if we move forward with the code as it is and optimize if it becomes a problem? We just want to incrementally improve the code and build up the database and caching logic. If it becomes a performance issue, we will optimize it since we are focusing on time-to-first-inference right now.

@pfultz2
Copy link
Copy Markdown
Collaborator

pfultz2 commented May 19, 2026

Do you mind if we move forward with the code as it is and optimize if it becomes a problem?

I dont understand why this is needed. I would like to keep the code as simple as possible so it easier to update with newer features in the future such as multi-targets, multi-file, sqlite, etc.

@tperry-amd
Copy link
Copy Markdown
Contributor

I dont understand why this is needed. I would like to keep the code as simple as possible so it easier to update with newer features in the future such as multi-targets, multi-file, sqlite, etc.

It's needed so that we can create problem cache databases that span different GPU's and GPU configurations. It will start off simple by selecting a single matching problem if there are multiple different matching hardware configurations but we plan to make the algorithm have better selection login in the future as our data improves. This is so that we can start collecting the data and work on building the database.

Our next update will actually be adding multi-targets and sqlite support. Daniel has also been profiling different backend support and will be providing an abstraction interface to allow interchangeable backends for logging problem cache data.

We need this change so we don't need to redo all the data collection work in the future when we want to select better solution when the hardware configuration changes but has the same gfx arch.

@pfultz2
Copy link
Copy Markdown
Collaborator

pfultz2 commented May 19, 2026

It's needed so that we can create problem cache databases that span different GPU's and GPU configurations.

Well this is not the way we would approach this. We would make the device a key. So instead of it being std::unordered_map<value, value> it would be std::unordered_map<std::string, std::unordered_map<value, value>> or std::unordered_map<value, std::unordered_map<value, value>>.

will be providing an abstraction interface

Make sure to use type erasure instead of inheritance for this.

@danieyan-amd
Copy link
Copy Markdown
Author

It's needed so that we can create problem cache databases that span different GPU's and GPU configurations.

Well this is not the way we would approach this. We would make the device a key. So instead of it being std::unordered_map<value, value> it would be std::unordered_map<std::string, std::unordered_map<value, value>> or std::unordered_map<value, std::unordered_map<value, value>>.

will be providing an abstraction interface

Make sure to use type erasure instead of inheritance for this.

I can look into this, and make the necessary changes

Addresses PR review feedback:
- Device (gpu_arch|cu_count|wavefront_size) used as composite cache key
- Type-erased problem_cache_backend wrapper (no virtual inheritance)
- JSON backend as default implementation
- load()/save() in problem_cache rewritten to use backend abstraction
@danieyan-amd danieyan-amd force-pushed the feature/problem-cache-schema-extension branch from 4b65154 to 3a47ddc Compare May 20, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants