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_LITE_SRC_CONTROL_FLOW_ACTOR_EXIT_ACTOR_H_ 18 #define MINDSPORE_LITE_SRC_CONTROL_FLOW_ACTOR_EXIT_ACTOR_H_ 19 #include <vector> 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 #include "src/litert/lite_mindrt.h" 24 25 namespace mindspore::lite { 26 class LiteExitOpActor : public LiteOpActor { 27 public: LiteExitOpActor(kernel::KernelExec * kernel,lite::InnerContext * ctx)28 explicit LiteExitOpActor(kernel::KernelExec *kernel, lite::InnerContext *ctx) : LiteOpActor(kernel, ctx) {} 29 ~LiteExitOpActor() override = default; 30 void RunOpData(OpData<Tensor> *inputs, OpContext<Tensor> *context = nullptr) override; 31 int PreInit(std::vector<std::shared_ptr<LiteOpActor>> *actors, 32 std::unordered_map<Tensor *, Tensor *> *input_map) override; 33 int PostInit() override; 34 35 protected: 36 void AsyncOutput(OpContext<Tensor> *context) override; 37 int PrepareOutputData() override; 38 int InitInputData() override; 39 int SetInputShape() override; 40 41 private: 42 struct MappingInfo { MappingInfoMappingInfo43 MappingInfo(kernel::KernelExec *partial, kernel::KernelExec *call) : partial_node(partial), call_node(call) {} 44 kernel::KernelExec *partial_node = nullptr; 45 kernel::KernelExec *call_node = nullptr; 46 AID partial_input_aid; 47 AID call_output_aid; 48 }; 49 int CreateMappingInfo(); 50 int RecordCallNodeOutputActor(std::vector<std::shared_ptr<LiteOpActor>> *actors); 51 void RecordPartialNodeInputActor(); 52 void SetEntranceInputAID(const OpData<Tensor> *inputs); 53 bool IsSubSet(const std::vector<lite::Tensor *> &all_set, const std::vector<lite::Tensor *> &sub_set); 54 55 std::vector<std::shared_ptr<LiteOpActor>> *actors_{}; 56 std::vector<MappingInfo> all_mapping_info_{}; 57 AID entrance_input_aid_; 58 }; 59 } // namespace mindspore::lite 60 #endif // MINDSPORE_LITE_SRC_CONTROL_FLOW_ACTOR_EXIT_ACTOR_H_ 61