[TE/HIP] Support ROCm 7.1+ hipMemImportFromShareableHandle signature change#1550
[TE/HIP] Support ROCm 7.1+ hipMemImportFromShareableHandle signature change#1550amd-arozanov wants to merge 3 commits intokvcache-ai:mainfrom
Conversation
…ine_bench - Update allocateMemoryPool to handle both nvlink and hip protocols - Update freeMemoryPool to handle both nvlink and hip protocols - Both protocols now use allocateFabricMemory/freeFabricMemory when USE_MNNVL is enabled
Summary of ChangesHello @amd-arozanov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a breaking API change in ROCm 7.1 and later versions concerning the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for a signature change in hipMemImportFromShareableHandle for ROCm 7.1+ by introducing a version-aware wrapper function. The changes look good and correctly address the compatibility issue. I've found one potential issue regarding thread-safety in the version caching mechanism and suggested a more robust implementation using modern C++ features. Please see the detailed comment.
| static int cached_version = -1; | ||
|
|
||
| if (cached_version < 0) { | ||
| int runtime_version = 0; | ||
| if (!checkHip(hipRuntimeGetVersion(&runtime_version), | ||
| "HipTransport: hipRuntimeGetVersion failed")) { | ||
| return hipErrorInvalidValue; | ||
| } | ||
| cached_version = runtime_version; | ||
| } | ||
|
|
||
| int runtime_version = cached_version; | ||
|
|
||
| if (runtime_version >= 70100000) { | ||
| return hipMemImportFromShareableHandle( | ||
| handle, (void *)(uintptr_t)export_handle->fd, | ||
| HIPX_MEM_HANDLE_TYPE_FABRIC); | ||
| } else { | ||
| return hipMemImportFromShareableHandle(handle, export_handle, | ||
| HIPX_MEM_HANDLE_TYPE_FABRIC); | ||
| } |
There was a problem hiding this comment.
The current implementation for caching the ROCm version is not thread-safe. If multiple threads call this function for the first time concurrently, it can lead to a race condition when reading and writing cached_version. This can result in hipRuntimeGetVersion being called multiple times unnecessarily.
A cleaner and thread-safe way to achieve this since C++11 is to use a static local variable initialized by a lambda. This ensures the version is fetched only once in a thread-safe manner.
static const int runtime_version = []() {
int version = 0;
if (!checkHip(hipRuntimeGetVersion(&version),
"HipTransport: hipRuntimeGetVersion failed")) {
return -1;
}
return version;
}();
if (runtime_version < 0) {
return hipErrorInvalidValue;
}
if (runtime_version >= 70100000) {
return hipMemImportFromShareableHandle(
handle, (void *)(uintptr_t)export_handle->fd,
HIPX_MEM_HANDLE_TYPE_FABRIC);
} else {
return hipMemImportFromShareableHandle(handle, export_handle,
HIPX_MEM_HANDLE_TYPE_FABRIC);
}|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
hipMemImportFromShareableHandle was changed in ROCm 7.1. Now the second argument should be provided by value instead of pointer.
Added importFromShareableHandle function, which checks ROCm version and calls hipMemImportFromShareableHandle accordantly.
Type of Change
How Has This Been Tested?
Checked that transfer_engine_bench works fine with different ROCm versions (7.0, 7.1 and 7.2)
Checklist
./scripts/code_format.shbefore submitting.