-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[fleet_executor] Framework for message and manager part. #36966
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
gongweibao
merged 23 commits into
PaddlePaddle:develop
from
FeixLiu:fleet_executor_message_part_framework
Nov 4, 2021
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4851fcd
framework for message/manager part
FeixLiu baf344f
bug fix
FeixLiu cace79b
bugs fix
FeixLiu d170e1f
lots of debug
FeixLiu cd0080e
add compile flag
FeixLiu f87a745
resolve brpc error
FeixLiu 8ed34e8
brpc debug
FeixLiu 2895ca2
add compile flag
FeixLiu b27fb25
compile flag
FeixLiu 6f651c4
remove test for another place
FeixLiu 9ad4504
update cmake
FeixLiu 9bc23fa
different compile
FeixLiu f6c0358
move back test
FeixLiu 896acee
move flag
FeixLiu 573a9c1
add depend on brpc
FeixLiu f1c52eb
for CE
FeixLiu 4c73a49
remove brpc depend
FeixLiu beede58
modify brpc depend
FeixLiu 74bcbd0
move brpc depend for distribute (for npu compile)
FeixLiu 7ee4be9
npu compile dependency
FeixLiu 5791466
some rename
FeixLiu 1f727d6
npu compile
FeixLiu 7b96334
remove npu support
FeixLiu 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
proto_library(fleet_executor_desc_proto SRCS fleet_executor_desc.proto) | ||
cc_library(fleet_executor SRCS fleet_executor.cc DEPS fleet_executor_desc_proto) | ||
|
||
if(WITH_PYTHON) | ||
py_proto_compile(fleet_executor_desc_py_proto SRCS fleet_executor_desc.proto) | ||
endif() | ||
proto_library(interceptor_message_proto SRCS interceptor_message.proto) | ||
|
||
if(WITH_DISTRIBUTE AND NOT (WITH_ASCEND OR WITH_ASCEND_CL)) | ||
set(BRPC_DEPS brpc) | ||
else() | ||
set(BRPC_DEPS "") | ||
endif() | ||
|
||
cc_library(fleet_executor SRCS fleet_executor.cc carrier.cc | ||
interceptor.cc interceptor_message_service.cc message_bus.cc | ||
DEPS fleet_executor_desc_proto interceptor_message_proto ${BRPC_DEPS}) | ||
|
||
if(WITH_DISTRIBUTE) | ||
set(DISTRIBUTE_COMPILE_FLAGS "-Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor") | ||
set_source_files_properties(message_bus.h PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS}) | ||
set_source_files_properties(message_bus.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS}) | ||
set_source_files_properties(carrier.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS}) | ||
set_source_files_properties(interceptor_message_service.h PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS}) | ||
set_source_files_properties(interceptor_message_service.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS}) | ||
endif() |
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,43 @@ | ||
// Copyright (c) 2021 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/distributed/fleet_executor/carrier.h" | ||
#include "paddle/fluid/distributed/fleet_executor/interceptor.h" | ||
#include "paddle/fluid/distributed/fleet_executor/interceptor_message_service.h" | ||
#include "paddle/fluid/distributed/fleet_executor/task_node.h" | ||
|
||
namespace paddle { | ||
namespace distributed { | ||
|
||
Carrier::Carrier( | ||
const std::unordered_map<int64_t, TaskNode*>& interceptor_id_to_node) { | ||
// init | ||
} | ||
|
||
Carrier::~Carrier() { | ||
// destroy | ||
} | ||
|
||
bool Carrier::EnqueueInterceptorMessage( | ||
const InterceptorMessage& interceptor_message) { | ||
// enqueue message to interceptor | ||
return true; | ||
} | ||
|
||
void Carrier::CreateInterceptors() { | ||
// create each Interceptor | ||
} | ||
|
||
} // namespace distributed | ||
} // namespace paddle |
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,60 @@ | ||
// Copyright (c) 2021 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 <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include "paddle/fluid/distributed/fleet_executor/interceptor_message.pb.h" | ||
#include "paddle/fluid/platform/macros.h" | ||
|
||
namespace paddle { | ||
namespace distributed { | ||
|
||
class Interceptor; | ||
class TaskNode; | ||
class InterceptorMessageServiceImpl; | ||
|
||
class Carrier final { | ||
public: | ||
Carrier() = delete; | ||
|
||
Carrier(const std::unordered_map<int64_t, TaskNode*>& interceptor_id_to_node); | ||
|
||
~Carrier(); | ||
|
||
// Enqueue a message to corresponding interceptor id | ||
bool EnqueueInterceptorMessage(const InterceptorMessage& interceptor_message); | ||
|
||
DISABLE_COPY_AND_ASSIGN(Carrier); | ||
|
||
private: | ||
// create each Interceptor | ||
void CreateInterceptors(); | ||
|
||
// get interceptor based on the interceptor id | ||
Interceptor* GetInterceptor(int64_t interceptor_id); | ||
|
||
// interceptor logic id to the Nodes info | ||
std::unordered_map<int64_t, TaskNode*> interceptor_id_to_node_; | ||
|
||
// interceptor logic id to actually interceptor | ||
std::unordered_map<int64_t, std::unique_ptr<Interceptor>> | ||
interceptor_idx_to_interceptor_; | ||
FeixLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
} // namespace distributed | ||
} // namespace paddle |
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,46 @@ | ||
// Copyright (c) 2021 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/distributed/fleet_executor/interceptor.h" | ||
|
||
namespace paddle { | ||
namespace distributed { | ||
|
||
Interceptor::Interceptor(int64_t interceptor_id_, TaskNode* node) { | ||
// init | ||
} | ||
|
||
int64_t Interceptor::GetInterceptorId() const { | ||
// return the interceptor id | ||
return 0; | ||
} | ||
|
||
bool Interceptor::EnqueueRemoteInterceptorMessage( | ||
const InterceptorMessage& interceptor_message) { | ||
// Called by Carrier, enqueue an InterceptorMessage to remote mailbox | ||
return true; | ||
} | ||
|
||
void Interceptor::PoolTheMailbox() { | ||
// pool the local mailbox, parse the Message | ||
} | ||
|
||
bool Interceptor::FetchRemoteMailbox() { | ||
// fetch all Message from remote mailbox to local mailbox | ||
// return true if remote mailbox not empty, otherwise return false | ||
return true; | ||
} | ||
|
||
} // namespace distributed | ||
} // namespace paddle |
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,83 @@ | ||
// Copyright (c) 2021 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 <condition_variable> | ||
#include <map> | ||
#include <memory> | ||
#include <queue> | ||
#include <thread> | ||
#include <vector> | ||
|
||
#include "paddle/fluid/distributed/fleet_executor/interceptor_message.pb.h" | ||
#include "paddle/fluid/platform/macros.h" | ||
|
||
namespace paddle { | ||
namespace distributed { | ||
|
||
class TaskNode; | ||
|
||
class Interceptor { | ||
public: | ||
Interceptor() = delete; | ||
|
||
Interceptor(int64_t interceptor_id_, TaskNode* node); | ||
|
||
virtual ~Interceptor() = default; | ||
|
||
// return the interceptor id | ||
int64_t GetInterceptorId() const; | ||
|
||
// Called by Carrier, enqueue an InterceptorMessage to remote mailbox | ||
bool EnqueueRemoteInterceptorMessage( | ||
const InterceptorMessage& interceptor_message); | ||
|
||
DISABLE_COPY_AND_ASSIGN(Interceptor); | ||
|
||
private: | ||
// pool the local mailbox, parse the Message | ||
void PoolTheMailbox(); | ||
FeixLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// fetch all Message from remote mailbox to local mailbox | ||
// return true if remote mailbox not empty, otherwise return false | ||
bool FetchRemoteMailbox(); | ||
|
||
// interceptor id, handed from above layer | ||
int64_t interceptor_id_; | ||
|
||
// node need to be handled by this interceptor | ||
TaskNode* node_; | ||
|
||
// mutex to control read/write conflict for remote mailbox | ||
std::mutex remote_mailbox_mutex_; | ||
|
||
// interceptor runs PoolTheMailbox() function to poll local mailbox | ||
std::thread interceptor_thread_; | ||
|
||
// conditional variable for blocking the thread when | ||
// fetch an empty remote mailbox | ||
std::condition_variable cond_var_; | ||
|
||
// remote mailbox, written by EnqueueRemoteMessage() | ||
// read by FetchRemoteMailbox() | ||
std::queue<InterceptorMessage> remote_mailbox_; | ||
|
||
// local mailbox, written by FetchRemoteMailbox() | ||
// read by PoolTheMailbox() | ||
std::queue<InterceptorMessage> local_mailbox_; | ||
}; | ||
|
||
} // namespace distributed | ||
} // namespace paddle |
40 changes: 40 additions & 0 deletions
40
paddle/fluid/distributed/fleet_executor/interceptor_message.proto
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,40 @@ | ||
// Copyright (c) 2021 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. | ||
|
||
syntax = "proto2"; | ||
package paddle.distributed; | ||
option cc_generic_services = true; | ||
option cc_enable_arenas = true; | ||
|
||
enum MessageType { | ||
STOP = 1; // STOP an Interceptor | ||
DATA_IS_READY = 2; // upstream data is ready | ||
DATE_IS_USELESS = 3; // downstream has used the data | ||
ERROR = 4; // current Interceptor encounters error | ||
RESET = 5; // reset the status | ||
} | ||
|
||
message InterceptorMessage { | ||
optional int64 src_id = 1 [ default = 0 ]; | ||
optional int64 dst_id = 2 [ default = 0 ]; | ||
optional MessageType message_type = 3 [ default = RESET ]; | ||
optional bool ctrl_message = 4 [ default = false ]; | ||
} | ||
|
||
message InterceptorResponse { optional bool rst = 1 [ default = false ]; } | ||
|
||
service TheInterceptorMessageService { | ||
rpc InterceptorMessageService(InterceptorMessage) | ||
returns (InterceptorResponse); | ||
} |
31 changes: 31 additions & 0 deletions
31
paddle/fluid/distributed/fleet_executor/interceptor_message_service.cc
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,31 @@ | ||
// Copyright (c) 2021 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. | ||
#ifndef PADDLE_WITH_ASCEND_CL | ||
#ifdef PADDLE_WITH_DISTRIBUTE | ||
#include "paddle/fluid/distributed/fleet_executor/interceptor_message_service.h" | ||
|
||
namespace paddle { | ||
namespace distributed { | ||
|
||
void InterceptorMessageServiceImpl::InterceptorMessageService( | ||
google::protobuf::RpcController* control_base, | ||
const InterceptorMessage* request, InterceptorResponse* response, | ||
google::protobuf::Closure* done) { | ||
// receive msg | ||
} | ||
|
||
} // namespace distributed | ||
} // namespace paddle | ||
#endif | ||
#endif |
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.