Skip to content

Commit

Permalink
fix code styling; fix imc pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
JiacongSun committed Dec 2, 2024
1 parent 0e16010 commit 336bc20
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion zigzag/cacti/cacti_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def create_item(
str(technology),
],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT
stderr=subprocess.STDOUT,
)

if p != 0:
Expand Down
15 changes: 9 additions & 6 deletions zigzag/hardware/architecture/get_cacti_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,18 @@ def get_w_cost_per_weight_from_cacti(


if __name__ == "__main__":
mem_size_list = [32*32*8//8]
bw = 32*8
mem_size_list = [32 * 32 * 8 // 8]
bw = 32 * 8
for mem_size in mem_size_list:
access_time, area, r_cost, w_cost = get_cacti_cost(cacti_path=f"../../cacti/cacti_master", tech_node=0.028, mem_type="sram",
mem_size_in_byte=mem_size, bw=bw)
access_time, area, r_cost, w_cost = get_cacti_cost(
cacti_path="../../cacti/cacti_master", tech_node=0.028, mem_type="sram", mem_size_in_byte=mem_size, bw=bw
)
r_cost_per_bit = round(r_cost / bw, 2)
if mem_size < 1024:
print(f"mem size: {mem_size}[B], r_cost_per_bit: {r_cost_per_bit}[pJ/bit], area: {area} [mm2]")
elif mem_size < 1024*1024:
elif mem_size < 1024 * 1024:
print(f"mem size: {mem_size//1024}[KB], r_cost_per_bit: {r_cost_per_bit}[pJ/bit], area: {area} [mm2]")
else:
print(f"mem size: {mem_size // 1024 // 1024}[MB], r_cost_per_bit: {r_cost_per_bit}[pJ/bit], area: {area} [mm2]")
print(
f"mem size: {mem_size // 1024 // 1024}[MB], r_cost_per_bit: {r_cost_per_bit}[pJ/bit], area: {area} [mm2]"
)
16 changes: 7 additions & 9 deletions zigzag/hardware/architecture/memory_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(
shared_memory_group_id: int = -1,
is_imc: bool = False,
cacti_size_scaling: float = 1,
cacti_bw_scaling: float = 1
cacti_bw_scaling: float = 1,
):
"""
Collect all the basic information of a physical memory module.
Expand Down Expand Up @@ -104,6 +104,9 @@ def __init__(
rw_port=rw_port,
bank=1,
)
self.w_cost = w_cost / cacti_bw_scaling
self.r_cost = 0 # cost has been included in the imc operational array
self.area = 0 # cost has been included in the imc operational array
else:
r_cost, w_cost, area = cacti_parser.get_item(
mem_name=name,
Expand All @@ -120,14 +123,9 @@ def __init__(
self.size = size
self.r_bw = r_bw
self.w_bw = w_bw
if is_imc and (cacti_size_scaling != 1 or cacti_bw_scaling != 1):
self.w_cost = w_cost / cacti_bw_scaling
self.r_cost = 0 # cost has been included in the imc operational array
self.area = 0 # cost has been included in the imc operational array
else:
self.r_cost = r_cost
self.w_cost = w_cost
self.area = area
self.r_cost = r_cost
self.w_cost = w_cost
self.area = area
self.r_port_nb = r_port
self.w_port_nb = w_port
self.rw_port_nb = rw_port
Expand Down
21 changes: 16 additions & 5 deletions zigzag/parser/accelerator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ def create(self, core_id: int = 0, shared_mem_group_id: int | None = None) -> Ac
cacti_bw_scaling = 1
cacti_size_scaling = 1
memory_factory = MemoryFactory(
mem_name, self.data["memories"][mem_name], shared_mem_group_id=shared_mem_group_id,
is_imc=is_imc, cacti_size_scaling=cacti_size_scaling, cacti_bw_scaling=cacti_bw_scaling
mem_name,
self.data["memories"][mem_name],
shared_mem_group_id=shared_mem_group_id,
is_imc=is_imc,
cacti_size_scaling=cacti_size_scaling,
cacti_bw_scaling=cacti_bw_scaling
)
memory_factory.add_memory_to_graph(mem_graph)

Expand Down Expand Up @@ -154,8 +158,15 @@ def __create_dataflow_single_oa_dim(self, mapping_data: list[str]) -> MappingSin
class MemoryFactory:
"""! Create MemoryInstances and adds them to memory hierarchy."""

def __init__(self, name: str, mem_data: dict[str, Any], shared_mem_group_id: int = -1, is_imc: bool = False,
cacti_size_scaling: float = 1, cacti_bw_scaling: float = 1):
def __init__(
self,
name: str,
mem_data: dict[str, Any],
shared_mem_group_id: int = -1,
is_imc: bool = False,
cacti_size_scaling: float = 1,
cacti_bw_scaling: float = 1,
):
self.data = mem_data
self.name = name
self.shared_mem_group_id = shared_mem_group_id
Expand Down Expand Up @@ -183,7 +194,7 @@ def create_memory_instance(self) -> MemoryInstance:
shared_memory_group_id=self.shared_mem_group_id,
is_imc=self.is_imc,
cacti_size_scaling=self.cacti_size_scaling,
cacti_bw_scaling=self.cacti_bw_scaling
cacti_bw_scaling=self.cacti_bw_scaling,
)

def add_memory_to_graph(self, mem_graph: MemoryHierarchy) -> None:
Expand Down

0 comments on commit 336bc20

Please sign in to comment.