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