-
Notifications
You must be signed in to change notification settings - Fork 329
[hipDNN] Plugin SDK + Device Properties Infrastructure (RFC 0007 - Part 1/3) #6467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cderb
merged 44 commits into
develop
from
users/cderb/rfc0007/pr1-plugin-sdk-infrastructure
Apr 23, 2026
Merged
Changes from 15 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
37111be
[hipDNN] Plugin SDK + Device Properties Infrastructure (RFC 0007 - Pa…
cderb 1e54ffb
Fix RFC references to include RFC 0007 prefix
cderb 1e19a4d
Add missing HipdnnException.hpp include to TestDeviceProperties
cderb 18d094a
Add RFC 0007 documentation
cderb 49f6188
Apply code quality and ABI fixes to PR1 Plugin SDK infrastructure
cderb 5856d6e
Add unit tests for RFC 0007 Part 1 Plugin SDK infrastructure
cderb 2da1d23
formatting corrections
cderb 853b064
Fix pre-commit hook failures
cderb 05af187
fix generated files
cderb 78bd506
Merge remote-tracking branch 'origin/develop' into users/cderb/rfc000…
cderb 5ff2578
add more coverage tests
cderb f1c3f8e
format on test files
cderb 98b1892
Add comprehensive HeuristicPlugin test coverage
cderb e2a17a6
Fixed race condition in heuristic plugin initialization.
cderb 5947d05
format
cderb 35c2155
reorganize heuristic plugin tests, reduce test files, add to plugin m…
cderb aeb7d54
remove special unicode characters
cderb 359c8aa
Require policy names and compute policy IDs from names
cderb 59a692c
Add architectureName to device properties for LLVM architecture support
cderb 6a24652
revert EngineOrdering changes, will re-investigate need in part 2
cderb c40cf35
format
cderb b8c2eda
format
cderb e98e1a6
fix directory resolution for heuristic plugin ci test
cderb 08429e3
nolints
cderb 4187f50
format
cderb 0dde900
Merge remote-tracking branch 'origin/develop' into users/cderb/rfc000…
cderb 1b97bb9
addressing reviews
cderb cc61d02
use weak ptr to track heuristic plugin manager resources
cderb 59e6ae6
format
cderb bb298a7
remove heuristicLoggingCallback and use backendLoggingCallback directly
cderb 94b9680
update patch version
cderb d9763c2
makelist corrections
cderb ee29b1c
corrections for MockHeuristicPlugin, add virtual to HeuristicPlugin m…
cderb 348e797
review comments
cderb 7e837d2
add PluginResourceManagerBase
cderb 9145dbb
format
cderb 86f19ad
windows test fix
cderb 45d57b3
refactor HeuristicsPluginApi to extend PluginApi
cderb f14da60
windows friendly test paths
cderb 72a83c0
fix test
cderb 3eb163b
Fix test for windows path names
jdcampbe 2917710
Fix SharedLibrary move losing _libraryPath after std::move
jdcampbe 8f674e6
format
cderb 4a1bb70
tidy fix
cderb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
projects/hipdnn/backend/src/heuristics/DeviceProperties.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright © Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "DeviceProperties.hpp" | ||
|
|
||
| #include <hip/hip_runtime.h> | ||
|
|
||
| #include <flatbuffers/flatbuffers.h> | ||
| #include <flatbuffers/verifier.h> | ||
|
|
||
| #include "HipdnnException.hpp" | ||
| #include "logging/Logging.hpp" | ||
|
|
||
| // Include generated FlatBuffer header | ||
| #include <hipdnn_data_sdk/data_objects/device_properties_generated.h> | ||
|
|
||
| namespace hipdnn_backend::heuristics | ||
| { | ||
|
|
||
| DeviceProperties queryDeviceProperties() | ||
| { | ||
| DeviceProperties out{}; | ||
|
|
||
| // Get current device | ||
| int device = 0; | ||
| hipError_t err = hipGetDevice(&device); | ||
| if(err != hipSuccess) | ||
| { | ||
| HIPDNN_BACKEND_LOG_WARN("hipGetDevice failed: {}. Using default device properties.", | ||
| hipGetErrorString(err)); | ||
| return out; | ||
| } | ||
| out.deviceId = device; | ||
|
|
||
| // Get device properties | ||
| hipDeviceProp_t hipProps{}; | ||
| err = hipGetDeviceProperties(&hipProps, device); | ||
| if(err != hipSuccess) | ||
| { | ||
| HIPDNN_BACKEND_LOG_WARN( | ||
| "hipGetDeviceProperties failed: {}. Using partial device properties.", | ||
| hipGetErrorString(err)); | ||
| return out; | ||
| } | ||
|
|
||
| out.multiProcessorCount = hipProps.multiProcessorCount; | ||
| out.totalGlobalMem = hipProps.totalGlobalMem; | ||
|
|
||
| HIPDNN_BACKEND_LOG_DEBUG( | ||
| "Queried device properties: deviceId={}, multiProcessorCount={}, totalGlobalMem={} bytes", | ||
| out.deviceId, | ||
| out.multiProcessorCount, | ||
| out.totalGlobalMem); | ||
|
|
||
| return out; | ||
| } | ||
|
|
||
| std::vector<uint8_t> serializeDeviceProperties(const DeviceProperties& props) | ||
| { | ||
| flatbuffers::FlatBufferBuilder builder(256); | ||
|
|
||
| // Build the DeviceProperties table | ||
| auto devicePropsOffset = hipdnn_data_sdk::data_objects::CreateDeviceProperties( | ||
| builder, props.deviceId, props.multiProcessorCount, props.totalGlobalMem); | ||
|
|
||
| builder.Finish(devicePropsOffset, "HDDP"); // File identifier for versioning | ||
|
|
||
| // Copy to vector | ||
| uint8_t* buf = builder.GetBufferPointer(); | ||
| const size_t size = builder.GetSize(); | ||
| return {buf, buf + size}; | ||
| } | ||
|
|
||
| DeviceProperties deserializeDeviceProperties(const uint8_t* buffer, size_t size) | ||
| { | ||
| THROW_IF_FALSE(buffer != nullptr, | ||
| HIPDNN_STATUS_BAD_PARAM_NULL_POINTER, | ||
| "Device properties buffer cannot be null"); | ||
| THROW_IF_FALSE(size > 0, HIPDNN_STATUS_BAD_PARAM, "Device properties buffer size must be > 0"); | ||
|
|
||
| // Verify the buffer | ||
| flatbuffers::Verifier verifier(buffer, size); | ||
| if(!verifier.VerifyBuffer<hipdnn_data_sdk::data_objects::DeviceProperties>("HDDP")) | ||
| { | ||
| throw HipdnnException(HIPDNN_STATUS_BAD_PARAM, | ||
| "Invalid device properties buffer: failed FlatBuffer verification"); | ||
| } | ||
|
|
||
| // Get the root table | ||
| auto devicePropsFB = hipdnn_data_sdk::data_objects::GetDeviceProperties(buffer); | ||
| if(devicePropsFB == nullptr) | ||
| { | ||
| throw HipdnnException(HIPDNN_STATUS_INTERNAL_ERROR, | ||
| "Failed to get DeviceProperties root table"); | ||
| } | ||
|
|
||
| // Extract fields | ||
| DeviceProperties props; | ||
| props.deviceId = devicePropsFB->device_id(); | ||
| props.multiProcessorCount = devicePropsFB->multi_processor_count(); | ||
| props.totalGlobalMem = devicePropsFB->total_global_mem(); | ||
|
|
||
| return props; | ||
| } | ||
|
|
||
| } // namespace hipdnn_backend::heuristics |
101 changes: 101 additions & 0 deletions
101
projects/hipdnn/backend/src/heuristics/DeviceProperties.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Copyright © Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include <hipdnn_plugin_sdk/PluginApiDataTypes.h> | ||
|
|
||
| namespace hipdnn_backend::heuristics | ||
| { | ||
|
|
||
| /** | ||
| * @brief Device properties for heuristic plugin selection. | ||
| * | ||
| * This structure carries device facts needed for engine selection heuristics. | ||
| * It is filled by the backend (via queryDeviceProperties() or descriptor override) | ||
| * and serialized to FlatBuffer format before being passed to heuristic plugins. | ||
| * | ||
| * RFC 0007 Reference: Section 6.1 | ||
| */ | ||
| struct DeviceProperties | ||
|
cderb marked this conversation as resolved.
Outdated
cderb marked this conversation as resolved.
Outdated
|
||
| { | ||
| int deviceId = -1; ///< Device ID from hipGetDevice | ||
| int multiProcessorCount = 0; ///< Number of multiprocessors (compute units) | ||
| size_t totalGlobalMem = 0; ///< Total global memory in bytes | ||
|
|
||
| // Future optional fields can be added here and to the FlatBuffer schema | ||
| // Example: std::string architectureName; | ||
| // Example: int wavefrontSize = 0; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Query device properties from HIP. | ||
| * | ||
| * Calls hipGetDevice() and hipGetDeviceProperties() to obtain current | ||
| * device information. This is the default acquisition method when no | ||
| * descriptor override is provided. | ||
| * | ||
| * Plugins must NOT call this function. They receive serialized device | ||
| * properties via hipdnnHeuristicHandleSetDeviceProperties. | ||
| * | ||
| * RFC 0007 Reference: Section 6.2 | ||
| * | ||
| * @return DeviceProperties populated from HIP, or default values on error. | ||
| */ | ||
| DeviceProperties queryDeviceProperties(); | ||
|
|
||
| /** | ||
| * @brief Serialize DeviceProperties to FlatBuffer format. | ||
| * | ||
| * Builds a FlatBuffer-serialized representation of the device properties | ||
| * using the schema from data_sdk/schemas/device_properties.fbs. | ||
| * | ||
| * The returned buffer is owned by the caller and must remain valid while | ||
| * any hipdnnPluginConstData_t wrappers pointing to it are in use. | ||
| * | ||
| * RFC 0007 Reference: Section 13.2 | ||
| * | ||
| * @param props Device properties to serialize. | ||
| * @return Vector containing the serialized FlatBuffer bytes. | ||
| */ | ||
| std::vector<uint8_t> serializeDeviceProperties(const DeviceProperties& props); | ||
|
|
||
| /** | ||
| * @brief Deserialize DeviceProperties from FlatBuffer format. | ||
| * | ||
| * Verifies and parses a FlatBuffer-serialized device properties buffer. | ||
| * Throws HipdnnException if the buffer is malformed or incompatible. | ||
| * | ||
| * This is primarily for testing and backend internal use. Plugins should | ||
| * use the generated FlatBuffer accessors directly. | ||
| * | ||
| * @param buffer Pointer to serialized FlatBuffer bytes. | ||
| * @param size Size of the buffer in bytes. | ||
| * @return DeviceProperties deserialized from the buffer. | ||
| * @throws HipdnnException if buffer is invalid. | ||
| */ | ||
| DeviceProperties deserializeDeviceProperties(const uint8_t* buffer, size_t size); | ||
|
|
||
| /** | ||
| * @brief Wrap serialized device properties in hipdnnPluginConstData_t. | ||
| * | ||
| * Creates a hipdnnPluginConstData_t wrapper pointing to the serialized buffer. | ||
| * The buffer must remain valid while the wrapper is in use. | ||
| * | ||
| * @param serializedBuffer Reference to the serialized buffer (must outlive the wrapper). | ||
| * @return hipdnnPluginConstData_t wrapper pointing to the buffer. | ||
| */ | ||
| inline hipdnnPluginConstData_t | ||
| wrapSerializedDeviceProperties(const std::vector<uint8_t>& serializedBuffer) | ||
| { | ||
| hipdnnPluginConstData_t wrapper; | ||
| wrapper.ptr = serializedBuffer.data(); | ||
| wrapper.size = serializedBuffer.size(); | ||
| return wrapper; | ||
| } | ||
|
|
||
| } // namespace hipdnn_backend::heuristics | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.