Skip to content

[PG] force register local memory for P2P memory regions#1690

Merged
UNIDY2002 merged 1 commit intomainfrom
sunxun/fix
Mar 18, 2026
Merged

[PG] force register local memory for P2P memory regions#1690
UNIDY2002 merged 1 commit intomainfrom
sunxun/fix

Conversation

@UNIDY2002
Copy link
Copy Markdown
Collaborator

Description

Similar to #1656.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Other

How Has This Been Tested?

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 bug in the PyTorch Backend (mooncake-pg) by enhancing the P2P memory registration mechanism. It ensures that local memory regions used for P2P communication are registered with a specific location, moving away from a wildcard approach. This change aims to improve the precision and correctness of memory management for P2P operations, aligning with best practices for distributed memory handling.

Highlights

  • P2P Memory Registration: Introduced a location field to the P2PProxy::Options and P2PProxy class to specify the memory region for P2P operations.
  • Specific Location Usage: Modified the registerLocalMemory calls within P2PProxy to use the newly added location_ member instead of a generic kWildcardLocation for both CPU and CUDA memory buffers and control regions.

🧠 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.

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.

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
Copy Markdown
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 introduces a location parameter to force registration of local memory for P2P memory regions with a specific location, instead of using a wildcard. The changes are straightforward and correctly implement the intended logic by passing the location from the MooncakeBackend down to the P2PProxy where it's used for memory registration.

My main feedback is regarding code formatting consistency. While the code was likely auto-formatted, there are some inconsistencies in how function calls are wrapped. I've added specific suggestions to improve readability and maintain a consistent style. Overall, the changes are good.

Comment on lines +75 to +76
int rc = engine_->registerLocalMemory(resources_.send_buffer_,
kP2PTotalBufferSize, location_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and maintain consistency, please consider reformatting this function call. The formatting of registerLocalMemory calls has become inconsistent in this file. This comment applies to other similar calls in this file.

Suggested change
int rc = engine_->registerLocalMemory(resources_.send_buffer_,
kP2PTotalBufferSize, location_);
int rc = engine_->registerLocalMemory(
resources_.send_buffer_, kP2PTotalBufferSize, location_);

Comment on lines +82 to +83
rc = engine_->registerLocalMemory(resources_.recv_buffer_,
kP2PTotalBufferSize, location_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please reformat for consistency, as mentioned in the previous comment.

Suggested change
rc = engine_->registerLocalMemory(resources_.recv_buffer_,
kP2PTotalBufferSize, location_);
rc = engine_->registerLocalMemory(
resources_.recv_buffer_, kP2PTotalBufferSize, location_);

Comment on lines +93 to +94
int rc = engine_->registerLocalMemory(resources_.send_buffer_,
kP2PTotalBufferSize, location_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please reformat for consistency, as mentioned in the previous comments.

Suggested change
int rc = engine_->registerLocalMemory(resources_.send_buffer_,
kP2PTotalBufferSize, location_);
int rc = engine_->registerLocalMemory(
resources_.send_buffer_, kP2PTotalBufferSize, location_);

Comment on lines +100 to +101
rc = engine_->registerLocalMemory(resources_.recv_buffer_,
kP2PTotalBufferSize, location_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please reformat for consistency, as mentioned in the previous comments.

Suggested change
rc = engine_->registerLocalMemory(resources_.recv_buffer_,
kP2PTotalBufferSize, location_);
rc = engine_->registerLocalMemory(
resources_.recv_buffer_, kP2PTotalBufferSize, location_);

Comment on lines 154 to +156
int rc = engine_->registerLocalMemory(resources_.ctrl_send_region_,
kMaxNumRanks * sizeof(P2PControlSlot),
kWildcardLocation);
location_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please reformat for consistency. This formatting is also inconsistent with other calls in this file (e.g. line 75).

Suggested change
int rc = engine_->registerLocalMemory(resources_.ctrl_send_region_,
kMaxNumRanks * sizeof(P2PControlSlot),
kWildcardLocation);
location_);
int rc = engine_->registerLocalMemory(
resources_.ctrl_send_region_,
kMaxNumRanks * sizeof(P2PControlSlot),
location_);

Comment on lines 159 to +161
rc = engine_->registerLocalMemory(resources_.ctrl_recv_region_,
kMaxNumRanks * sizeof(P2PControlSlot),
kWildcardLocation);
location_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please reformat for consistency, as mentioned in the previous comments.

Suggested change
rc = engine_->registerLocalMemory(resources_.ctrl_recv_region_,
kMaxNumRanks * sizeof(P2PControlSlot),
kWildcardLocation);
location_);
rc = engine_->registerLocalMemory(
resources_.ctrl_recv_region_,
kMaxNumRanks * sizeof(P2PControlSlot),
location_);

@codecov-commenter
Copy link
Copy Markdown

⚠️ 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!

Copy link
Copy Markdown
Collaborator

@ympcMark ympcMark left a comment

Choose a reason for hiding this comment

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

LGTM

@UNIDY2002 UNIDY2002 merged commit 47b016d into main Mar 18, 2026
18 of 19 checks passed
@UNIDY2002 UNIDY2002 deleted the sunxun/fix branch March 18, 2026 08:20
whn09 pushed a commit to whn09/Mooncake that referenced this pull request Apr 4, 2026
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.

3 participants