Skip to content

Commit

Permalink
Merge pull request #40 from Moyne/db_support
Browse files Browse the repository at this point in the history
feat: db param and memory allocation
  • Loading branch information
asyms authored Feb 1, 2024
2 parents 22deb32 + 2ac0c32 commit fc08868
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions zigzag/classes/hardware/architecture/memory_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MemoryInstance:
# @param min_w_granularity (int): The minimal number of bits that can be written in a clock cycle (can be less than w_bw)
# @param mem_type (str): The type of memory. Used for CACTI cost extraction.
# @param auto_cost_extraction (bool): Automatically extract the read cost, write cost and area using CACTI.
# @param double_buffering_support (bool): Support for double buffering on this memory instance.
def __init__(
self,
name: str,
Expand All @@ -35,6 +36,7 @@ def __init__(
min_w_granularity=None,
mem_type: str = "sram",
auto_cost_extraction: bool = False,
double_buffering_support: bool = False,
):
if auto_cost_extraction:
# Size must be a multiple of 8 when using CACTI
Expand Down Expand Up @@ -74,6 +76,7 @@ def __init__(
self.w_port = w_port
self.rw_port = rw_port
self.latency = latency
self.double_buffering_support = double_buffering_support
if not min_r_granularity:
self.r_bw_min = r_bw
else:
Expand Down
15 changes: 13 additions & 2 deletions zigzag/classes/opt/temporal/loma/memory_allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def allocate_node(self, node: MemoryLevel, top_levels: List[MemoryLevel]):
mem_ops = node.operands
# Then select only the mem operands that are required for this layer (e.g. pooling has no weights so one mem op less)
mem_ops = [mem_op for mem_op in mem_ops if mem_op in self.mem_ops]

# Does this node support double buffering
db_support=node.memory_instance.double_buffering_support
# Get the capacity of this memory node (in bits)
mem_capacity = node.memory_instance.size

Expand Down Expand Up @@ -178,7 +179,8 @@ def allocate_node(self, node: MemoryLevel, top_levels: List[MemoryLevel]):
# slices of the unallocated loops, with 'mem_capacity' as an upper bound.
# @param mem_op
# @param mem_capacity Capacity of the memory node in bits.
def calc_size_slices(self, mem_op: str, mem_capacity: int):
# @param db_support Double buffering support of this node
def calc_size_slices(self, mem_op: str, mem_capacity: int, db_support: bool=False):

# Already allocated loops for this mem_op
allocated_loops = self.allocated[mem_op]
Expand All @@ -187,6 +189,11 @@ def calc_size_slices(self, mem_op: str, mem_capacity: int):
unallocated_loops = self.unallocated[mem_op]
sizes = []

# If this memory supports double buffering get the size it would take to allocate everything
if db_support:
all_loops=(allocated_loops+unallocated_loops[:len(unallocated_loops)+1])
all_loops_size=self.calc_loops_size(all_loops,mem_op,unallocated_loops)

for i in range(
len(unallocated_loops) + 1
): # Go through all slices (includes empty slice)
Expand All @@ -197,6 +204,10 @@ def calc_size_slices(self, mem_op: str, mem_capacity: int):
allocated_loops + unallocated_slice
) # Join them with already allocated loops
size = self.calc_loops_size(loops, mem_op, unallocated_loops)
# double size allocated if the node uses double buffering
if db_support:
if len(unallocated_loops[i:])>0 and size<all_loops_size:
size*=2
if size <= mem_capacity:
sizes.append(size)
else:
Expand Down

0 comments on commit fc08868

Please sign in to comment.