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> |
Louis Verhaard | 226ecaf | 2021-03-30 10:18:28 +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. |
Rickard Bolin | bc6ee58 | 2022-11-04 08:24:29 +0000 | [diff] [blame] | 16 | # |
Louis Verhaard | 226ecaf | 2021-03-30 10:18:28 +0200 | [diff] [blame] | 17 | # Description: |
| 18 | # Contains unit tests for tensor allocation |
| 19 | import pytest |
| 20 | |
| 21 | from ethosu.vela.data_type import DataType |
| 22 | from ethosu.vela.errors import AllocationError |
| 23 | from ethosu.vela.live_range import LiveRangeGraph |
| 24 | from ethosu.vela.tensor import Tensor |
| 25 | from ethosu.vela.tensor_allocation import verify_allocation |
| 26 | |
| 27 | |
| 28 | def test_verify_allocation(): |
| 29 | # Create live range graph with 2 live ranges with overlapping start/end time |
| 30 | lr_graph = LiveRangeGraph() |
| 31 | t1 = Tensor([1, 100, 10, 10], DataType.int8, "t1") |
| 32 | lr1 = lr_graph.get_or_create_range(t1) |
| 33 | lr1.mark_usage(4) |
| 34 | lr1.mark_usage(8) |
| 35 | t2 = Tensor([1, 10, 20, 10], DataType.int8, "t2") |
| 36 | lr2 = lr_graph.get_or_create_range(t2) |
| 37 | # Set overlapping addresses, should lead to verification failure |
| 38 | lr1.set_address(16) |
| 39 | lr2.set_address(32) |
| 40 | lr2.mark_usage(7) |
| 41 | lr2.mark_usage(12) |
| 42 | with pytest.raises(AllocationError): |
| 43 | verify_allocation(lr_graph, 16) |
| 44 | # Set non-overlapping addresses, verification should now succeed |
| 45 | lr2.set_address(None) |
| 46 | lr2.set_address(160000) |
| 47 | verify_allocation(lr_graph, 16) |