-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Support multi carriers #38650
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
Merged
Support multi carriers #38650
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -17,6 +17,24 @@ | |
namespace paddle { | ||
namespace distributed { | ||
|
||
// TODO(liyurui): Change this file to global.h | ||
template <typename T> | ||
class GlobalVal final { | ||
public: | ||
static T Get() { return *GetPtr(); } | ||
static T Set(T val) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个函数为啥有返回值 |
||
auto* ptr = GetPtr(); | ||
*ptr = val; | ||
return val; | ||
} | ||
|
||
private: | ||
static T* GetPtr() { | ||
static T value; | ||
return &value; | ||
} | ||
}; | ||
|
||
template <typename KeyT, typename ValueT> | ||
class GlobalMap final { | ||
public: | ||
|
@@ -26,6 +44,7 @@ class GlobalMap final { | |
item, platform::errors::NotFound("This value is not in global map.")); | ||
return item; | ||
} | ||
|
||
template <typename... Args> | ||
static ValueT* Create(KeyT id, Args&&... args) { | ||
auto* ptr = GetPPtr(id); | ||
|
@@ -37,6 +56,34 @@ class GlobalMap final { | |
return item; | ||
} | ||
|
||
private: | ||
static std::unique_ptr<ValueT>* GetPPtr(KeyT id) { | ||
static std::unordered_map<KeyT, std::unique_ptr<ValueT>> id_to_ptr; | ||
return &id_to_ptr[id]; | ||
} | ||
}; | ||
|
||
template <typename KeyT, typename ValueT> | ||
class ThreadSafeGlobalMap final { | ||
public: | ||
static ValueT* Get(KeyT id) { | ||
ValueT* item = GetPPtr(id)->get(); | ||
PADDLE_ENFORCE_NOT_NULL( | ||
item, platform::errors::NotFound( | ||
"This value is not in thread safe global map.")); | ||
return item; | ||
} | ||
template <typename... Args> | ||
static ValueT* Create(KeyT id, Args&&... args) { | ||
auto* ptr = GetPPtr(id); | ||
PADDLE_ENFORCE_EQ(ptr->get(), nullptr, | ||
platform::errors::AlreadyExists( | ||
"This value has already in thread safe global map.")); | ||
ValueT* item = new ValueT(std::forward<Args>(args)...); | ||
ptr->reset(item); | ||
return item; | ||
} | ||
|
||
private: | ||
static std::unique_ptr<ValueT>* GetPPtr(KeyT id) { | ||
static std::mutex mutex; | ||
|
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
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.
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.
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.
对于不同的program,我们共用runtime graph么?是不是这个改成个map比较好,一个carrier id对应一个runtime graph这样?
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.
这个确实后面要改的