-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add rpc_client interface. #11154
Merged
Merged
Add rpc_client interface. #11154
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
044e133
add rpc_client.h
gongweibao 0787213
fix compile error
gongweibao 8d4050a
follow comments
gongweibao 8432c20
follow comments
gongweibao 60f0ed7
add getinstance template
gongweibao a1db10b
add rpc_client.cc
gongweibao 98b668a
merge
gongweibao 0e35c70
fix bug
gongweibao 06f7295
fix return value
gongweibao 8060263
follow comments
gongweibao 82928fd
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
gongweibao 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 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 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 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 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 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,26 @@ | ||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/operators/detail/rpc_client.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
namespace detail { | ||
|
||
std::once_flag RPCClient::init_flag_; | ||
std::unique_ptr<RPCClient> RPCClient::rpc_client_(nullptr); | ||
|
||
} // namespace detail | ||
} // namespace operators | ||
} // namespace paddle |
This file contains 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,82 @@ | ||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "paddle/fluid/framework/data_type.h" | ||
#include "paddle/fluid/framework/lod_tensor.h" | ||
#include "paddle/fluid/framework/scope.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
namespace detail { | ||
|
||
class RPCClient { | ||
public: | ||
virtual bool AsyncSendVar(const std::string& ep, | ||
const platform::DeviceContext& ctx, | ||
const framework::Scope& scope, | ||
const std::string& var_name, | ||
int64_t time_out = rpc_time_out) = 0; | ||
|
||
virtual bool AsyncGetVar(const std::string& ep, | ||
const platform::DeviceContext& ctx, | ||
const framework::Scope& scope, | ||
const std::string& var_name, | ||
int64_t time_out = rpc_time_out) = 0; | ||
|
||
virtual bool AsyncPrefetchVar(const std::string& ep, | ||
const platform::DeviceContext& ctx, | ||
const framework::Scope& scope, | ||
const std::string& in_var_name, | ||
const std::string& out_var_name, | ||
int64_t time_out = rpc_time_out) = 0; | ||
|
||
virtual void AsyncSendBatchBarrier(const std::string& ep, | ||
int64_t time_out = rpc_time_out) = 0; | ||
|
||
virtual void AsyncSendFetchBarrier(const std::string& ep, | ||
int64_t time_out = rpc_time_out) = 0; | ||
|
||
virtual void Wait() = 0; | ||
|
||
static constexpr int64_t rpc_time_out = 600 * 1000; | ||
|
||
template <typename T> | ||
static RPCClient* GetInstance() { | ||
std::call_once(init_flag_, &RPCClient::Init<T>); | ||
return rpc_client_.get(); | ||
} | ||
|
||
// Init is called by GetInstance. | ||
template <typename T> | ||
static void Init() { | ||
if (rpc_client_.get() == nullptr) { | ||
rpc_client_.reset(new T()); | ||
rpc_client_->InitImpl(); | ||
} | ||
} | ||
|
||
protected: | ||
virtual void InitImpl() = 0; | ||
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. This may not need to be pure virtual, not all implementations need to start an event loop for a client. 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. Done.Thanks! |
||
|
||
private: | ||
static std::once_flag init_flag_; | ||
static std::unique_ptr<RPCClient> rpc_client_; | ||
}; | ||
} // namespace detail | ||
} // namespace operators | ||
} // namespace paddle |
This file contains 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.
600s is a bit long.
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.
Done.Thanks.