• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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_ABSTRACT_ACTOR_H_
18 #define MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_ABSTRACT_ACTOR_H_
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include <utility>
24 #include "mindrt/include/actor/op_actor.h"
25 #include "runtime/framework/actor/actor_common.h"
26 #include "runtime/framework/device_tensor_store.h"
27 #include "runtime/hardware/device_context.h"
28 
29 namespace mindspore {
30 namespace runtime {
31 using mindspore::device::DeviceContext;
32 
33 // The abstract common attributes of actors. The actor inheritance relationship:  OpActor --> AbstractActor -->
34 // MemoryAwareActor --> DebugAwareActor --> KernelActor/DataSourceActor/CopyActor/LoopCountActor/OutputActor.
35 class AbstractActor : public OpActor<DeviceTensor> {
36  public:
AbstractActor(const std::string & name,KernelTransformType type,const AID * recorder_aid)37   explicit AbstractActor(const std::string &name, KernelTransformType type, const AID *recorder_aid)
38       : OpActor(name),
39         type_(type),
40         recorder_aid_(recorder_aid),
41         input_datas_num_(0),
42         input_controls_num_(0),
43         running_dependent_msg_num_(0) {}
44   virtual ~AbstractActor() = default;
45 
IsActive(int msg_num)46   bool IsActive(int msg_num) override { return msg_num >= running_dependent_msg_num_ ? true : false; }
47 
48   // Get the position of node in the actor.
FetchNodePosition(const AnfNodePtr & node)49   virtual size_t FetchNodePosition(const AnfNodePtr &node) const { return 0; }
50 
51  protected:
52   friend class GraphScheduler;
53 
54   // Check whether satisfy the actor running condition.
55   bool CheckRunningCondition(const OpContext<DeviceTensor> *context) const;
56   // Erase input data and input controls when finish actor running.
57   void EraseInput(const OpContext<DeviceTensor> *const context);
58 
59   KernelTransformType type_;
60 
61   // The device interface.
62   std::vector<const DeviceContext *> device_contexts_;
63 
64   // The id of recorder actor. Send message to it for recording info.
65   const AID *recorder_aid_;
66 
67   // The output result arrows of graph output.
68   std::vector<DataArrowPtr> output_result_arrows_;
69 
70   // The dependent device tensor stores,  the dependent expression is pair<index, AnfNode>.
71   // Index is the input position, AnfNode is the key of the device tensor store.
72   std::vector<std::pair<size_t, AnfNodePtr>> device_tensor_store_keys_;
73 
74   // The dependent input actors.
75   std::vector<AID> input_data_arrow_aids_;
76   std::vector<AID> input_control_arrow_aids_;
77   // The dependent inputs number.
78   size_t input_datas_num_;
79   size_t input_controls_num_;
80 
81   // The dependent messages number of actor running.
82   int running_dependent_msg_num_;
83 };
84 
85 using AbstractActorPtr = std::shared_ptr<AbstractActor>;
86 }  // namespace runtime
87 }  // namespace mindspore
88 
89 #endif  // MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_ABSTRACT_ACTOR_H_
90