Skip to content

Commit

Permalink
update netlist for PE, add glb dump override
Browse files Browse the repository at this point in the history
  • Loading branch information
mbstrange2 committed Aug 16, 2022
1 parent 4101150 commit 6524b3e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
66 changes: 52 additions & 14 deletions sam/onyx/generate_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ def _create_matrix(self):
def _create_fiber_tree(self):
self.fiber_tree = FiberTree(tensor=self.array)

def dump_outputs(self, format=None, tpose=False, dump_shape=True):
def dump_outputs(self, format=None, tpose=False, dump_shape=True, glb_override=False, glb_dump_dir=None):
'''
Dump the matrix into many files depending on matrix format
'''
print(f"Using dump directory - {self.dump_dir}")

use_dir = self.dump_dir
print_hex = False
if glb_override:
use_dir = glb_dump_dir
print_hex = True

print(f"Using dump directory - {use_dir}")

# Transpose it first if necessary
if tpose is True:
Expand All @@ -79,8 +86,12 @@ def dump_outputs(self, format=None, tpose=False, dump_shape=True):
tmp_lvl_list.append(self.fiber_tree.get_root())

seg_arr, coord_arr = self._dump_csf(tmp_lvl_list)
self.write_array(seg_arr, name=f"tensor_{self.name}_mode_0_seg")
self.write_array(coord_arr, name=f"tensor_{self.name}_mode_0_crd")
if glb_override:
lines = [len(seg_arr), *seg_arr, len(coord_arr), *coord_arr]
self.write_array(lines, name=f"tensor_{self.name}_mode_0", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(seg_arr, name=f"tensor_{self.name}_mode_0_seg", dump_dir=use_dir, hex=print_hex)
self.write_array(coord_arr, name=f"tensor_{self.name}_mode_0_crd", dump_dir=use_dir, hex=print_hex)

at_vals = False
i = 1
Expand All @@ -99,17 +110,30 @@ def dump_outputs(self, format=None, tpose=False, dump_shape=True):
tmp_lvl_list = next_tmp_lvl_list
if at_vals:
# If at vals, we don't need to dump csf, we have the level
self.write_array(tmp_lvl_list, name=f"tensor_{self.name}_mode_vals")
if glb_override:
lines = [len(tmp_lvl_list), *tmp_lvl_list]
# self.write_array(tmp_lvl_list, name=f"tensor_{self.name}_mode_vals" dump_dir=use_dir)
self.write_array(lines, name=f"tensor_{self.name}_mode_vals", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(tmp_lvl_list, name=f"tensor_{self.name}_mode_vals", dump_dir=use_dir, hex=print_hex)
else:
seg_arr, coord_arr = self._dump_csf(tmp_lvl_list)
self.write_array(seg_arr, name=f"tensor_{self.name}_mode_{i}_seg")
self.write_array(coord_arr, name=f"tensor_{self.name}_mode_{i}_crd")
if glb_override:
lines = [len(seg_arr), *seg_arr, len(coord_arr), *coord_arr]
self.write_array(lines, name=f"tensor_{self.name}_mode_{i}", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(seg_arr, name=f"tensor_{self.name}_mode_{i}_seg", dump_dir=use_dir, hex=print_hex)
self.write_array(coord_arr, name=f"tensor_{self.name}_mode_{i}_crd", dump_dir=use_dir, hex=print_hex)
i = i + 1
elif self.format == "UNC":
flat_array = []
for val in numpy.nditer(self.array):
flat_array.append(val)
self.write_array(flat_array, name=f"tensor_{self.name}_mode_vals")
if glb_override:
lines = [len(flat_array), *flat_array]
self.write_array(lines, name=f"tensor_{self.name}_mode_vals", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(flat_array, name=f"tensor_{self.name}_mode_vals", dump_dir=use_dir, hex=print_hex)
elif self.format == "COO":
crd_dict = dict()
order = len(self.array.shape)
Expand All @@ -124,12 +148,20 @@ def dump_outputs(self, format=None, tpose=False, dump_shape=True):
is_not_finished = it.iternext()
for key in crd_dict:
if key == order:
self.write_array(crd_dict[key], name=f"tensor_{self.name}_mode_vals")
if glb_override:
lines = [len(crd_dict[key]), *crd_dict[key]]
self.write_array(lines, name=f"tensor_{self.name}_mode_vals", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(crd_dict[key], name=f"tensor_{self.name}_mode_vals", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(crd_dict[key], name=f"tensor_{self.name}_mode_{key}_crd")
if glb_override:
lines = [len(crd_dict[key]), *crd_dict[key]]
self.write_array(lines, name=f"tensor_{self.name}_mode_{key}_crd", dump_dir=use_dir, hex=print_hex)
else:
self.write_array(crd_dict[key], name=f"tensor_{self.name}_mode_{key}_crd", dump_dir=use_dir, hex=print_hex)

if dump_shape:
self.write_array(self.array.shape, name=f"shape")
self.write_array(self.array.shape, name=f"shape", dump_dir=use_dir, hex=print_hex)

# Transpose it back
if tpose is True:
Expand Down Expand Up @@ -158,17 +190,23 @@ def _dump_csf(self, level_list):

return seg_arr, coord_arr

def write_array(self, str_list, name):
def write_array(self, str_list, name, dump_dir=None, hex=False):
"""Write an array/list to a file
Args:
list (list): array/list of values
name (str): name of file
"""
full_path = self.dump_dir + "/" + name
if dump_dir is None:
dump_dir = self.dump_dir

full_path = dump_dir + "/" + name
with open(full_path, "w+") as wr_file:
for item in str_list:
wr_file.write(f"{item}\n")
if hex:
wr_file.write(f"{item:04X}\n")
else:
wr_file.write(f"{item}\n")

def get_matrix(self):
return self.array
Expand Down
11 changes: 6 additions & 5 deletions sam/onyx/hw_nodes/compute_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def connect(self, other, edge):
new_conns = {
'pe_to_rd_scan': [
# send output to rd scanner
([(pe, "data_out"), (rd_scan, "us_pos_in")], 17),
([(pe, "res"), (rd_scan, "us_pos_in")], 17),
# ([(pe, "eos_out"), (rd_scan, "us_eos_in")], 1),
# ([(rd_scan, "us_ready_out"), (pe, "ready_in")], 1),
# ([(pe, "valid_out"), (rd_scan, "us_valid_in")], 1),
Expand All @@ -52,7 +52,7 @@ def connect(self, other, edge):
new_conns = {
'pe_to_wr_scan': [
# send output to rd scanner
([(pe, "data_out"), (wr_scan, "data_in")], 17),
([(pe, "res"), (wr_scan, "data_in")], 17),
# ([(pe, "eos_out"), (wr_scan, "eos_in_0")], 1),
# ([(wr_scan, "ready_out_0"), (pe, "ready_in")], 1),
# ([(pe, "valid_out"), (wr_scan, "valid_in_0")], 1),
Expand All @@ -74,7 +74,7 @@ def connect(self, other, edge):
new_conns = {
f'pe_to_isect_{in_str}_{isect_conn}': [
# send output to rd scanner
([(pe, "data_out"), (isect, f"{in_str}_{isect_conn}")], 17),
([(pe, "res"), (isect, f"{in_str}_{isect_conn}")], 17),
# ([(pe, "eos_out"), (isect, f"eos_in_{isect_conn * 2 + offset}")], 1),
# ([(isect, f"ready_out_{isect_conn * 2 + offset}"), (pe, "ready_in")], 1),
# ([(pe, "valid_out"), (isect, f"valid_in_{isect_conn * 2 + offset}")], 1),
Expand All @@ -88,7 +88,7 @@ def connect(self, other, edge):
new_conns = {
f'pe_to_reduce': [
# send output to rd scanner
([(pe, "data_out"), (other_red, f"data_in")], 17),
([(pe, "res"), (other_red, f"data_in")], 17),
# ([(pe, "eos_out"), (other_red, f"eos_in")], 1),
# ([(other_red, f"ready_out"), (pe, "ready_in")], 1),
# ([(pe, "valid_out"), (other_red, f"valid_in")], 1),
Expand All @@ -111,7 +111,8 @@ def connect(self, other, edge):
new_conns = {
f'pe_to_pe_{other_conn}': [
# send output to rd scanner
([(pe, "data_out"), (other_pe, f"data_in_{other_conn}")], 17),
# ([(pe, "res"), (other_pe, f"data_in_{other_conn}")], 17),
([(pe, "res"), (other_pe, f"data{other_conn}")], 17),
# ([(pe, "eos_out"), (other_pe, f"eos_in_{other_conn}")], 1),
# ([(other_pe, f"ready_out_{other_conn}"), (pe, "ready_in")], 1),
# ([(pe, "valid_out"), (other_pe, f"valid_in_{other_conn}")], 1),
Expand Down
3 changes: 2 additions & 1 deletion sam/onyx/hw_nodes/read_scanner_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def connect(self, other, edge):
new_conns = {
f'rd_scan_to_compute_{compute_conn}': [
# send output to rd scanner
([(rd_scan, "coord_out"), (compute, f"data_in_{compute_conn}")], 17),
# ([(rd_scan, "coord_out"), (compute, f"data_in_{compute_conn}")], 17),
([(rd_scan, "coord_out"), (compute, f"data{compute_conn}")], 17),
]
}
# Now update the PE/compute to use the next connection next time
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pycodestyle]
max-line-length = 127
ignore = E741,W504,E266,E211,E722,W602
ignore = E741,W504,E266,E722,W602

0 comments on commit 6524b3e

Please sign in to comment.