• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_RPC_MUX_SEND_ACTOR_H_
18 #define MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_RPC_MUX_SEND_ACTOR_H_
19 
20 #include <string>
21 #include <memory>
22 #include <set>
23 
24 #include "runtime/graph_scheduler/actor/rpc/send_actor.h"
25 #include "runtime/graph_scheduler/actor/rpc/mux_recv_actor.h"
26 
27 namespace mindspore {
28 namespace runtime {
29 // MuxSendActor inherits from SendActor and it's used to send data to other processes.
30 // MuxSendActor(Multiplexed Send Actor) can send data to different Recv Actor each time, for example, when responding to
31 // requests or replying to requests as a service, it only needs to reply to the caller of the service, although the
32 // actor may have established connections with multiple Recv Actors.
33 class MuxSendActor : public SendActor {
34  public:
MuxSendActor(const std::string & name,const CNodePtr & kernel,const DeviceContext * device_context,const AID & memory_manager_aid,const AID * debug_aid,const AID * recorder_aid,GraphExecutionStrategy strategy,const std::set<size_t> & modifiable_ref_input_indexes,const std::set<size_t> & modifiable_ref_output_indexes)35   explicit MuxSendActor(const std::string &name, const CNodePtr &kernel, const DeviceContext *device_context,
36                         const AID &memory_manager_aid, const AID *debug_aid, const AID *recorder_aid,
37                         GraphExecutionStrategy strategy, const std::set<size_t> &modifiable_ref_input_indexes,
38                         const std::set<size_t> &modifiable_ref_output_indexes)
39       : SendActor(name, kernel, device_context, memory_manager_aid, debug_aid, recorder_aid, strategy,
40                   modifiable_ref_input_indexes, modifiable_ref_output_indexes) {}
41   ~MuxSendActor() override = default;
42 
43   // Set the MuxRecvActor paired with the MuxSendActor to get the 'from url' from the MuxRecvActor.
set_mux_recv_actor(const MuxRecvActorPtr & mux_recv_actor)44   void set_mux_recv_actor(const MuxRecvActorPtr &mux_recv_actor) { mux_recv_actor_ = mux_recv_actor; }
45 
46  private:
47   // After rpc send kernel is launched, inter-process data should be sent and can be sent to different Recv Actor each
48   // time. For example, when responding to a request or replying to a request as a service, it only needs to reply to
49   // the caller of the service, although the actor may have established connections with multiple Recv Actors.
50   // When serving as a service, the MuxSendActor and MuxRecvActor of the server are used in pairs, and the MuxSendActor
51   // needs to obtain the information(ip and port) of peer that initiates this service from the corresponding
52   // MuxRecvActor to response request.
53   bool LaunchKernel(OpContext<DeviceTensor> *const context, bool is_skip_launch = false) override;
54 
55   // MuxSendActor and MuxRecvActor of the server are used in pairs, and the MuxSendActor
56   // needs to obtain the information(ip and port) of peer from the corresponding MuxRecvActor.
57   MuxRecvActorPtr mux_recv_actor_;
58 };
59 
60 using MuxSendActorPtr = std::shared_ptr<MuxSendActor>;
61 }  // namespace runtime
62 }  // namespace mindspore
63 
64 #endif  // MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_RPC_MUX_SEND_ACTOR_H_
65