From 5c744c0918d69770ffbf37d04891c23cb3b37965 Mon Sep 17 00:00:00 2001 From: ling Date: Thu, 28 Jan 2021 17:21:36 +0800 Subject: [PATCH] expand dims & flatten & squeeze & unsqueeze --- mindspore/lite/nnacl/base/expand_dims_base.h | 36 ------- mindspore/lite/nnacl/base/unsqueeze_base.h | 34 ------- mindspore/lite/nnacl/fp32/expandDims_fp32.c | 15 --- .../runtime/kernel/arm/base/reshape_base.cc | 18 ++++ .../runtime/kernel/arm/base/squeeze_base.cc | 27 ----- .../runtime/kernel/arm/base/squeeze_base.h | 34 ------- .../kernel/arm/fp32/expandDims_fp32.cc | 98 ------------------- .../runtime/kernel/arm/fp32/expandDims_fp32.h | 54 ---------- .../runtime/kernel/arm/fp32/flatten_fp32.cc | 46 --------- .../runtime/kernel/arm/fp32/flatten_fp32.h | 40 -------- .../runtime/kernel/arm/fp32/unsqueeze_fp32.cc | 88 ----------------- .../runtime/kernel/arm/fp32/unsqueeze_fp32.h | 49 ---------- 12 files changed, 18 insertions(+), 521 deletions(-) delete mode 100644 mindspore/lite/nnacl/base/expand_dims_base.h delete mode 100644 mindspore/lite/nnacl/base/unsqueeze_base.h delete mode 100644 mindspore/lite/nnacl/fp32/expandDims_fp32.c delete mode 100644 mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc delete mode 100644 mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h delete mode 100644 mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.cc delete mode 100644 mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.h delete mode 100644 mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.cc delete mode 100644 mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.h delete mode 100644 mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.cc delete mode 100644 mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.h diff --git a/mindspore/lite/nnacl/base/expand_dims_base.h b/mindspore/lite/nnacl/base/expand_dims_base.h deleted file mode 100644 index 542216ef9a6..00000000000 --- a/mindspore/lite/nnacl/base/expand_dims_base.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_LITE_NNACL_EXPAND_DIMS_BASE_H_ -#define MINDSPORE_LITE_NNACL_EXPAND_DIMS_BASE_H_ - -#include "nnacl/op_base.h" -#include "nnacl/errorcode.h" - -#ifdef __cplusplus -extern "C" { -#endif - -inline int ExpandDims(const void *input_ptr, void *output_ptr, size_t data_size) { - memcpy(output_ptr, input_ptr, data_size); - return NNACL_OK; -} - -#ifdef __cplusplus -} -#endif - -#endif // MINDSPORE_LITE_NNACL_EXPAND_DIMS_BASE_H_ diff --git a/mindspore/lite/nnacl/base/unsqueeze_base.h b/mindspore/lite/nnacl/base/unsqueeze_base.h deleted file mode 100644 index 7bd536d6708..00000000000 --- a/mindspore/lite/nnacl/base/unsqueeze_base.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_LITE_NNACL_BASE_UNSQUEEZE_BASE_H_ -#define MINDSPORE_LITE_NNACL_BASE_UNSQUEEZE_BASE_H_ - -#include "nnacl/op_base.h" -#include "nnacl/errorcode.h" - -#ifdef __cplusplus -extern "C" { -#endif -int Unsqueeze(const int8_t *input_ptr, int8_t *output_ptr, size_t data_size) { - memcpy(output_ptr, input_ptr, data_size); - return NNACL_OK; -} -#ifdef __cplusplus -} -#endif - -#endif // MINDSPORE_LITE_NNACL_BASE_UNSQUEEZE_BASE_H_ diff --git a/mindspore/lite/nnacl/fp32/expandDims_fp32.c b/mindspore/lite/nnacl/fp32/expandDims_fp32.c deleted file mode 100644 index ebb8decd086..00000000000 --- a/mindspore/lite/nnacl/fp32/expandDims_fp32.c +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc index 9da7d0e779f..767e4e22355 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc @@ -22,7 +22,11 @@ using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_ExpandDims; +using mindspore::schema::PrimitiveType_Flatten; using mindspore::schema::PrimitiveType_Reshape; +using mindspore::schema::PrimitiveType_Squeeze; +using mindspore::schema::PrimitiveType_Unsqueeze; namespace mindspore::kernel { int ReshapeBaseCPUKernel::Init() { return ReSize(); } @@ -68,4 +72,18 @@ int ReshapeBaseCPUKernel::Run() { REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reshape, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reshape, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reshape, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Flatten, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Flatten, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_ExpandDims, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_ExpandDims, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_ExpandDims, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_ExpandDims, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Squeeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Squeeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Squeeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Squeeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Unsqueeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Unsqueeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Unsqueeze, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt64, PrimitiveType_Unsqueeze, LiteKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc deleted file mode 100644 index 2be895eddd9..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "src/runtime/kernel/arm/base/squeeze_base.h" -#include "src/kernel_registry.h" -#include "schema/model_generated.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::schema::PrimitiveType_Squeeze; -namespace mindspore::kernel { -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Squeeze, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Squeeze, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Squeeze, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Squeeze, LiteKernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h deleted file mode 100644 index e9a3a1dd1a7..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ - -#include -#include "src/runtime/kernel/arm/base/reshape_base.h" - -using mindspore::lite::InnerContext; -namespace mindspore::kernel { -class SqueezeBaseCPUKernel : public ReshapeBaseCPUKernel { - public: - SqueezeBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} - ~SqueezeBaseCPUKernel() override = default; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.cc deleted file mode 100644 index 93fac469270..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.cc +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "src/runtime/kernel/arm/fp32/expandDims_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "src/runtime/runtime_api.h" - -using mindspore::kernel::KERNEL_ARCH::kCPU; -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_ExpandDims; - -namespace mindspore::kernel { -int ExpandDimsCPUKernel::Init() { - if (!InferShapeDone()) { - return RET_OK; - } - return ReSize(); -} - -int ExpandDimsCPUKernel::ReSize() { - data_size_ = in_tensors_.at(0)->ElementsNum(); - thread_sz_count_ = MSMIN(thread_count_, static_cast(data_size_)); - thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_); - return RET_OK; -} - -int ExpandDimsCPUKernel::DoExpandDims(int task_id) { - size_t size = MSMIN(thread_sz_stride_, static_cast(data_size_ - task_id * thread_sz_stride_)); - if (size == 0) { - return RET_OK; - } - int offset = task_id * thread_sz_stride_; - if (this->in_tensors_.at(0)->data_type() == kNumberTypeFloat32) { - int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, reinterpret_cast(out_ptr_) + offset, - size * sizeof(float)); - if (ret != RET_OK) { - MS_LOG(ERROR) << "ExpandDimsRun error task_id[" << task_id << "] error_code[" << ret << "]"; - return ret; - } - } else if (this->in_tensors_.at(0)->data_type() == kNumberTypeInt8) { - int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, reinterpret_cast(out_ptr_) + offset, - size * sizeof(int8_t)); - if (ret != RET_OK) { - MS_LOG(ERROR) << "ExpandDimsRun error task_id[" << task_id << "] error_code[" << ret << "]"; - return ret; - } - } else if (this->in_tensors_.at(0)->data_type() == kNumberTypeInt32) { - int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, reinterpret_cast(out_ptr_) + offset, - size * sizeof(int32_t)); - if (ret != RET_OK) { - MS_LOG(ERROR) << "ExpandDimsRun error task_id[" << task_id << "] error_code[" << ret << "]"; - return ret; - } - } - return RET_OK; -} - -int ExpandDimsRun(void *cdata, int task_id) { - auto g_kernel = reinterpret_cast(cdata); - auto ret = g_kernel->DoExpandDims(task_id); - if (ret != RET_OK) { - MS_LOG(ERROR) << "ExpandDimsRun error task_id[" << task_id << "] error_code[" << ret << "]"; - return ret; - } - return RET_OK; -} - -int ExpandDimsCPUKernel::Run() { - in_ptr_ = in_tensors_.at(0)->data_c(); - out_ptr_ = out_tensors_.at(0)->data_c(); - auto ret = ParallelLaunch(this->context_->thread_pool_, ExpandDimsRun, this, thread_sz_count_); - if (ret != RET_OK) { - MS_LOG(ERROR) << "ExpandDimsRun error error_code[" << ret << "]"; - return ret; - } - return RET_OK; -} - -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_ExpandDims, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_ExpandDims, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_ExpandDims, LiteKernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.h deleted file mode 100644 index 5185fea0e4f..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims_fp32.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_EXPANDDIMS_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_EXPANDDIMS_H_ - -#include -#include "include/errorcode.h" -#include "src/lite_kernel.h" -#include "nnacl/base/expand_dims_base.h" -#include "schema/model_generated.h" - -#include "include/context.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class ExpandDimsCPUKernel : public LiteKernel { - public: - ExpandDimsCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) {} - ~ExpandDimsCPUKernel() override = default; - - int Init() override; - int ReSize() override; - int Run() override; - int DoExpandDims(int task_id); - - private: - int thread_sz_count_; - int thread_sz_stride_; - size_t data_size_; - void *in_ptr_; - void *out_ptr_; - int thread_count_; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_CCSRC_KERNEL_CPU_ARM_FP32_EXPANDDIMS_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.cc deleted file mode 100644 index 1f7bbbc0de9..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.cc +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "src/runtime/kernel/arm/fp32/flatten_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" - -using mindspore::kernel::KERNEL_ARCH::kCPU; -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Flatten; - -namespace mindspore::kernel { -int FlattenCPUKernel::Init() { - if (!InferShapeDone()) { - return RET_OK; - } - return ReSize(); -} - -int FlattenCPUKernel::ReSize() { return RET_OK; } - -int FlattenCPUKernel::Run() { - auto input = in_tensors_.at(0); - auto output = out_tensors_.at(0); - memcpy(output->data_c(), input->data_c(), output->Size()); - return RET_OK; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Flatten, LiteKernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.h deleted file mode 100644 index e3274771ba0..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten_fp32.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FLATTEN_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FLATTEN_H_ - -#include -#include "src/lite_kernel.h" -#include "include/context.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class FlattenCPUKernel : public LiteKernel { - public: - FlattenCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} - ~FlattenCPUKernel() override = default; - - int Init() override; - int ReSize() override; - int Run() override; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FLATTEN_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.cc deleted file mode 100644 index eb08f433147..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.cc +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "src/runtime/kernel/arm/fp32/unsqueeze_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "src/runtime/runtime_api.h" -#include "nnacl/base/unsqueeze_base.h" - -using mindspore::kernel::KERNEL_ARCH::kCPU; -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Unsqueeze; - -namespace mindspore::kernel { -int UnsqueezeCPUKernel::Init() { - if (!InferShapeDone()) { - return RET_OK; - } - return ReSize(); -} - -int UnsqueezeCPUKernel::ReSize() { - data_size_ = in_tensors_.at(0)->ElementsNum(); - thread_sz_count_ = MSMIN(context_->thread_num_, data_size_); - if (thread_sz_count_ == 0) { - thread_sz_stride_ = 0; - return RET_OK; - } - thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_); - return RET_OK; -} - -int UnsqueezeCPUKernel::DoUnsqueeze(int task_id) { - size_t size = MSMIN(thread_sz_stride_, data_size_ - task_id * thread_sz_stride_); - if (size == 0) { - return RET_OK; - } - size_t offset = task_id * thread_sz_stride_ * sizeof(float); - MS_ASSERT(in_ptr_); - MS_ASSERT(out_ptr_); - int ret = Unsqueeze(in_ptr_ + offset, out_ptr_ + offset, size * sizeof(float)); - if (ret != RET_OK) { - MS_LOG(ERROR) << "UnsqueezeRun error task_id[" << task_id << "] error_code[" << ret << "]"; - return ret; - } - return RET_OK; -} - -int UnsqueezeRun(void *cdata, int task_id) { - auto g_kernel = reinterpret_cast(cdata); - auto ret = g_kernel->DoUnsqueeze(task_id); - if (ret != RET_OK) { - MS_LOG(ERROR) << "UnsqueezeRun error task_id[" << task_id << "] error_code[" << ret << "]"; - return ret; - } - return RET_OK; -} - -int UnsqueezeCPUKernel::Run() { - in_ptr_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); - out_ptr_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - auto ret = ParallelLaunch(this->context_->thread_pool_, UnsqueezeRun, this, thread_sz_count_); - if (ret != RET_OK) { - MS_LOG(ERROR) << "UnsqueezeRun error error_code[" << ret << "]"; - return ret; - } - return RET_OK; -} -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Unsqueeze, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Unsqueeze, LiteKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt64, PrimitiveType_Unsqueeze, LiteKernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.h deleted file mode 100644 index 4cde2c2cbc2..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze_fp32.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_ - -#include -#include "src/lite_kernel.h" -#include "include/context.h" -#include "nnacl/unsqueeze_parameter.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class UnsqueezeCPUKernel : public LiteKernel { - public: - UnsqueezeCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} - ~UnsqueezeCPUKernel() = default; - - int Init() override; - int ReSize() override; - int Run() override; - int DoUnsqueeze(int task_id); - - private: - int thread_sz_count_; - int thread_sz_stride_; - int data_size_; - int8_t *in_ptr_; - int8_t *out_ptr_; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_