From 9f0138b7de6976dff75fd42d54649b070e50ecb5 Mon Sep 17 00:00:00 2001 From: zengxianglong Date: Sat, 10 Jul 2021 16:02:53 +0800 Subject: [PATCH] allow reduce op has only one input when axes param is not given --- .../kernel_compiler/cpu/nnacl/infer/reduce_infer.c | 8 ++++---- mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc | 2 -- mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.h | 1 - mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc | 2 -- mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.h | 1 - .../tools/converter/parser/onnx/onnx_reduce_parser.cc | 2 +- 6 files changed, 5 insertions(+), 11 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/reduce_infer.c b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/reduce_infer.c index cd2d4ecfd4b..30170c5c7d6 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/reduce_infer.c +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/reduce_infer.c @@ -52,7 +52,7 @@ int ReduceOnSelectedAxes(const TensorC *input, size_t num_axes, const int *actua int ReduceInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size, OpParameter *parameter) { - int check_ret = CheckAugmentNullSize(inputs, inputs_size, outputs, outputs_size, parameter, 2, 1); + int check_ret = CheckAugmentNullSizeInputTwo(inputs, inputs_size, outputs, outputs_size, parameter, 1, 2, 1); if (check_ret != NNACL_OK) { return check_ret; } @@ -70,11 +70,11 @@ int ReduceInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC * bool keep_dims = param->keep_dims_; int out_shape[MAX_SHAPE_SIZE] = {0}; const size_t out_shape_size = 0; - // get axes from input tensor - const TensorC *axes_input = inputs[1]; - if (axes_input->shape_size_ == 1 && axes_input->shape_[0] == 0) { + if (inputs_size == 1) { return ReduceOnAllAxes(input, output, out_shape, out_shape_size, keep_dims); } + // get axes from input tensor + const TensorC *axes_input = inputs[1]; int *axes = (int *)axes_input->data_; if (axes == NULL) { return NNACL_NULL_PTR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc index ace7716a413..d1f2755bb5b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc @@ -59,8 +59,6 @@ int ReduceFp16CPUKernel::Init() { return ReSize(); } -int ReduceFp16CPUKernel::ReSize() { return ReduceBaseCPUKernel::ReSize(); } - int ReduceFp16CPUKernel::CallReduceUnit(int task_id) { auto ret = reducer_(outer_size_, inner_size_, axis_size_, fp16_src_data_, fp16_dst_data_, task_id, op_parameter_->thread_num_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.h index a56736d8d48..49c34e3edf6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.h @@ -36,7 +36,6 @@ class ReduceFp16CPUKernel : public ReduceBaseCPUKernel { ~ReduceFp16CPUKernel() = default; int Init() override; - int ReSize() override; int Run() override; int CallReduceUnit(int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc index e143ad83479..65b545f1fa6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc @@ -53,8 +53,6 @@ int ReduceCPUKernel::Init() { return ReSize(); } -int ReduceCPUKernel::ReSize() { return ReduceBaseCPUKernel::ReSize(); } - int ReduceCPUKernel::CallReduceUnit(int task_id) { if (data_type_ == kDataTypeFloat) { if (!reducer_) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.h index fb1876151b9..b890c4119f8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.h @@ -54,7 +54,6 @@ class ReduceCPUKernel : public ReduceBaseCPUKernel { } int Init() override; - int ReSize() override; int Run() override; int CallReduceUnit(int task_id); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc index 5b7f8f1fb4d..84934ffaf88 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc @@ -34,11 +34,11 @@ ops::PrimitiveC *OnnxReduceParser::Parse(const onnx::GraphProto &onnx_graph, con for (int i = 0; i < size; ++i) { axes.push_back(onnx_node_attr.ints(i)); } + prim->AddAttr("axes", MakeValue(axes)); } else if (attribute_name == "keepdims") { prim->set_keep_dims(static_cast(onnx_node_attr.i())); } } - prim->AddAttr("axes", MakeValue(axes)); const auto &type = onnx_node.op_type(); if (type == "ReduceMean") {