Rickard Bolin | bc6ee58 | 2022-11-04 08:24:29 +0000 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: Copyright 2020 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Louis Verhaard | 0b9c9a3 | 2020-09-15 14:05:38 +0200 | [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. |
| 16 | # |
| 17 | # Description: |
| 18 | # Unit tests for compiler driver |
| 19 | from ethosu.vela.compiler_driver import next_sram_factor |
| 20 | |
| 21 | |
| 22 | def test_next_sram_factor(): |
| 23 | lower = 0.7 |
| 24 | assert (1.0, False) == next_sram_factor([]) |
| 25 | assert (None, False) == next_sram_factor([True]) |
| 26 | assert (lower, True) == next_sram_factor([False]) |
| 27 | assert ((1 + lower) / 2, True) == next_sram_factor([False, True]) |
| 28 | assert (lower / 2, True) == next_sram_factor([False, False]) |
| 29 | # Tests next_sram_factor for a range of simulated allocator efficiencies |
| 30 | for i in range(20): |
| 31 | allocator_factor = i / 20.0 # The simulated allocator efficiency |
| 32 | alloc_results = [] |
| 33 | bisected_factor = 0 # The end result of the bisect search |
| 34 | while True: |
| 35 | factor, dry_test = next_sram_factor(alloc_results) |
| 36 | if factor is None: |
| 37 | break |
| 38 | alloc_result = factor < allocator_factor |
| 39 | if alloc_result and not dry_test: |
| 40 | bisected_factor = factor |
| 41 | alloc_results.append(alloc_result) |
| 42 | assert len(alloc_results) < 100 |
| 43 | assert bisected_factor <= allocator_factor |
| 44 | assert abs(bisected_factor - allocator_factor) < 0.02 |