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_NPU_CONVERTER_UITLS_H_ 18 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_CONVERTER_UITLS_H_ 19 #include <string> 20 #include <memory> 21 #include <vector> 22 #ifdef ENABLE_ARM64 23 #include <arm_neon.h> 24 #endif 25 #include "schema/ops_generated.h" 26 #include "include/graph/tensor.h" 27 #include "include/graph/op/array_defs.h" 28 #include "include/api/types.h" 29 #include "include/api/data_type.h" 30 31 namespace mindspore { 32 enum NCHW_SHAPE { NCHW_INVALID = -1, NCHW_N = 0, NCHW_C = 1, NCHW_H = 2, NCHW_W = 3 }; 33 enum NHWC_SHAPE { NHWC_N = 0, NHWC_H = 1, NHWC_W = 2, NHWC_C = 3 }; 34 35 enum NPU_ACTIVATION_MODE { 36 ACTIVATION_INVALID = -1, 37 SIGMOID = 0, 38 RELU = 1, 39 TANH = 2, 40 CLIPPED_RELU = 3, 41 ELU = 4, 42 P_RELU = 5, 43 ABS = 6, 44 RELU1 = 7, 45 SOFTSIGN = 8, 46 SOFTPLUS = 9, 47 HARD_SIGMOID = 10, 48 THRESHOLD_RELU = 11, 49 SELU = 12, 50 LINEAR = 13, 51 RELU6 = 14, 52 GELU = 15, 53 }; 54 55 enum PAD { 56 PAD_UP = 0, 57 PAD_DOWN = 1, 58 PAD_LEFT = 2, 59 PAD_RIGHT = 3, 60 }; 61 62 enum NPU_PAD_MODE { 63 PAD_VALID = 5, 64 PAD_SAME = 6, 65 }; 66 67 #ifdef ENABLE_ARM64 68 void Float32ToFloat16(const float *__restrict input, float16_t *__restrict output, int number); 69 70 void Float16ToFloat32(const float16_t *__restrict input, float *__restrict output, int number); 71 #endif 72 73 std::shared_ptr<ge::Tensor> ConverterToNPUTensor(mindspore::MSTensor src); 74 75 hiai::op::Data *ConverterToNPUData(mindspore::MSTensor src, const std::string &name); 76 77 ge::Format ConverterToNPUFormat(schema::Format format); 78 79 ge::DataType ConverterToNPUDataType(DataType type_id); 80 81 ge::Shape ConverterToNPUShape(const std::vector<int64_t> &src_shape); 82 83 int ConverterToNPUEltwiseMode(schema::EltwiseMode mode); 84 85 int ConverterToNPUActivationMode(schema::ActivationType type); 86 87 int TransFormAxis(int axis); 88 89 bool IsContainMSTensor(const std::vector<mindspore::MSTensor> &tensor_vec, const mindspore::MSTensor tensor); 90 } // namespace mindspore 91 #endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_CONVERTER_UITLS_H_ 92