From 56744d993da7a80a827a35401d7ed441440c20d6 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Sun, 21 Jan 2024 13:00:38 -0800 Subject: [PATCH] update mapped input port storing logic, compute to compute connetion logic, and dedicated reduce primitive mapping logic --- sam/onyx/hw_nodes/compute_node.py | 9 +++++---- sam/onyx/hw_nodes/read_scanner_node.py | 2 +- sam/onyx/hw_nodes/reduce_node.py | 9 ++++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sam/onyx/hw_nodes/compute_node.py b/sam/onyx/hw_nodes/compute_node.py index 30a39afc..de147365 100644 --- a/sam/onyx/hw_nodes/compute_node.py +++ b/sam/onyx/hw_nodes/compute_node.py @@ -139,6 +139,8 @@ def connect(self, other, edge, kwargs=None): other_conn = 1 else: assert 0 & "edge connected to faddiexp has to have comment specified to either 'exp' or 'fp'" + else: + other_conn = other.mapped_input_ports[other_conn] new_conns = { f'pe_to_pe_{other_conn}': [ ([(pe, "res"), (other_pe, f"data{other_conn}")], 17), @@ -183,7 +185,7 @@ def parse_mapped_json(self, filename, node_id): # if the connection is to the data port of alu if "self.in" in src: # get the port name of the alu - self.mapped_input_ports.append(dest.split(".")[1]) + self.mapped_input_ports.append(dest.split(".")[1].strip("data")) self.opcode = int(opcode, 0) def configure(self, attributes): @@ -201,9 +203,8 @@ def configure(self, attributes): pe_in_external = 1 # according to the mapped input ports generate input port config num_sparse_inputs = list("000") - for i in range(3): - if f"data{2 - i}" in self.mapped_input_ports: - num_sparse_inputs[i] = '1' + for port in self.mapped_input_ports: + num_sparse_inputs[2 - int(port)] = '1' print("".join(num_sparse_inputs)) num_sparse_inputs = int("".join(num_sparse_inputs), 2) diff --git a/sam/onyx/hw_nodes/read_scanner_node.py b/sam/onyx/hw_nodes/read_scanner_node.py index 1dfd762a..2d210fb6 100644 --- a/sam/onyx/hw_nodes/read_scanner_node.py +++ b/sam/onyx/hw_nodes/read_scanner_node.py @@ -215,7 +215,7 @@ def connect(self, other, edge, kwargs=None): assert 0 & "edge connected to faddiexp has to have comment specified to either 'exp' or 'fp'" new_conns = { f'rd_scan_to_compute_{compute_conn}': [ - ([(rd_scan, "coord_out"), (compute, other.mapped_input_ports[compute_conn])], 17), + ([(rd_scan, "coord_out"), (compute, f"data{other.mapped_input_ports[compute_conn]}")], 17), ] } # Now update the PE/compute to use the next connection next time diff --git a/sam/onyx/hw_nodes/reduce_node.py b/sam/onyx/hw_nodes/reduce_node.py index b19cf5e2..4a43a9ec 100644 --- a/sam/onyx/hw_nodes/reduce_node.py +++ b/sam/onyx/hw_nodes/reduce_node.py @@ -1,4 +1,8 @@ from sam.onyx.hw_nodes.hw_node import * +from peak.assembler import Assembler +from hwtypes.modifiers import strip_modifiers +from lassen.sim import PE_fc as lassen_fc +import lassen.asm as asm class ReduceNode(HWNode): @@ -112,7 +116,10 @@ def configure(self, attributes): # data I/O to and from the PE should be internal with the reduce pe_in_external = 0 # op is set to integer add for the PE TODO: make this configurable in the sam graph - op = 0 + # TODO: make this use the metamapper + instr_type = strip_modifiers(lassen_fc.Py.input_t.field_dict['inst']) + asm_ = Assembler(instr_type) + op = int(asm_.assemble(asm.add())) cfg_kwargs = { 'stop_lvl': stop_lvl, 'pe_connected_to_reduce': pe_connected_to_reduce,