-
Notifications
You must be signed in to change notification settings - Fork 82
Feat: Introduce Mbox C API for multiple parties communication #567
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @tongke6, 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 establishes a foundational interface for inter-party communication within the yacl::link
module. By introducing the Mbox
interface and an in-memory implementation, it provides a flexible and testable mechanism for exchanging messages between different participants. This enhancement is crucial for building and verifying distributed protocols, offering a clear abstraction layer for communication channels.
Highlights
- New Mbox Interface: Introduced a new virtual interface,
yacl::link::Mbox
, for abstracting multi-party communication, definingSend
andRecv
methods. - In-Memory Mbox Implementation: Provided an
InMemoryMbox
class, which is a concrete implementation of theMbox
interface, designed for testing and local development scenarios. - Mbox Factory: Added a factory function,
CreateInMemoryMboxs
, to easily create multiple interconnectedInMemoryMbox
instances for a givenworld_size
. - Unit Tests: Included comprehensive unit tests for
InMemoryMbox
covering basic send/receive, multiple messages, timeout handling, and concurrent operations to ensure correctness. - Bazel Build Updates: Updated the Bazel build configuration to include the new
mbox
andmbox_factory
libraries and their corresponding tests, along with a minor update toMODULE.bazel.lock
.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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
-
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. ↩
There was a problem hiding this 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 new Mbox
interface for multi-party communication, along with an in-memory implementation for testing purposes. The overall design is sound. My review focuses on improving performance, code hygiene, and style consistency. I've suggested using absl::StrCat
for more efficient string construction, which requires a small build file modification. I've also pointed out some unused header includes and recommended adding missing newlines at the end of the new files for better style compliance.
deps = [ | ||
":mbox", | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox.h
Outdated
int64_t timeout_ms) = 0; | ||
}; | ||
|
||
} // namespace yacl::link No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory.cc
Outdated
|
||
#include <chrono> | ||
#include <exception> | ||
#include <future> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory.cc
Outdated
#include <map> | ||
#include <mutex> | ||
#include <optional> | ||
#include <shared_mutex> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory.cc
Outdated
std::string full_key = | ||
"/frm/" + std::to_string(rank_) + "/msg/" + std::string(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string concatenation creates multiple temporary std::string
objects, which is inefficient. Using absl::StrCat
is a more performant way to concatenate strings as it avoids intermediate allocations.
To use absl::StrCat
, you'll also need to:
- Add
#include "absl/strings/str_cat.h"
to this file. - Add the
@abseil-cpp//absl/strings
dependency inyacl/link/BUILD.bazel
(I've added a separate comment for this).
std::string full_key = | |
"/frm/" + std::to_string(rank_) + "/msg/" + std::string(key); | |
std::string full_key = absl::StrCat("/frm/", rank_, "/msg/", key); |
yacl/link/mbox_factory.cc
Outdated
std::string full_key = | ||
"/frm/" + std::to_string(src) + "/msg/" + std::string(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory.cc
Outdated
return result; | ||
} | ||
|
||
} // namespace yacl::link No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory.h
Outdated
// from 0 to world_size - 1. | ||
std::vector<std::shared_ptr<Mbox>> CreateInMemoryMboxs(size_t world_size); | ||
|
||
} // namespace yacl::link No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory_test.cc
Outdated
receiver.join(); | ||
} | ||
|
||
} // namespace yacl::link No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yacl/link/mbox_factory.cc
Outdated
|
||
std::optional<std::vector<uint8_t>> result = std::nullopt; | ||
|
||
auto stop_wait = [&] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以使用 extract:
auto stop_wait = [&] {
auto& mailbox = shared_state_->mailboxes[rank_];
if (auto node = mailbox.extract(full_key); !node.empty()) {
result = std::move(node.mapped());
return true;
}
return false;
};
yacl/link/mbox_factory_test.cc
Outdated
EXPECT_FALSE(received.has_value()); | ||
} | ||
|
||
TEST(InMemoryMbox, ConcurrentSendRecv) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来Concurrent不是重点,BlockingRecvThenSend 如何?
yacl/link/mbox_factory.h
Outdated
std::optional<std::vector<uint8_t>> Recv(size_t src, std::string_view key, | ||
int64_t timeout_ms) override; | ||
|
||
public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple "public"s in a class
5baf9df
to
36ca71d
Compare
/// @param data_len Length of data in bytes. | ||
/// | ||
/// @return MBOX_SUCCESS on success, appropriate error code on failure. | ||
mbox_error_t mbox_send(mbox_t* mbox, size_t dst, const char* key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个API有个隐藏语义
send到底是放到 自己的mbox 就success了,还是到达对方的 mbox 才算success
理论上我理解放到 自己的mbox就算成功了,这样对异步比较友好,但也有两个问题
- sender 如何知道 mbox 之间的发送错误,需要新的接口吗?
- mobx 是否本身也要 flush 接口,Sender 异步send完毕后结束进程的问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前想的是放到自己的发送队列里就算成功。
flush 接口可以按需加。
mbox 后续会增加stats 接口,统计发送成功的,正在发送的,以及发送失败的等统计信息,以及接受信息。
Stale pull request message. Please comment to remove stale tag. Otherwise this pr will be closed soon. |
No description provided.