Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 1 | # 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 tensor_allocator. |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame^] | 19 | import pytest |
| 20 | |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 21 | from ethosu import tensor_allocator |
| 22 | |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame^] | 23 | test_data = [ |
| 24 | ([(0, 100, 8000), (0, 1, 8016), (100, 110, 2000), (108, 110, 4000), (109, 110, 6000)], 16016), |
| 25 | ( |
| 26 | [ |
| 27 | (0, 23, 131072), |
| 28 | (4, 5, 65568), |
| 29 | (4, 9, 8192), |
| 30 | (8, 30, 15360), |
| 31 | (10, 11, 65568), |
| 32 | (10, 15, 4096), |
| 33 | (16, 17, 65552), |
| 34 | (16, 21, 2048), |
| 35 | (22, 23, 32784), |
| 36 | (22, 27, 1024), |
| 37 | ], |
| 38 | 216096, |
| 39 | ), |
| 40 | ] |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 41 | |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame^] | 42 | |
| 43 | @pytest.mark.parametrize("lrs, expected_size", test_data) |
| 44 | def test_allocate(lrs, expected_size): |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 45 | """Tests the search allocator""" |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 46 | input = [x for lr in lrs for x in lr] |
| 47 | res = tensor_allocator.allocate(input, 0) |
| 48 | assert len(res) == len(lrs) |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame^] | 49 | assert max(addr + lr[2] for addr, lr in zip(res, lrs)) == expected_size |