!11525 [MS][LITE][CPU]optimize reshape,squeeze,tile,strideslice op
From: @fuzhiye Reviewed-by: @zhanghaibo5,@zhang_xue_tong Signed-off-by: @zhang_xue_tongpull/11525/MERGE
commit
01b77c448a
@ -1,35 +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_RESHAHPE_BASE_H_
|
|
||||||
#define MINDSPORE_LITE_NNACL_RESHAHPE_BASE_H_
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "nnacl/op_base.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline void Reshape(const void *input_ptr, void *output_ptr, size_t data_size) {
|
|
||||||
memcpy(output_ptr, input_ptr, data_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MINDSPORE_LITE_NNACL_RESHAHPE_BASE_H_
|
|
@ -1,38 +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_SQUEEZE_BASE_H_
|
|
||||||
#define MINDSPORE_LITE_NNACL_SQUEEZE_BASE_H_
|
|
||||||
|
|
||||||
#include "nnacl/errorcode.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int DoSqueeze(const void *input_ptr, void *output_ptr, size_t data_size) {
|
|
||||||
if (input_ptr == NULL || output_ptr == NULL) {
|
|
||||||
return NNACL_ERR;
|
|
||||||
}
|
|
||||||
(void)memcpy(output_ptr, input_ptr, data_size);
|
|
||||||
return NNACL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MINDSPORE_LITE_NNACL_SQUEEZE_BASE_H_
|
|
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* 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/reshape_base.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_Reshape;
|
||||||
|
|
||||||
|
namespace mindspore::kernel {
|
||||||
|
int ReshapeBaseCPUKernel::Init() { return ReSize(); }
|
||||||
|
|
||||||
|
int ReshapeBaseCPUKernel::ReSize() {
|
||||||
|
int in_data_size = in_tensors_.front()->Size();
|
||||||
|
int thread_num = context_->thread_num_;
|
||||||
|
cal_max_num_per_thread_ = UP_DIV(in_data_size, thread_num);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ReshapeBaseCPUKernel::RunImpl(int task_id) {
|
||||||
|
size_t start_index = task_id * cal_max_num_per_thread_;
|
||||||
|
auto cur_in_ptr = input_ptr_ + start_index;
|
||||||
|
auto cur_out_ptr = output_ptr_ + start_index;
|
||||||
|
size_t data_size = in_tensors_.front()->Size() - start_index;
|
||||||
|
data_size = data_size > cal_max_num_per_thread_ ? cal_max_num_per_thread_ : data_size;
|
||||||
|
memcpy(cur_out_ptr, cur_in_ptr, data_size);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ReshapeRun(void *cdata, int task_id) {
|
||||||
|
auto reshape = reinterpret_cast<ReshapeBaseCPUKernel *>(cdata);
|
||||||
|
auto ret = reshape->RunImpl(task_id);
|
||||||
|
if (ret != RET_OK) {
|
||||||
|
MS_LOG(ERROR) << "ReshapeRun error task_id[" << task_id << "] error_code[" << ret << "]";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ReshapeBaseCPUKernel::Run() {
|
||||||
|
input_ptr_ = reinterpret_cast<uint8_t *>(in_tensors_.at(kInputIndex)->data_c());
|
||||||
|
output_ptr_ = reinterpret_cast<uint8_t *>(out_tensors_.at(kOutputIndex)->data_c());
|
||||||
|
auto ret = ParallelLaunch(this->context_->thread_pool_, ReshapeRun, this, context_->thread_num_);
|
||||||
|
if (ret != RET_OK) {
|
||||||
|
MS_LOG(ERROR) << "Reshape run error error_code[" << ret << "]";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reshape, LiteKernelCreator<ReshapeBaseCPUKernel>)
|
||||||
|
REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reshape, LiteKernelCreator<ReshapeBaseCPUKernel>)
|
||||||
|
REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reshape, LiteKernelCreator<ReshapeBaseCPUKernel>)
|
||||||
|
} // namespace mindspore::kernel
|
@ -1,43 +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/fp16/reshape_fp16.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_Reshape;
|
|
||||||
|
|
||||||
namespace mindspore::kernel {
|
|
||||||
|
|
||||||
int ReshapeFp16CPUKernel::Run() {
|
|
||||||
auto in_tensor = in_tensors_.at(kInputIndex);
|
|
||||||
auto out_tensor = out_tensors_.at(kOutputIndex);
|
|
||||||
|
|
||||||
float16_t *input_ptr = reinterpret_cast<float16_t *>(in_tensor->data_c());
|
|
||||||
float16_t *output_ptr = reinterpret_cast<float16_t *>(out_tensor->data_c());
|
|
||||||
|
|
||||||
Reshape(input_ptr, output_ptr, out_tensor->Size());
|
|
||||||
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reshape, LiteKernelCreator<ReshapeFp16CPUKernel>)
|
|
||||||
} // namespace mindspore::kernel
|
|
@ -1,45 +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/reshape_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_Reshape;
|
|
||||||
|
|
||||||
namespace mindspore::kernel {
|
|
||||||
int ReshapeCPUKernel::Init() { return RET_OK; }
|
|
||||||
|
|
||||||
int ReshapeCPUKernel::ReSize() { return RET_OK; }
|
|
||||||
|
|
||||||
int ReshapeCPUKernel::Run() {
|
|
||||||
auto input_ptr = in_tensors_.at(kInputIndex)->data_c();
|
|
||||||
auto output_ptr = out_tensors_.at(kOutputIndex)->data_c();
|
|
||||||
size_t data_size = in_tensors_.at(kInputIndex)->Size();
|
|
||||||
MS_ASSERT(input_ptr);
|
|
||||||
MS_ASSERT(output_ptr);
|
|
||||||
Reshape(input_ptr, output_ptr, data_size);
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reshape, LiteKernelCreator<ReshapeCPUKernel>)
|
|
||||||
REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reshape, LiteKernelCreator<ReshapeCPUKernel>)
|
|
||||||
} // namespace mindspore::kernel
|
|
@ -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_SQUEEZE_H_
|
|
||||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SQUEEZE_H_
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "src/lite_kernel.h"
|
|
||||||
#include "nnacl/base/squeeze_base.h"
|
|
||||||
|
|
||||||
namespace mindspore::kernel {
|
|
||||||
|
|
||||||
class SqueezeCPUKernel : public LiteKernel {
|
|
||||||
public:
|
|
||||||
explicit SqueezeCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs,
|
|
||||||
const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx,
|
|
||||||
const mindspore::lite::PrimitiveC *primitive)
|
|
||||||
: LiteKernel(parameter, inputs, outputs, ctx, primitive) {}
|
|
||||||
~SqueezeCPUKernel() override = default;
|
|
||||||
|
|
||||||
int Init() override;
|
|
||||||
int ReSize() override;
|
|
||||||
int Run() override;
|
|
||||||
};
|
|
||||||
} // namespace mindspore::kernel
|
|
||||||
|
|
||||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SQUEEZE_H_
|
|
Loading…
Reference in new issue