Skip to content

Comments

[TE/HIP] Support ROCm 7.1+ hipMemImportFromShareableHandle signature change#1550

Open
amd-arozanov wants to merge 3 commits intokvcache-ai:mainfrom
amd-arozanov:arozanov/hipMemImportFromShareableHandle
Open

[TE/HIP] Support ROCm 7.1+ hipMemImportFromShareableHandle signature change#1550
amd-arozanov wants to merge 3 commits intokvcache-ai:mainfrom
amd-arozanov:arozanov/hipMemImportFromShareableHandle

Conversation

@amd-arozanov
Copy link
Collaborator

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

  • Types
    • Bug fix
    • New feature
      • Transfer Engine
      • Mooncake Store
      • Mooncake EP
      • Integration
      • P2P Store
      • Python Wheel
    • Breaking change
    • CI/CD
    • Documentation update
    • Other

How Has This Been Tested?

Checked that transfer_engine_bench works fine with different ROCm versions (7.0, 7.1 and 7.2)

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • [] I have updated the documentation.
  • [] I have added tests to prove my changes are effective.

…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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 hipMemImportFromShareableHandle function. It introduces a compatibility layer within the HIP transport mechanism to ensure that memory import operations function correctly across different ROCm runtime versions. This change ensures the transfer engine's stability and functionality when interacting with varying ROCm environments.

Highlights

  • ROCm 7.1+ hipMemImportFromShareableHandle Signature Change: The hipMemImportFromShareableHandle function's second argument changed from a pointer to a value in ROCm 7.1 and later versions, requiring an adaptation for compatibility.
  • Version-Aware Wrapper Function: A new static helper function, importFromShareableHandle, was introduced to dynamically check the ROCm runtime version and call hipMemImportFromShareableHandle with the correct signature, ensuring backward and forward compatibility.
  • transfer_engine_bench Example Update: The transfer_engine_bench example was updated to correctly associate the 'hip' protocol with the nvlink condition when allocating and freeing fabric memory, ensuring USE_MNNVL is properly required.

🧠 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
  • mooncake-transfer-engine/example/transfer_engine_bench.cpp
    • Updated allocateMemoryPool to include 'hip' protocol in the nvlink condition for USE_MNNVL requirement.
    • Updated freeMemoryPool to include 'hip' protocol in the nvlink condition for USE_MNNVL requirement.
  • mooncake-transfer-engine/src/transport/hip_transport/hip_transport.cpp
    • Added a new static helper function importFromShareableHandle to abstract the hipMemImportFromShareableHandle call based on ROCm runtime version.
    • Replaced direct calls to hipMemImportFromShareableHandle with the new importFromShareableHandle wrapper.
Activity
  • The author performed a self-review of the code.
  • The code was formatted using ./scripts/code_format.sh.
  • Testing was conducted to ensure transfer_engine_bench works correctly with ROCm versions 7.0, 7.1, and 7.2.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 81 to 101
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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);
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants