diff options
author | Diqing Zhong <diqing.zhong@arm.com> | 2020-12-09 15:22:40 +0100 |
---|---|---|
committer | patrik.gustavsson <patrik.gustavsson@arm.com> | 2020-12-14 06:58:24 +0000 |
commit | 94457b175b8646bce089c9924e99686587de8992 (patch) | |
tree | ef83eac89ff7f828c5a517c1ba48b2358ffc8bb1 /ethosu/vela/test/test_graph_optimiser.py | |
parent | 9bfe0f86ea525055954b160a3c678024743030ec (diff) | |
download | ethos-u-vela-94457b175b8646bce089c9924e99686587de8992.tar.gz |
Revert "Revert "MLMBED-3450: Do not convert batched fully connected to conv""
- We have combined estimates for conv and fc, add the fix back
Change-Id: I49a29c716189b37b387df4b46efab5f4e6125994
Signed-off-by: Diqing Zhong <diqing.zhong@arm.com>
Diffstat (limited to 'ethosu/vela/test/test_graph_optimiser.py')
-rw-r--r-- | ethosu/vela/test/test_graph_optimiser.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ethosu/vela/test/test_graph_optimiser.py b/ethosu/vela/test/test_graph_optimiser.py new file mode 100644 index 00000000..62a1b763 --- /dev/null +++ b/ethosu/vela/test/test_graph_optimiser.py @@ -0,0 +1,61 @@ +# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. +# +# Description: +# Unit tests for graph_optimiser +import numpy as np + +from ethosu.vela.graph_optimiser import convert_batched_fc_shape +from ethosu.vela.operation import Op +from ethosu.vela.tensor import create_const_tensor +from ethosu.vela.tensor import Tensor +from ethosu.vela.test import testutil + + +def test_convert_batched_fc(): + """Tests shape conversion of batched fully connected""" + shape = [4, 8] + ifm = create_const_tensor("test_in", shape, np.uint8, np.zeros(shape)) + weights = create_const_tensor("weight_in", shape, np.uint8, np.zeros(shape)) + ofm = Tensor(ifm.shape, np.uint8, "test_out") + op = testutil.create_op(Op.FullyConnected, [ifm, weights], ofm) + ifm.consumer_list.append(op) + + prev_op = op.clone() + conv_op = convert_batched_fc_shape(op, None, None) + + assert conv_op.ifm != prev_op.ifm + assert conv_op.ofm != prev_op.ofm + assert conv_op.type == Op.FullyConnected + assert len(conv_op.ifm.shape) == 4 + assert conv_op.ifm.shape == conv_op.ofm.shape + assert conv_op.ifm.ops[0].type == Op.Reshape + + shape = [1, 8] + ifm.shape = shape + weights.shape = shape + ofm.shape = shape + op = testutil.create_op(Op.FullyConnected, [ifm, weights], ofm) + ifm.consumer_list.append(op) + + prev_op = op.clone() + conv_op = convert_batched_fc_shape(op, None, None) + + assert conv_op.ifm == prev_op.ifm + assert conv_op.ofm == prev_op.ofm + assert conv_op.type == Op.FullyConnected + assert len(conv_op.ifm.shape) == 2 + assert conv_op.ifm.shape == conv_op.ofm.shape |