-
Notifications
You must be signed in to change notification settings - Fork 90
use unix socket to share fd #634
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
Merged
+516
−46
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
be1d40c
use unix socket to trans fd
Binyang2014 404b2e0
Update src/unix_socket.cc
Binyang2014 359f188
Update src/include/unix_socket.hpp
Binyang2014 207c354
minor fix
Binyang2014 8f94df7
fix
Binyang2014 1bdde1a
WIP
Binyang2014 f15f5f3
update
Binyang2014 da6c902
WIP
Binyang2014 84ca518
Fallback for multi-nodes
Binyang2014 c313e91
WIP
Binyang2014 5ff9fd7
WIP
Binyang2014 aaa13cc
fix ut
Binyang2014 4aa70cd
support worldsize=1
Binyang2014 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| #ifndef MSCCLPP_UNIX_SOCKET_HPP_ | ||
| #define MSCCLPP_UNIX_SOCKET_HPP_ | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <string> | ||
| #include <thread> | ||
| #include <unordered_map> | ||
|
|
||
| namespace mscclpp { | ||
|
|
||
| class UnixSocketServer { | ||
| public: | ||
| static UnixSocketServer& instance(); | ||
| static std::string generateSocketPath(int localRankId); | ||
|
|
||
| void start(int localRankId); | ||
| void stop(); | ||
| uint32_t registerFd(int fd); | ||
| void unregisterFd(uint32_t fdId); | ||
| std::string getSocketPath() const; | ||
|
|
||
| private: | ||
| int listenUnixSockFd_ = -1; | ||
| std::string listenUnixSockPath_; | ||
| std::thread mainThread_; | ||
| std::unique_ptr<uint32_t> abortFlagStorage_; | ||
| volatile uint32_t* abortFlag_; | ||
| std::mutex mutex_; | ||
| std::unordered_map<uint32_t, int> fdMap_; | ||
|
|
||
| UnixSocketServer(); | ||
| void mainLoop(); | ||
| }; | ||
|
|
||
| class UnixSocketClient { | ||
| public: | ||
| static UnixSocketClient& instance(); | ||
|
|
||
| int requestFd(const std::string& socketPath, uint32_t fdId); | ||
| ~UnixSocketClient(); | ||
|
|
||
| private: | ||
| std::unordered_map<std::string, int> cachedFds_; | ||
| std::mutex mutex_; | ||
|
|
||
| UnixSocketClient() = default; | ||
| int requestFdInternal(int connFd, uint32_t fdId); | ||
| }; | ||
|
|
||
| } // namespace mscclpp | ||
|
|
||
| #endif // MSCCLPP_UNIX_SOCKET_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.