Skip to content

fix: fix heterogeneous rdma transport error#1657

Merged
stmatengss merged 9 commits into
kvcache-ai:mainfrom
XingSong-Sun:main
Mar 17, 2026
Merged

fix: fix heterogeneous rdma transport error#1657
stmatengss merged 9 commits into
kvcache-ai:mainfrom
XingSong-Sun:main

Conversation

@XingSong-Sun
Copy link
Copy Markdown
Contributor

Description

修复异构RDMA Transport对cpu memory的判断错误导致的NPU报错问题

@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!

此拉取请求旨在解决异构RDMA传输中一个关键的内存识别问题。通过修正 isCpuMemory 函数的判断逻辑,确保系统能够准确区分CPU内存和设备内存,从而避免了因内存类型误判而导致的NPU错误。此外,还更新了示例配置以包含NPU设备,并调整了类之间的友元关系以支持这些更改。

Highlights

  • 修复异构RDMA传输错误: 解决了异构RDMA Transport对CPU内存判断不准确导致NPU报错的问题。
  • 内存判断逻辑优化: 更新了 isCpuMemory 函数的逻辑,使其在 aclrtPointerGetAttributes 调用失败时,或当 location.type 不为1(设备内存)时,能正确地将内存识别为CPU内存。
  • NPU设备配置: 在示例配置文件中,为 nicPriorityMatrix 添加了 npu:0 条目。
  • 类友元关系: 将 HeterogeneousRdmaTransport 类声明为 RdmaTransport 类的友元。

🧠 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_heterogeneous_ascend_perf_initiator.cpp
    • 为NIC优先级矩阵添加了NPU设备配置。
  • mooncake-transfer-engine/include/transport/rdma_transport/rdma_transport.h
    • HeterogeneousRdmaTransport 声明为 RdmaTransport 的友元类。
  • mooncake-transfer-engine/src/transport/ascend_transport/heterogeneous_rdma_transport/heterogeneous_rdma_transport.cpp
    • 修正了 isCpuMemory 函数的逻辑,以正确处理 aclrtPointerGetAttributes 失败的情况,并根据 location.type 准确判断CPU内存。
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
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 fixes an issue with heterogeneous RDMA transport where CPU memory was being incorrectly identified, leading to NPU errors. The main change is in isCpuMemory to correctly classify memory types. Additionally, a test file is updated to include NPU devices, and a header file is modified to add a friend class declaration. My review focuses on improving code clarity and correctness.

Comment on lines +9 to +13
if (int ret = aclrtPointerGetAttributes(addr, &attributes)) {
LOG(ERROR) << "aclrtPointrtGetAttributes error, ret: " << ret;
return false;
// If ACL cannot identify the pointer, it is not ACL-managed device
// memory, so treat it as regular CPU memory.
LOG(WARNING) << "aclrtPointerGetAttributes failed for addr " << addr
<< ", ret: " << ret
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.

high

The logic for determining if a memory address belongs to the CPU has been updated. The previous implementation only checked for ACL_HOST memory (type == 0) and incorrectly returned false on aclrtPointerGetAttributes failure. The new logic correctly treats any memory that is not explicitly device memory (type != 1) as CPU memory. This includes ACL_HOST memory (type == 0), regular CPU memory (type == 2), and cases where aclrtPointerGetAttributes fails. This change is crucial for correctness.

Comment on lines +162 to +164
"], []], " " \"npu:0\": [["
+ device_names +
"], []], " " \"cuda:0\": [[" +
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

The string concatenation for adding the npu:0 entry has inconsistent formatting, which makes the code harder to read. Please reformat this section for better clarity and consistency with the surrounding code.

Suggested change
"], []], " " \"npu:0\": [["
+ device_names +
"], []], " " \"cuda:0\": [[" +
"], []], "
" \"npu:0\": [[" +
device_names +
"], []], "
" \"cuda:0\": [[" +

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 14, 2026

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

return (attributes.location.type == 0);
// location.type: 0 = ACL host memory, 1 = device memory, 2 = regular
// CPU memory (malloc). Only type 1 is device memory; all others are CPU.
return (attributes.location.type != 1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use constant value if possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

friend class RdmaEndPoint;
friend class WorkerPool;

friend class HeterogeneousRdmaTransport;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you clarify which private member(s) this is needed for? If none currently, this should be removed — friend breaks encapsulation and shouldn't be added speculatively.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

HeterogeneousRdmaTransport needs to access the private members submitTransfer, submitTransferTask, and getTransferStatus in RdmaTransport. If friend is not added, it will result in a compilation error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

HeterogeneousRdmaTransport needs to access the private members submitTransfer, submitTransferTask, and getTransferStatus in RdmaTransport. If friend is not added, it will result in a compilation error.

Thanks for the explanation — that makes sense for the original code. However, PR #1663 has since been merged, which moved submitTransfer and related methods from private to public. So the friend class declaration is no longer needed. Could you rebase onto the latest main and drop that change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The corresponding modifications have been submitted.

return false;
// If ACL cannot identify the pointer, it is not ACL-managed device
// memory, so treat it as regular CPU memory.
LOG(WARNING) << "aclrtPointerGetAttributes failed for addr " << addr
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

reformat the example file string concatenation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Copy Markdown
Collaborator

@staryxchen staryxchen left a comment

Choose a reason for hiding this comment

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

LGTM

@stmatengss stmatengss merged commit 335de42 into kvcache-ai:main Mar 17, 2026
16 of 17 checks passed
whn09 pushed a commit to whn09/Mooncake that referenced this pull request Apr 4, 2026
---------

Co-authored-by: sunwenhan <sunwenhan@xfusion.com>
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.

5 participants