• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-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_RUNTIME_DELEGATE_NPU_PASS_NPU_PASS_UTILS_H_
18 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_PASS_NPU_PASS_UTILS_H_
19 #include <vector>
20 #include <set>
21 #include <string>
22 #include <unordered_map>
23 #include "src/litert/delegate/npu/op/npu_op.h"
24 #include "src/litert/delegate/npu/op/transpose_npu.h"
25 
26 namespace mindspore::lite {
27 class NPUPassUtils {
28  public:
29   static NPUOp *CreateNchw2NhwcOp(const std::vector<mindspore::MSTensor> &in_tensors,
30                                   const std::vector<mindspore::MSTensor> &out_tensors, const std::string &name);
31 
32   static NPUOp *CreateNhwc2NchwOp(const std::vector<mindspore::MSTensor> &in_tensors,
33                                   const std::vector<mindspore::MSTensor> &out_tensors, const std::string &name);
34 
35   static void UpdateOp(NPUOp *op, const std::vector<NPUOp *> &in_ops, const std::vector<NPUOp *> &out_ops,
36                        const std::vector<mindspore::MSTensor> &in_tensors,
37                        const std::vector<mindspore::MSTensor> &out_tensors);
38 
39   static void UpdateNH2NCTransNodePreOp(NPUOp *pre_op, NPUOp *trans_op, NPUOp *op);
40 
41   static void UpdateNC2NHTransNodePreOp(NPUOp *pre_op, const std::vector<NPUOp *> &trans_ops,
42                                         const std::vector<NPUOp *> &ops);
43 
44   static void UpdateNH2NCTransNodePostOp(NPUOp *trans_op, NPUOp *post_op);
45 
46   static void UpdateNC2NHTransNodePostOp(NPUOp *op, NPUOp *trans_op, NPUOp *post_op,
47                                          const mindspore::MSTensor &org_in_tensor);
48 
49   static bool IsNhwc2Nchw(NPUOp *op);
50 
51   static bool IsNchw2Nhwc(NPUOp *op);
52   static NPUOp *OpInputFromOp(NPUOp *op, mindspore::MSTensor in_tensor);
53   static std::vector<mindspore::MSTensor> GetNonConstInputs(NPUOp *op);
54   static bool Scale4dCase(NPUOp *op);
55 };
56 }  // namespace mindspore::lite
57 #endif  // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_PASS_NPU_PASS_UTILS_H_
58