From 807278a7d3cc305e232c05b7c098a13485f70203 Mon Sep 17 00:00:00 2001 From: Henrik G Olsson Date: Mon, 8 Mar 2021 18:20:00 +0100 Subject: MLBEDSW-4209 Use live range alignment when allocating Change-Id: I05216cebe785a3669032a3f021a9b496c44c4d66 Signed-off-by: Henrik G Olsson --- ethosu/vela/greedy_allocation.py | 9 ++++++--- ethosu/vela/hillclimb_allocation.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'ethosu/vela') diff --git a/ethosu/vela/greedy_allocation.py b/ethosu/vela/greedy_allocation.py index b0395def..51b07805 100644 --- a/ethosu/vela/greedy_allocation.py +++ b/ethosu/vela/greedy_allocation.py @@ -41,9 +41,12 @@ class GreedyAllocator: current_offset = 0 for start_addr, lr in self.current_allocs: aligned_current_offset = numeric_util.round_up(current_offset, new_lr.get_alignment()) - if aligned_current_offset + aligned_size <= start_addr and start_addr - current_offset < best_offset_fit: - best_offset = current_offset - best_offset_fit = start_addr - current_offset + if ( + aligned_current_offset + aligned_size <= start_addr + and start_addr - aligned_current_offset < best_offset_fit + ): + best_offset = aligned_current_offset + best_offset_fit = start_addr - aligned_current_offset current_offset = start_addr + lr.size diff --git a/ethosu/vela/hillclimb_allocation.py b/ethosu/vela/hillclimb_allocation.py index de53ab83..5e02dac0 100644 --- a/ethosu/vela/hillclimb_allocation.py +++ b/ethosu/vela/hillclimb_allocation.py @@ -20,11 +20,12 @@ import random from typing import List from typing import Set +from . import numeric_util from .live_range import LiveRange class LiveRangeInfo: - def __init__(self, id: int, start_time: int, end_time: int, size: int): + def __init__(self, id: int, start_time: int, end_time: int, size: int, min_alignment: int): # Index of this live range self.id = id # Start time (input to the allocator algorithm) @@ -44,6 +45,7 @@ class LiveRangeInfo: # Max value of size_at_time (only used in the heuristic allocation) self.urgency = 0 self.neighbours: List["LiveRangeInfo"] = [] + self.min_alignment = min_alignment def overlaps(self, addr2: int, size2: int) -> int: return self.address < addr2 + size2 and addr2 < self.end_address @@ -96,7 +98,8 @@ class HillClimbAllocator: def __init__(self, live_ranges: List[LiveRange]): # Contains the live ranges self.lrs: List[LiveRangeInfo] = [ - LiveRangeInfo(id, lr.start_time, lr.end_time, lr.size) for id, lr in enumerate(live_ranges) + LiveRangeInfo(id, lr.start_time, lr.end_time, lr.size, lr.get_alignment()) + for id, lr in enumerate(live_ranges) ] self.lrs_at_time = [] # The available size (input to algorithm). @@ -145,7 +148,7 @@ class HillClimbAllocator: if lr2.overlaps(address, lr.size): # Overlap found increase address fits = False - address = lr2.end_address + address = numeric_util.round_up(lr2.end_address, lr.min_alignment) predecessor = lr2.id lr.address = address lr.end_address = address + lr.size -- cgit v1.2.1