blob: 62a1b76359226c539be74939373a2fe284370a8e [file] [log] [blame]
Andreas Nevalainen15a8e802020-11-16 09:14:52 +01001# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Description:
18# Unit tests for graph_optimiser
19import numpy as np
20
21from ethosu.vela.graph_optimiser import convert_batched_fc_shape
22from ethosu.vela.operation import Op
23from ethosu.vela.tensor import create_const_tensor
24from ethosu.vela.tensor import Tensor
25from ethosu.vela.test import testutil
26
27
28def test_convert_batched_fc():
29 """Tests shape conversion of batched fully connected"""
30 shape = [4, 8]
31 ifm = create_const_tensor("test_in", shape, np.uint8, np.zeros(shape))
32 weights = create_const_tensor("weight_in", shape, np.uint8, np.zeros(shape))
33 ofm = Tensor(ifm.shape, np.uint8, "test_out")
34 op = testutil.create_op(Op.FullyConnected, [ifm, weights], ofm)
35 ifm.consumer_list.append(op)
36
37 prev_op = op.clone()
38 conv_op = convert_batched_fc_shape(op, None, None)
39
40 assert conv_op.ifm != prev_op.ifm
41 assert conv_op.ofm != prev_op.ofm
42 assert conv_op.type == Op.FullyConnected
43 assert len(conv_op.ifm.shape) == 4
44 assert conv_op.ifm.shape == conv_op.ofm.shape
45 assert conv_op.ifm.ops[0].type == Op.Reshape
46
47 shape = [1, 8]
48 ifm.shape = shape
49 weights.shape = shape
50 ofm.shape = shape
51 op = testutil.create_op(Op.FullyConnected, [ifm, weights], ofm)
52 ifm.consumer_list.append(op)
53
54 prev_op = op.clone()
55 conv_op = convert_batched_fc_shape(op, None, None)
56
57 assert conv_op.ifm == prev_op.ifm
58 assert conv_op.ofm == prev_op.ofm
59 assert conv_op.type == Op.FullyConnected
60 assert len(conv_op.ifm.shape) == 2
61 assert conv_op.ifm.shape == conv_op.ofm.shape