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_LOOP_COUNT_ACTOR_H_ 18 #define MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_LOOP_COUNT_ACTOR_H_ 19 20 #include <vector> 21 #include <string> 22 #include <memory> 23 #include <unordered_map> 24 #include <map> 25 #include <utility> 26 #include "runtime/framework/actor/actor_common.h" 27 #include "runtime/framework/actor/debug_aware_actor.h" 28 #include "runtime/framework/device_tensor_store.h" 29 #include "runtime/framework/control_node_parser.h" 30 31 namespace mindspore { 32 namespace runtime { 33 // The loop count actor is used to receive the control of tail kernel actor to represent the end of one step 34 // and decide whether to loop execution by loop count. 35 class LoopCountActor : public DebugAwareActor { 36 public: LoopCountActor(const std::string & name,size_t loop_count,const AID & memory_manager_aid,const AID * debug_aid,const AID * recorder_aid)37 LoopCountActor(const std::string &name, size_t loop_count, const AID &memory_manager_aid, const AID *debug_aid, 38 const AID *recorder_aid) 39 : DebugAwareActor(name, KernelTransformType::kLoopCountActor, recorder_aid, memory_manager_aid, debug_aid), 40 loop_count_(loop_count), 41 current_count_(0), 42 total_running_count_(0) {} 43 44 ~LoopCountActor() override = default; 45 46 // The loop count actor run when receive the input control. 47 void RunOpControl(AID *const input_control, OpContext<DeviceTensor> *const context) override; 48 49 // The callback waits for the memory manager actor to finish all the message processing. 50 void OnMemoryAllocFinish(OpContext<DeviceTensor> *const context) override; 51 52 // The debug related operation interface. 53 void SendDebugReq(OpContext<DeviceTensor> *const context) override; 54 // The callback after debug finished. 55 void OnDebugFinish(OpContext<DeviceTensor> *const context) override; 56 57 private: 58 friend class GraphScheduler; 59 60 void IncreaseLoopCount(OpContext<DeviceTensor> *const context); 61 void SendOutput(OpContext<DeviceTensor> *const context); 62 63 // The loop count is constant, the current count is increased after each step running finished. 64 size_t loop_count_; 65 size_t current_count_; 66 // The total running count represents the toal step running count. 67 size_t total_running_count_; 68 69 // The output controls contain the data prepare actor and output actor. 70 AID data_prepare_aid_; 71 AID output_aid_; 72 }; 73 74 using LoopCountActorPtr = std::shared_ptr<LoopCountActor>; 75 } // namespace runtime 76 } // namespace mindspore 77 78 #endif // MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_LOOP_COUNT_ACTOR_H_ 79