From 3a0eed82844fc3a0332f371b33a0774f8b40bbc5 Mon Sep 17 00:00:00 2001 From: wangzhe Date: Mon, 8 Mar 2021 18:59:01 +0800 Subject: [PATCH] scheduler add fitkernel --- ..._shape.h => constant_of_shape_parameter.h} | 21 ++-------- .../lite/nnacl/fp16/constant_of_shape_fp16.h | 41 +++++++++++++++++++ .../constant_of_shape_fp32.h} | 24 ++++++++--- .../nnacl/infer/constant_of_shape_infer.h | 2 +- .../populate/constant_of_shape_populate.cc | 2 +- .../v0/constant_of_shape_populate_v0.cc | 2 +- .../kernel/arm/base/constant_of_shape.cc | 6 +++ .../kernel/arm/base/constant_of_shape.h | 4 +- mindspore/lite/src/scheduler.cc | 32 +++++++++++++++ mindspore/lite/src/scheduler.h | 2 + 10 files changed, 110 insertions(+), 26 deletions(-) rename mindspore/lite/nnacl/{constant_of_shape.h => constant_of_shape_parameter.h} (61%) create mode 100644 mindspore/lite/nnacl/fp16/constant_of_shape_fp16.h rename mindspore/lite/nnacl/{constant_of_shape.c => fp32/constant_of_shape_fp32.h} (54%) diff --git a/mindspore/lite/nnacl/constant_of_shape.h b/mindspore/lite/nnacl/constant_of_shape_parameter.h similarity index 61% rename from mindspore/lite/nnacl/constant_of_shape.h rename to mindspore/lite/nnacl/constant_of_shape_parameter.h index 12bf757c9d..813fdf488d 100644 --- a/mindspore/lite/nnacl/constant_of_shape.h +++ b/mindspore/lite/nnacl/constant_of_shape_parameter.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 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. @@ -13,14 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_H_ -#define MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_H_ +#ifndef MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_PARAMETER_H_ +#define MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_PARAMETER_H_ -#ifdef ENABLE_NEON -#include -#endif #include "nnacl/op_base.h" -#include "nnacl/errorcode.h" typedef struct ConstantOfShapeParameter { OpParameter op_parameter_; @@ -32,13 +28,4 @@ typedef struct ConstantOfShapeParameter { int element_size_; } ConstantOfShapeParameter; -#ifdef __cplusplus -extern "C" { -#endif -int ConstantOfShapeFp32(float *output, int start, int end, float value); -int ConstantOfShapeInt32(int32_t *output, int start, int end, int32_t value); -#ifdef __cplusplus -} -#endif - -#endif // MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_H_ +#endif // MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_PARAMETER_H_ diff --git a/mindspore/lite/nnacl/fp16/constant_of_shape_fp16.h b/mindspore/lite/nnacl/fp16/constant_of_shape_fp16.h new file mode 100644 index 0000000000..a414b50b40 --- /dev/null +++ b/mindspore/lite/nnacl/fp16/constant_of_shape_fp16.h @@ -0,0 +1,41 @@ +/** + * Copyright 2020-2021 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_FP16_CONSTANT_OF_SHAPE_FP16_H_ +#define MINDSPORE_LITE_NNACL_FP16_CONSTANT_OF_SHAPE_FP16_H_ + +#ifdef ENABLE_NEON +#include +#endif +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/constant_of_shape_parameter.h" + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +#ifdef ENABLE_NEON +inline int ConstantOfShapeFp16(float16_t *output, int start, int end, float16_t value) { + for (int i = start; i < end; i++) { + output[i] = value; + } + return NNACL_OK; +} +#endif +} +#endif + +#endif // MINDSPORE_LITE_NNACL_FP16_CONSTANT_OF_SHAPE_FP16_H_ diff --git a/mindspore/lite/nnacl/constant_of_shape.c b/mindspore/lite/nnacl/fp32/constant_of_shape_fp32.h similarity index 54% rename from mindspore/lite/nnacl/constant_of_shape.c rename to mindspore/lite/nnacl/fp32/constant_of_shape_fp32.h index ce37a11484..672d30a5e5 100644 --- a/mindspore/lite/nnacl/constant_of_shape.c +++ b/mindspore/lite/nnacl/fp32/constant_of_shape_fp32.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 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. @@ -13,19 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef MINDSPORE_LITE_NNACL_FP32_CONSTANT_OF_SHAPE_FP32_H_ +#define MINDSPORE_LITE_NNACL_FP32_CONSTANT_OF_SHAPE_FP32_H_ +#include +#include +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/constant_of_shape_parameter.h" -#include "nnacl/constant_of_shape.h" - -int ConstantOfShapeInt32(int32_t *output, int start, int end, int32_t value) { +#ifdef __cplusplus +extern "C" { +#endif +inline int ConstantOfShapeInt32(int32_t *output, int start, int end, int32_t value) { for (int i = start; i < end; i++) { output[i] = value; } return NNACL_OK; } -int ConstantOfShapeFp32(float *output, int start, int end, float value) { +inline int ConstantOfShapeFp32(float *output, int start, int end, float value) { for (int i = start; i < end; i++) { output[i] = value; } return NNACL_OK; } + +#ifdef __cplusplus +} +#endif + +#endif // MINDSPORE_LITE_NNACL_FP32_CONSTANT_OF_SHAPE_FP32_H_ diff --git a/mindspore/lite/nnacl/infer/constant_of_shape_infer.h b/mindspore/lite/nnacl/infer/constant_of_shape_infer.h index 2c51287201..4fb53ec4d3 100644 --- a/mindspore/lite/nnacl/infer/constant_of_shape_infer.h +++ b/mindspore/lite/nnacl/infer/constant_of_shape_infer.h @@ -17,7 +17,7 @@ #define MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_INFER_H #include "nnacl/infer/common_infer.h" -#include "nnacl/constant_of_shape.h" +#include "nnacl/constant_of_shape_parameter.h" #ifdef __cplusplus extern "C" { diff --git a/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc b/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc index 89997653c4..a6c89a795d 100644 --- a/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc +++ b/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc @@ -14,7 +14,7 @@ * limitations under the License. */ #include "src/ops/populate/populate_register.h" -#include "nnacl/constant_of_shape.h" +#include "nnacl/constant_of_shape_parameter.h" namespace mindspore::lite { namespace { diff --git a/mindspore/lite/src/ops/populate/v0/constant_of_shape_populate_v0.cc b/mindspore/lite/src/ops/populate/v0/constant_of_shape_populate_v0.cc index 761def4190..cb40ba5be2 100644 --- a/mindspore/lite/src/ops/populate/v0/constant_of_shape_populate_v0.cc +++ b/mindspore/lite/src/ops/populate/v0/constant_of_shape_populate_v0.cc @@ -16,7 +16,7 @@ #include "schema/model_v0_generated.h" #include "src/ops/populate/populate_register.h" -#include "nnacl/constant_of_shape.h" +#include "nnacl/constant_of_shape_parameter.h" namespace mindspore::lite { namespace { diff --git a/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc b/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc index 7ed1d51a9d..bcb2d92d10 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc @@ -52,6 +52,12 @@ int ConstantOfShapeCPUKernel::DoExecute(int task_id) { ConstantOfShapeInt32(reinterpret_cast(output_ptr_), start, start + current_stride, param_->value_.int32_value_); break; +#ifdef ENABLE_NEON + case kNumberTypeFloat16: + ConstantOfShapeFp16(reinterpret_cast(output_ptr_), start, start + current_stride, + param_->value_.f32_value_); + break; +#endif default: MS_LOG(ERROR) << "Invalid datatype in ConstantOfShapeRun"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.h b/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.h index fd2fab96e8..0fa4174f08 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.h @@ -20,7 +20,9 @@ #include "include/errorcode.h" #include "src/lite_kernel.h" #include "include/context.h" -#include "nnacl/constant_of_shape.h" +#include "nnacl/constant_of_shape_parameter.h" +#include "nnacl/fp32/constant_of_shape_fp32.h" +#include "nnacl/fp16/constant_of_shape_fp16.h" namespace mindspore::kernel { class ConstantOfShapeCPUKernel : public LiteKernel { diff --git a/mindspore/lite/src/scheduler.cc b/mindspore/lite/src/scheduler.cc index 810e96c54b..65152bbedf 100644 --- a/mindspore/lite/src/scheduler.cc +++ b/mindspore/lite/src/scheduler.cc @@ -387,6 +387,38 @@ int Scheduler::ScheduleSubGraphToKernels(size_t subgraph_index, std::vector Scheduler::FindAllSubGraphKernels( kernel::LiteKernel *head_kernel, std::map *sinked_kernel_map) { MS_ASSERT(head_kernel != nullptr); diff --git a/mindspore/lite/src/scheduler.h b/mindspore/lite/src/scheduler.h index ebf0fbe28b..79e32fe3df 100644 --- a/mindspore/lite/src/scheduler.h +++ b/mindspore/lite/src/scheduler.h @@ -68,6 +68,8 @@ class Scheduler { bool MergeOpIsReady(const kernel::LiteKernel *kernel, std::map is_kernel_finish); + bool KernelFitCurrentSubGraph(const kernel::SubGraphType subgraph_type, const kernel::LiteKernel &kernel); + std::vector FindAllSubGraphKernels( kernel::LiteKernel *head_kernel, std::map *sinked_kernel_map);