From ae7766cdace8174aac5741e13a8b2cdaf208575d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=9E=E8=BF=9E=E9=A3=9E?= Date: Tue, 27 Nov 2018 11:25:50 +0800 Subject: [PATCH] optimize eltwise computing order --- mace/ops/eltwise.cc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/mace/ops/eltwise.cc b/mace/ops/eltwise.cc index 9bca9033..373210b3 100644 --- a/mace/ops/eltwise.cc +++ b/mace/ops/eltwise.cc @@ -900,23 +900,21 @@ class EltwiseOp : public Operation { } } - if (need_general_broadcast) { + if (input1->size() == 1) { + TensorScalarEltwise(type_, input0_ptr, input1_ptr[0], coeff_, + input0->size(), swapped, output_ptr); + } else if (input0_shape == input1_shape) { + TensorEltwise(type_, input0_ptr, input1_ptr, coeff_, input0->size(), + swapped, output_ptr); + } else if (need_general_broadcast) { TensorGeneralBroadcastEltwise(type_, input0_ptr, input1_ptr, coeff_, swapped, input0_shape, input1_shape, output_shape, output_ptr); - } else if (input1->size() == input0->size()) { - TensorEltwise(type_, input0_ptr, input1_ptr, coeff_, input0->size(), - swapped, output_ptr); - } else if (input1->size() < input0->size()) { - if (input1->size() > 1) { - index_t common_size = input1->size(); - index_t diff_size = input0->size() / common_size; - TensorBroadcastEltwise(type_, input0_ptr, input1_ptr, coeff_, - diff_size, common_size, swapped, output_ptr); - } else { - TensorScalarEltwise(type_, input0_ptr, input1_ptr[0], coeff_, - input0->size(), swapped, output_ptr); - } + } else { + index_t common_size = input1->size(); + index_t diff_size = input0->size() / common_size; + TensorBroadcastEltwise(type_, input0_ptr, input1_ptr, coeff_, + diff_size, common_size, swapped, output_ptr); } } -- GitLab