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 #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_INSTANCE_NORM_H_ 17 #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_INSTANCE_NORM_H_ 18 #include <vector> 19 #include "src/inner_kernel.h" 20 #include "include/context.h" 21 #include "nnacl/instance_norm_parameter.h" 22 23 using mindspore::lite::InnerContext; 24 25 namespace mindspore::kernel { 26 class InstanceNormCPUKernel : public InnerKernel { 27 public: InstanceNormCPUKernel(OpParameter * parameter,const std::vector<lite::Tensor * > & inputs,const std::vector<lite::Tensor * > & outputs,const lite::InnerContext * ctx)28 InstanceNormCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs, 29 const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx) 30 : InnerKernel(parameter, inputs, outputs, ctx) { 31 param_ = reinterpret_cast<InstanceNormParameter *>(parameter); 32 } ~InstanceNormCPUKernel()33 ~InstanceNormCPUKernel() override{}; 34 35 int Init() override; 36 int ReSize() override; 37 int Run() override; 38 int DoInstanceNorm(int task_id); FreeTmpBuffer()39 void FreeTmpBuffer() { 40 if (tmp_src_data_ != nullptr) { 41 ms_context_->allocator->Free(tmp_src_data_); 42 tmp_src_data_ = nullptr; 43 } 44 } 45 46 private: 47 InstanceNormParameter *param_ = nullptr; 48 float *src_data_ = nullptr; 49 float *tmp_src_data_ = nullptr; 50 float *dst_data_ = nullptr; 51 float *gamma_data_ = nullptr; 52 float *beta_data_ = nullptr; 53 }; 54 } // namespace mindspore::kernel 55 56 #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_INSTANCE_NORM_H_ 57