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_RUNTIME_DELEGATE_NPU_TRANSPOSE_KERNEL_H_ 18 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_TRANSPOSE_KERNEL_H_ 19 #include <utility> 20 #include <vector> 21 #include <string> 22 #include "include/graph/op/all_ops.h" 23 #include "include/api/kernel.h" 24 #include "include/errorcode.h" 25 #include "src/common/log_adapter.h" 26 27 using mindspore::lite::RET_ERROR; 28 using mindspore::lite::RET_OK; 29 30 namespace mindspore::lite { 31 void PackNHWCToNCHWFp32(const void *src, void *dst, int batches, int plane, int channel); 32 33 void PackNCHWToNHWCFp32(const void *src, void *dst, int batch, int plane, int channel); 34 35 class TransposeNPUKernel : public kernel::Kernel { 36 public: TransposeNPUKernel(const std::vector<mindspore::MSTensor> & in_tensors,const std::vector<mindspore::MSTensor> & out_tensors,std::vector<int> perm,std::string name)37 TransposeNPUKernel(const std::vector<mindspore::MSTensor> &in_tensors, 38 const std::vector<mindspore::MSTensor> &out_tensors, std::vector<int> perm, std::string name) 39 : kernel::Kernel(in_tensors, out_tensors, nullptr, nullptr) { 40 type_ = schema::PrimitiveType_Transpose; 41 name_ = std::move(name); 42 perm_ = std::move(perm); 43 } 44 45 ~TransposeNPUKernel() override = default; 46 Prepare()47 int Prepare() override { return RET_OK; } 48 49 int Execute() override; 50 ReSize()51 int ReSize() override { 52 MS_LOG(ERROR) << "NPU does not support the resize function temporarily."; 53 return RET_ERROR; 54 } 55 56 protected: 57 std::vector<int> perm_; 58 }; 59 } // namespace mindspore::lite 60 #endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_TRANSPOSE_KERNEL_H_ 61