blob: 20ad73adf11479aeafc88177052a8c8d4c27017b [file] [log] [blame]
Rickard Bolinbc6ee582022-11-04 08:24:29 +00001# SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
Louis Verhaard226ecaf2021-03-30 10:18:28 +02002#
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 Bolinbc6ee582022-11-04 08:24:29 +000016#
Louis Verhaard226ecaf2021-03-30 10:18:28 +020017# Description:
18# Contains unit tests for tensor allocation
19import pytest
20
21from ethosu.vela.data_type import DataType
22from ethosu.vela.errors import AllocationError
23from ethosu.vela.live_range import LiveRangeGraph
24from ethosu.vela.tensor import Tensor
25from ethosu.vela.tensor_allocation import verify_allocation
26
27
28def 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)