1 /** 2 * Copyright 2020 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_LITE_KERNEL_UTIL_H_ 18 #define MINDSPORE_LITE_SRC_LITE_KERNEL_UTIL_H_ 19 #include <vector> 20 #include <set> 21 #include "src/lite_kernel.h" 22 23 namespace mindspore::kernel { 24 25 class LiteKernelUtil { 26 public: 27 static std::vector<kernel::LiteKernel *> SubgraphInputNodes(const std::vector<kernel::LiteKernel *> &kernels); 28 static std::vector<kernel::LiteKernel *> SubgraphOutputNodes(const std::vector<kernel::LiteKernel *> &kernels); 29 static std::vector<lite::Tensor *> SubgraphInputTensors(const std::vector<kernel::LiteKernel *> &kernels); 30 static std::vector<lite::Tensor *> SubgraphOutputTensors(const std::vector<kernel::LiteKernel *> &kernels); 31 static int TopologicalSortKernels(std::vector<kernel::LiteKernel *> *kernels); 32 static void InitTensorInitRefCount(const std::vector<kernel::LiteKernel *> &kernels); 33 static int SetInput(const LiteKernel &kernelMod, const std::vector<lite::Tensor *> &inputs); 34 #ifndef CONTROLFLOW_TENSORLIST_CLIP 35 static bool IsSwitchCall(kernel::LiteKernel *kernel); 36 #endif 37 static kernel::LiteKernel *GetInputsSpecificNode(const kernel::LiteKernel *kernel, 38 const schema::PrimitiveType &primitive_type); 39 static bool InputsContainsSpecificNode(const kernel::LiteKernel *kernel, const schema::PrimitiveType &primitive_type); 40 // find in_kernels_ and out_kernels of kernel, sub_graph and nodes_ in sub_graph 41 static void FindAllInoutKernels(const std::vector<kernel::LiteKernel *> &kernels); 42 43 private: 44 static std::set<lite::Tensor *> AllOutTensor(const std::vector<kernel::LiteKernel *> &kernels); 45 }; 46 47 } // namespace mindspore::kernel 48 49 #endif // MINDSPORE_LITE_SRC_LITE_KERNEL_UTIL_H_ 50