From 3ec3a58ba103ec169d42f52906b3b2cfc1ef93fa Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 9 Apr 2024 16:57:22 -0700 Subject: [PATCH 1/7] added graph for dense to sprse conversion --- compiler/sam-outputs/onyx-dot/mat_dn2sp.gv | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 compiler/sam-outputs/onyx-dot/mat_dn2sp.gv diff --git a/compiler/sam-outputs/onyx-dot/mat_dn2sp.gv b/compiler/sam-outputs/onyx-dot/mat_dn2sp.gv new file mode 100644 index 00000000..726b9187 --- /dev/null +++ b/compiler/sam-outputs/onyx-dot/mat_dn2sp.gv @@ -0,0 +1,20 @@ +digraph SAM { + comment="X=ss01,B=dd01" + 5 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=dense,src=true,root=true" label="FiberLookup i: B0\ndense" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="dense" src="true" root="true"] + 2 [comment="type=fiberwrite,index=i,tensor=X,mode=0,format=compressed,segsize=2,crdsize=B0_dim,sink=true" label="FiberWrite i: X0\ncompressed" color=green3 shape=box style=filled type="fiberwrite" index="i" tensor="X" mode="0" format="compressed" segsize="2" crdsize="B0_dim" sink="true"] + 4 [comment="type=fiberlookup,index=j,tensor=B,mode=1,format=dense,src=true,root=false" label="FiberLookup j: B1\ndense" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="B" mode="1" format="dense" src="true" root="false"] + 1 [comment="type=fiberwrite,index=j,tensor=X,mode=1,format=compressed,segsize=B0_dim+1,crdsize=B0_dim*B1_dim,sink=true" label="FiberWrite j: X1\ncompressed" color=green3 shape=box style=filled type="fiberwrite" index="j" tensor="X" mode="1" format="compressed" segsize="B0_dim+1" crdsize="B0_dim*B1_dim" sink="true"] + 3 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] + 0 [comment="type=fiberwrite,mode=vals,tensor=X,size=1*B0_dim*B1_dim,sink=true" label="FiberWrite Vals: X" color=green3 shape=box style=filled type="fiberwrite" tensor="X" mode="vals" size="1*B0_dim*B1_dim" sink="true"] + 6 [comment="type=crddrop,outer=j,inner=val,mode=0" label="CrdDrop Compression j, val" color=orange style=filled type="crddrop" outer="j" inner="val" mode="0"] + 7 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] + 5 -> 4 [label="ref" style=bold type="ref" comment=""] + 4 -> 3 [label="ref" style=bold type="ref" comment=""] + 3 -> 6 [label="val" type="val" comment="inner-val"] + 4 -> 6 [label="crd_outer-j" style=dashed type="crd" comment="outer-j"] + 6 -> 7 [label="crd_inner-j" style=dashed type="crd" comment="outer-j"] + 5 -> 7 [label="crd_outer-i" style=dashed type="crd" comment="outer_i"] + 6 -> 0 [label="val" type="val" comment="inner-val"] + 7 -> 1 [label="crd_innner-j" style=dashed type="crd" comment="inner-j"] + 7 -> 2 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] +} From 70d2a4bd68a35474149875f7bd17cd9a3130a101 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 9 Apr 2024 23:02:02 -0700 Subject: [PATCH 2/7] WIP: sp2dn conversion working, but need to investigate why flush is asserted when we use C as the dummy zero dense matrix --- compiler/sam-outputs/onyx-dot/mat_sp2dn.gv | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 compiler/sam-outputs/onyx-dot/mat_sp2dn.gv diff --git a/compiler/sam-outputs/onyx-dot/mat_sp2dn.gv b/compiler/sam-outputs/onyx-dot/mat_sp2dn.gv new file mode 100644 index 00000000..7ca86c10 --- /dev/null +++ b/compiler/sam-outputs/onyx-dot/mat_sp2dn.gv @@ -0,0 +1,32 @@ +digraph SAM { + comment="X=ss01,B=dd01,C=ss01" + 10 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=dense,src=true,root=true" label="FiberLookup i: B0\ndense" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="dense" src="true" root="true"] + 9 [comment="type=union,index=i" label="union i" color=purple shape=box style=filled type="union" index="i"] + 2 [comment="type=fiberwrite,index=i,tensor=X,mode=0,format=compressed,segsize=2,crdsize=B0_dim,sink=true" label="FiberWrite i: X0\ncompressed" color=green3 shape=box style=filled type="fiberwrite" index="i" tensor="X" mode="0" format="compressed" segsize="2" crdsize="B0_dim" sink="true"] + 7 [comment="type=fiberlookup,index=j,tensor=B,mode=1,format=dense,src=true,root=false" label="FiberLookup j: B1\ndense" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="B" mode="1" format="dense" src="true" root="false"] + 6 [comment="type=union,index=j" label="union j" color=purple shape=box style=filled type="union" index="j"] + 1 [comment="type=fiberwrite,index=j,tensor=X,mode=1,format=compressed,segsize=B0_dim+1,crdsize=B0_dim*B1_dim,sink=true" label="FiberWrite j: X1\ncompressed" color=green3 shape=box style=filled type="fiberwrite" index="j" tensor="X" mode="1" format="compressed" segsize="B0_dim+1" crdsize="B0_dim*B1_dim" sink="true"] + 4 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] + 3 [comment="type=add,sub=0" label="Add" color=brown shape=box style=filled type="add" sub="0"] + 0 [comment="type=fiberwrite,mode=vals,tensor=X,size=1*B0_dim*B1_dim,sink=true" label="FiberWrite Vals: X" color=green3 shape=box style=filled type="fiberwrite" tensor="X" mode="vals" size="1*B0_dim*B1_dim" sink="true"] + 5 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] + 8 [comment="type=fiberlookup,index=j,tensor=C,mode=1,format=compressed,src=true,root=false" label="FiberLookup j: C1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="C" mode="1" format="compressed" src="true" root="false"] + 11 [comment="type=fiberlookup,index=i,tensor=C,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="C" mode="0" format="compressed" src="true" root="true"] + 10 -> 9 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 9 -> 2 [label="crd" style=dashed type="crd"] + 9 -> 7 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 7 -> 6 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 6 -> 1 [label="crd" style=dashed type="crd"] + 6 -> 4 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 4 -> 3 [label="val" type="val"] + 3 -> 0 [label="val" type="val"] + 6 -> 5 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 5 -> 3 [label="val" type="val"] + 7 -> 6 [label="ref_in-B" style=bold type="ref" comment="in-B"] + 9 -> 8 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 8 -> 6 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 8 -> 6 [label="ref_in-C" style=bold type="ref" comment="in-C"] + 10 -> 9 [label="ref_in-B" style=bold type="ref" comment="in-B"] + 11 -> 9 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 11 -> 9 [label="ref_in-C" style=bold type="ref" comment="in-C"] +} From 86eb691fa708b84ebec93f319dd1dc86da5ab01e Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 16 Apr 2024 16:21:02 -0700 Subject: [PATCH 3/7] removed printing statement and commented code, also remove connection to GLB for dense scanners --- sam/onyx/parse_dot.py | 73 +++++++++---------------------------------- 1 file changed, 14 insertions(+), 59 deletions(-) diff --git a/sam/onyx/parse_dot.py b/sam/onyx/parse_dot.py index 76015ff3..9738e1b8 100644 --- a/sam/onyx/parse_dot.py +++ b/sam/onyx/parse_dot.py @@ -921,9 +921,6 @@ def rewrite_lookup(self): for node in nodes_to_proc: if 'fiberlookup' in node.get_comment(): - print("PRINTING NODES") - print(node.get_attributes()) - print(node.get_name()) # Rewrite this node to a read root = bool(node.get_root()) root = False @@ -934,50 +931,6 @@ def rewrite_lookup(self): og_label = attrs['label'] del attrs['label'] - dense_ = attrs['format'].strip('"') == 'dense' - print(f"IS DENSE: {dense_}") - - # if dense_: - - # rd_scan = pydot.Node(f"rd_scan_{self.get_next_seq()}", - # **attrs, label=f"{og_label}_rd_scan", hwnode=f"{HWNodeType.ReadScanner}", - # fa_color=self.fa_color) - - # self.fa_color += 1 - - # crd_out_edge = [edge for edge in self.graph.get_edges() if edge.get_source() == node.get_name() and - # "crd" in edge.get_label()][0] - # ref_out_edge = [edge for edge in self.graph.get_edges() if edge.get_source() == node.get_name() and - # "ref" in edge.get_label()][0] - # ref_in_edge = None - # if not root: - # # Then we have ref in edge... - # ref_in_edge = [edge for edge in self.graph.get_edges() - # if edge.get_destination() == node.get_name() and - # "ref" in edge.get_label()][0] - # # Now add the nodes and move the edges... - # self.graph.add_node(rd_scan) - - # # Now inject the read scanner to other nodes... - # rd_to_down_crd = pydot.Edge(src=rd_scan, dst=crd_out_edge.get_destination(), - # **crd_out_edge.get_attributes()) - # rd_to_down_ref = pydot.Edge(src=rd_scan, dst=ref_out_edge.get_destination(), - # **ref_out_edge.get_attributes()) - # self.graph.add_edge(rd_to_down_crd) - # self.graph.add_edge(rd_to_down_ref) - # if ref_in_edge is not None: - # up_to_ref = pydot.Edge(src=ref_in_edge.get_source(), dst=rd_scan, **ref_in_edge.get_attributes()) - # self.graph.add_edge(up_to_ref) - - # # Delte old stuff... - # ret = self.graph.del_node(node) - # ret = self.graph.del_edge(crd_out_edge.get_source(), crd_out_edge.get_destination()) - # self.graph.del_edge(ref_out_edge.get_source(), ref_out_edge.get_destination()) - # if ref_in_edge is not None: - # self.graph.del_edge(ref_in_edge.get_source(), ref_in_edge.get_destination()) - - # else: - rd_scan = pydot.Node(f"rd_scan_{self.get_next_seq()}", **attrs, label=f"{og_label}_rd_scan", hwnode=f"{HWNodeType.ReadScanner}", fa_color=self.fa_color) @@ -993,22 +946,24 @@ def rewrite_lookup(self): # Only instantiate the glb_write if it doesn't exist tensor = attrs['tensor'].strip('"') mode = attrs['mode'].strip('"') - print(mode) - if f'{tensor}_{mode}_fiberlookup' in self.shared_writes and \ - self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] is not None: - glb_write = self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] - else: - glb_write = pydot.Node(f"glb_write_{self.get_next_seq()}", - **attrs, label=f"{og_label}_glb_write", hwnode=f"{HWNodeType.GLB}") - self.graph.add_node(glb_write) - if f'{tensor}_{mode}_fiberlookup' in self.shared_writes: - self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] = glb_write + is_dense = attrs['format'].strip('"') == 'dense' + + # dense scanner is basically a counter that counts up to the dimension size + # and does not rely on the GLB tile to supply any data + if not is_dense: + if f'{tensor}_{mode}_fiberlookup' in self.shared_writes and \ + self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] is not None: + glb_write = self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] + else: + glb_write = pydot.Node(f"glb_write_{self.get_next_seq()}", + **attrs, label=f"{og_label}_glb_write", hwnode=f"{HWNodeType.GLB}") + self.graph.add_node(glb_write) + if f'{tensor}_{mode}_fiberlookup' in self.shared_writes: + self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] = glb_write if self.local_mems is False: memory = pydot.Node(f"memory_{self.get_next_seq()}", **attrs, label=f"{og_label}_SRAM", hwnode=f"{HWNodeType.Memory}") - # Entertain multiple edges - # Now add the nodes and move the edges... self.graph.add_node(rd_scan) self.graph.add_node(wr_scan) From e5abf90ad0c2da97709c338bd0e172e28549030c Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 16 Apr 2024 16:26:32 -0700 Subject: [PATCH 4/7] fix code style --- sam/onyx/parse_dot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sam/onyx/parse_dot.py b/sam/onyx/parse_dot.py index 9738e1b8..c2a5d2b3 100644 --- a/sam/onyx/parse_dot.py +++ b/sam/onyx/parse_dot.py @@ -946,7 +946,7 @@ def rewrite_lookup(self): # Only instantiate the glb_write if it doesn't exist tensor = attrs['tensor'].strip('"') mode = attrs['mode'].strip('"') - is_dense = attrs['format'].strip('"') == 'dense' + is_dense = attrs['format'].strip('"') == 'dense' # dense scanner is basically a counter that counts up to the dimension size # and does not rely on the GLB tile to supply any data @@ -956,7 +956,7 @@ def rewrite_lookup(self): glb_write = self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] else: glb_write = pydot.Node(f"glb_write_{self.get_next_seq()}", - **attrs, label=f"{og_label}_glb_write", hwnode=f"{HWNodeType.GLB}") + **attrs, label=f"{og_label}_glb_write", hwnode=f"{HWNodeType.GLB}") self.graph.add_node(glb_write) if f'{tensor}_{mode}_fiberlookup' in self.shared_writes: self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] = glb_write From ddfc4af193171b58bd632f34be4f3effa3907f3c Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 16 Apr 2024 16:29:32 -0700 Subject: [PATCH 5/7] fix code style --- sam/onyx/parse_dot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sam/onyx/parse_dot.py b/sam/onyx/parse_dot.py index c2a5d2b3..c5966259 100644 --- a/sam/onyx/parse_dot.py +++ b/sam/onyx/parse_dot.py @@ -956,7 +956,7 @@ def rewrite_lookup(self): glb_write = self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] else: glb_write = pydot.Node(f"glb_write_{self.get_next_seq()}", - **attrs, label=f"{og_label}_glb_write", hwnode=f"{HWNodeType.GLB}") + **attrs, label=f"{og_label}_glb_write", hwnode=f"{HWNodeType.GLB}") self.graph.add_node(glb_write) if f'{tensor}_{mode}_fiberlookup' in self.shared_writes: self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] = glb_write From 274cbbc0d5d8a9f908abeedb42d0b8b1114d41cd Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Mon, 29 Apr 2024 13:33:03 -0700 Subject: [PATCH 6/7] remove connection from dense scanner to glb --- sam/onyx/parse_dot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sam/onyx/parse_dot.py b/sam/onyx/parse_dot.py index c5966259..69e469e2 100644 --- a/sam/onyx/parse_dot.py +++ b/sam/onyx/parse_dot.py @@ -950,6 +950,7 @@ def rewrite_lookup(self): # dense scanner is basically a counter that counts up to the dimension size # and does not rely on the GLB tile to supply any data + glb_write = None if not is_dense: if f'{tensor}_{mode}_fiberlookup' in self.shared_writes and \ self.shared_writes[f'{tensor}_{mode}_fiberlookup'][1] is not None: @@ -972,9 +973,11 @@ def rewrite_lookup(self): if self.local_mems is False: self.graph.add_node(memory) # Glb to WR - glb_to_wr = pydot.Edge(src=glb_write, dst=wr_scan, label=f"glb_to_wr_{self.get_next_seq()}", - style="bold") - self.graph.add_edge(glb_to_wr) + # Dense scanner doesn't need data from the GLB, hence no connection to the GLB + if not is_dense: + glb_to_wr = pydot.Edge(src=glb_write, dst=wr_scan, label=f"glb_to_wr_{self.get_next_seq()}", + style="bold") + self.graph.add_edge(glb_to_wr) # write + read to buffet wr_to_buff = pydot.Edge(src=wr_scan, dst=buffet, label=f'wr_to_buff_{self.get_next_seq()}') self.graph.add_edge(wr_to_buff) From a8c09c6eb16f3998f7d5d57e66a1eb355b62aad5 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Mon, 29 Apr 2024 13:41:17 -0700 Subject: [PATCH 7/7] fixed code style --- sam/onyx/parse_dot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sam/onyx/parse_dot.py b/sam/onyx/parse_dot.py index 8e52328c..6b8d7054 100644 --- a/sam/onyx/parse_dot.py +++ b/sam/onyx/parse_dot.py @@ -977,7 +977,7 @@ def rewrite_lookup(self): # Dense scanner doesn't need data from the GLB, hence no connection to the GLB if not is_dense: glb_to_wr = pydot.Edge(src=glb_write, dst=wr_scan, label=f"glb_to_wr_{self.get_next_seq()}", - style="bold") + style="bold") self.graph.add_edge(glb_to_wr) # write + read to buffet wr_to_buff = pydot.Edge(src=wr_scan, dst=buffet, label=f'wr_to_buff_{self.get_next_seq()}')