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_FUSION_ACTOR_H_ 18 #define MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_FUSION_ACTOR_H_ 19 20 #include <vector> 21 #include <string> 22 #include <memory> 23 #include <utility> 24 #include <unordered_set> 25 #include "utils/hash_map.h" 26 #include "runtime/graph_scheduler/actor/actor_common.h" 27 #include "runtime/graph_scheduler/actor/abstract_actor.h" 28 29 namespace mindspore { 30 namespace runtime { 31 // The fusion actor is the actors set that have the execution dependency. These actors can't execute concurrently and 32 // fuse to the FusionActor. 33 class FusionActor : public AbstractActor { 34 public: FusionActor(const std::string & name)35 explicit FusionActor(const std::string &name) 36 : AbstractActor(name, KernelTransformType::kFusionActor, nullptr), recv_input_controls_num_(0) {} 37 ~FusionActor() override = default; 38 39 // The actor run when receive the input data. 40 void RunOpData(OpData<DeviceTensor> *const input_data, OpContext<DeviceTensor> *const context) override; 41 // The actor run when receive the input control. 42 void RunOpControl(AID *const input_control, OpContext<DeviceTensor> *const context) override; 43 real_input_data()44 const std::vector<std::pair<AbstractActor *, size_t>> &real_input_data() const { return real_input_data_; } real_input_controls()45 const mindspore::HashMap<std::string, std::vector<AbstractActor *>> &real_input_controls() const { 46 return real_input_controls_; 47 } 48 49 private: 50 friend class SchedulerHelper; 51 friend class AnyTypeGraphScheduler; 52 53 // std::pair<actor, input_index> used to find the mapping between fusion actor inputs and real actors inputs. 54 std::vector<std::pair<AbstractActor *, size_t>> real_input_data_; 55 // Used to record the input controls info of the real actors. 56 mindspore::HashMap<std::string, std::vector<AbstractActor *>> real_input_controls_; 57 58 // Record the received input control info. 59 std::unordered_set<std::string> recv_input_control_actors_; 60 size_t recv_input_controls_num_; 61 }; 62 63 using FusionActorPtr = std::shared_ptr<FusionActor>; 64 } // namespace runtime 65 } // namespace mindspore 66 67 #endif // MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_FUSION_ACTOR_H_ 68