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