Commit 4e68c93
Frontend Heuristic Policy Enumeration API (RFC 0007 - Part 3/3) (ROCm#6757)
## Overview
This PR completes the three-part implementation of RFC 0007 by adding
**frontend C++ wrapper APIs** for heuristic policy enumeration. It
provides a user-friendly interface for applications to discover and
inspect loaded heuristic policies at runtime, enabling diagnostics,
logging, and understanding of engine selection behavior.
**PR Series:**
- **PR1:** Plugin SDK Infrastructure
(`users/cderb/rfc0007/pr1-plugin-sdk-infrastructure`)
- **PR2:** Heuristic Framework + Default Plugins
(`users/cderb/rfc0007/pr2-heuristic-framework-plugins`)
- **PR3:** Frontend Wrapper API
(`users/cderb/rfc0007/pr3-frontend-wrapper-clean`) <-- **This PR**
---
## What's New in PR3
### 1. Frontend Policy Enumeration API
**New Header:**
`frontend/include/hipdnn_frontend/HeuristicPolicyInfo.hpp`
Provides a clean C++ interface to query loaded heuristic policies:
```cpp
#include <hipdnn_frontend/HeuristicPolicyInfo.hpp>
auto [handle, err] = hipdnn_frontend::createHipdnnHandle();
// Query all loaded heuristic policies
auto [policies, err2] = hipdnn_frontend::getLoadedHeuristicPolicyInfos(*handle);
for (const auto& policy : policies) {
std::cout << "Policy: " << policy.policyName
<< " (ID: " << policy.policyId << ")"
<< " Version: " << policy.pluginVersion
<< " API: " << policy.apiVersion << std::endl;
}
```
**Output Example:**
```
Policy: SelectionHeuristic::Config (ID: -7234567890123456789) Version: 1.0.0 API: 0.0.1
Policy: SelectionHeuristic::StaticOrdering (ID: -1234567890123456789) Version: 1.0.0 API: 0.0.1
```
### 2. Backend C API Extensions
**New Functions in `hipdnn_backend.h`:**
```c
// Get count of loaded heuristic policies
hipdnnStatus_t hipdnnGetHeuristicPolicyCount_ext(
hipdnnHandle_t handle,
size_t* numPolicies);
// Query policy metadata by index (two-call pattern for strings)
hipdnnStatus_t hipdnnGetHeuristicPolicyInfo_ext(
hipdnnHandle_t handle,
size_t index,
int64_t* policyId,
char* policyName,
size_t* policyNameLen,
char* pluginVersion,
size_t* pluginVersionLen,
char* apiVersion,
size_t* apiVersionLen);
```
### 3. DeviceProperties Helper Functions
**New Files:**
- `backend/src/heuristics/DeviceProperties.hpp`
- `backend/src/heuristics/DeviceProperties.cpp`
Provides utility functions for heuristic policy plugins:
```cpp
// Query device properties from HIP
hipdnn_flatbuffers_sdk::data_objects::DevicePropertiesT
queryDeviceProperties();
// Serialize device properties to FlatBuffer
std::vector<uint8_t>
serializeDeviceProperties(const DevicePropertiesT& props);
// Wrap serialized buffer in plugin data structure
hipdnnPluginConstData_t
wrapSerializedDeviceProperties(const std::vector<uint8_t>& serializedBuffer);
```
**Usage in Backend:**
```cpp
// Query and serialize device properties
auto devProps = queryDeviceProperties();
auto serialized = serializeDeviceProperties(devProps);
auto wrapper = wrapSerializedDeviceProperties(serialized);
// Pass to heuristic plugin
hipdnnHeuristicHandleSetDeviceProperties(pluginHandle, &wrapper);
```
---
## Files Changed
### New Files (5)
1. **Frontend API:**
- `frontend/include/hipdnn_frontend/HeuristicPolicyInfo.hpp` - Policy
enumeration API
2. **Backend Helpers:**
- `backend/src/heuristics/DeviceProperties.hpp` - Device properties
utilities (header)
- `backend/src/heuristics/DeviceProperties.cpp` - Device properties
utilities (impl)
3. **Tests:**
- `frontend/tests/TestHeuristicPolicyEnumeration.cpp` - Frontend API
tests (12 tests)
4. **Mock Backend:**
- (Updates to existing mock for testing)
### Modified Files (4)
1. **Backend Wrappers:**
- `frontend/include/hipdnn_frontend/detail/BackendWrapper.hpp` - Add
policy query wrappers
- `frontend/include/hipdnn_frontend/detail/HipdnnBackendInterface.hpp` -
Add virtual methods
- `frontend/include/hipdnn_frontend/detail/IncompatibleBackend.hpp` -
Graceful degradation
2. **Test Configuration:**
- `frontend/tests/CMakeLists.txt` - Register new test file
3. **Mock Backend:**
- `frontend/tests/fake_backend/MockHipdnnBackend.hpp` - Implement mock
policy queries
**Total: 9 files changed (+583 lines, -83 lines)**
---
## Testing
### Frontend Tests (12 tests)
**File:** `frontend/tests/TestHeuristicPolicyEnumeration.cpp`
12 tests covering basic enumeration, metadata validation, default policy
presence, and integration scenarios.
### Integration with PR2 Tests
PR3 builds on PR2's comprehensive backend tests (178+ tests):
- [x] Policy loading and validation
- [x] Outer loop orchestration
- [x] Device properties serialization
- [x] Default policies (Config, StaticOrdering)
**Combined Test Coverage: 190+ tests**
---
## RFC 0007 Compliance
### Section 16: Frontend API Flow
**RFC Requirements:**
> "Frontend should expose an enumeration API similar to engine config
enumeration:
>
> - `getLoadedHeuristicPolicyInfos(hipdnnHandle_t)` returns policy
metadata
> - Policy ID (int64_t)
> - Policy name (UTF-8 string)
> - Plugin version
> - API version"
**Implementation Status:**
- [x] Frontend function `getLoadedHeuristicPolicyInfos()` implemented
- [x] Backend C API `hipdnnGetHeuristicPolicyCount_ext()` implemented
- [x] Backend C API `hipdnnGetHeuristicPolicyInfo_ext()` implemented
- [x] `HeuristicPolicyInfo` struct with all required fields
- [x] Two-call pattern for string sizing (matches engine config pattern)
- [x] Error handling via frontend `Error` type
- [x] Works before graph creation (as required)
---
## Design Decisions
### DeviceProperties Helper Functions
While RFC 0007 specifies device properties serialization for plugins,
PR3 adds reusable helper functions to avoid code duplication:
```cpp
queryDeviceProperties() // Query from HIP
serializeDeviceProperties() // Convert to FlatBuffer
wrapSerializedDeviceProperties() // Wrap in C API struct
```
These provide a reference implementation for custom plugin developers
and maintain FlatBuffer encapsulation without exposing POD structs
across the ABI boundary.
---
## Integration with PR1 & PR2
### From PR1 (Plugin SDK):
- [x] Uses `HeuristicsPluginApi.h` C ABI definitions
- [x] Relies on two-tier plugin architecture (handle + descriptor)
### From PR2 (Heuristic Framework):
- [x] Queries
`HeuristicPluginResourceManager::getHeuristicPolicyInfos()`
- [x] Enumerates policies loaded via `HeuristicPluginManager`
- [x] Accesses default policies (Config, StaticOrdering)
### New in PR3:
- [x] Frontend C++ wrapper API
- [x] Backend C API extensions (`hipdnnGetHeuristicPolicy*_ext`)
- [x] DeviceProperties helper utilities
- [x] Frontend integration tests
---
## Summary
PR3 completes RFC 0007 by adding frontend policy enumeration and device
properties helpers. **Combined with PR1 and PR2, RFC 0007 is now fully
implemented.**
---
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jason Campbell <jascampb@amd.com>
Co-authored-by: Claude Filter Strategist <claude@anthropic.com>1 parent fb8d081 commit 4e68c93
20 files changed
Lines changed: 1325 additions & 74 deletions
File tree
- projects/hipdnn
- backend
- src
- descriptors
- heuristics
- tests
- descriptors
- heuristics
- data_sdk/include/hipdnn_data_sdk/utilities
- frontend
- include
- hipdnn_frontend
- detail
- tests
- fake_backend
- tests/frontend
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
Lines changed: 6 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
| |||
207 | 205 | | |
208 | 206 | | |
209 | 207 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
247 | 213 | | |
248 | 214 | | |
249 | 215 | | |
| |||
Lines changed: 64 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
Lines changed: 88 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
Lines changed: 11 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | | - | |
35 | | - | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 47 | + | |
| 48 | + | |
57 | 49 | | |
58 | 50 | | |
59 | 51 | | |
| |||
172 | 164 | | |
173 | 165 | | |
174 | 166 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 167 | + | |
| 168 | + | |
179 | 169 | | |
180 | 170 | | |
181 | 171 | | |
| |||
193 | 183 | | |
194 | 184 | | |
195 | 185 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 186 | + | |
| 187 | + | |
200 | 188 | | |
201 | 189 | | |
202 | 190 | | |
| |||
226 | 214 | | |
227 | 215 | | |
228 | 216 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 217 | + | |
| 218 | + | |
233 | 219 | | |
234 | 220 | | |
235 | 221 | | |
| |||
463 | 449 | | |
464 | 450 | | |
465 | 451 | | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
| 452 | + | |
| 453 | + | |
470 | 454 | | |
471 | 455 | | |
472 | 456 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
0 commit comments