James Ward | 6bf1613 | 2021-09-08 11:14:20 +0100 | [diff] [blame] | 1 | # Copyright (C) 2021 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 | # Description: |
| 17 | # Unit tests for the mapping of TFLite or TOSA to NNG |
| 18 | import pytest |
| 19 | |
| 20 | from ethosu.vela.tflite_mapping import builtin_operator_map |
| 21 | from ethosu.vela.tosa_mapping import tosa_operator_map |
| 22 | |
| 23 | |
| 24 | class TestNNGMapping: |
| 25 | """Ensure the mappings from TFLite to NNG are consistent.""" |
| 26 | |
| 27 | @pytest.mark.parametrize( |
| 28 | "operator_map", |
| 29 | ((builtin_operator_map), (tosa_operator_map)), |
| 30 | ids=("test_tflite_indices_match_nng", "test_tosa_indices_match_nng"), |
| 31 | ) |
| 32 | def test_op_indices_match(self, operator_map): |
| 33 | """Ensure TFLite/TOSA indices and NNG indices are consistent for each operator.""" |
| 34 | for map_op in operator_map.values(): |
| 35 | op_type = map_op[0] |
| 36 | map_op_indices = map_op[-1] # TFLite/TOSA indices in last element of tuple |
| 37 | |
| 38 | nng_indices = op_type.info.indices |
| 39 | |
| 40 | for idx in range(3): |
| 41 | assert len(map_op_indices[idx]) == len(nng_indices[idx]) |