From ac0261ab7a7c63f7df18462d3a359e8a78d7fd65 Mon Sep 17 00:00:00 2001 From: Bo-Wun Cheng Date: Fri, 13 Oct 2023 11:06:39 -0700 Subject: [PATCH 1/9] updated new graphs for opal and mapping code to cope with the addtion of compression mode in crddrop --- .../opal-dot/matmul_ijk_crddrop_relu.gv | 60 +++++++++++++++++++ .../matmul_ijk_crddrop_relu_no_valdrop.gv | 54 +++++++++++++++++ sam/onyx/hw_nodes/merge_node.py | 6 +- 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv create mode 100644 compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv diff --git a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv new file mode 100644 index 00000000..73d523cc --- /dev/null +++ b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv @@ -0,0 +1,60 @@ +digraph SAM { + comment="X=ss01,B=ss01,C=ss10" + 17 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"] + 16 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 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"] + 15 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"] + 14 [comment="type=repeat,index=i,tensor=C,root=true" label="Repeat i: C" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="C" root="true"] + 13 [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"] + 12 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 1 [comment="type=fiberwrite,index=j,tensor=X,mode=1,format=compressed,segsize=B0_dim+1,crdsize=B0_dim*C1_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*C1_dim" sink="true"] + 11 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"] + 10 [comment="type=repeat,index=j,tensor=B,root=false" label="Repeat j: B" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="B" root="false"] + 8 [comment="type=fiberlookup,index=k,tensor=B,mode=1,format=compressed,src=true,root=false" label="FiberLookup k: B1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="B" mode="1" format="compressed" src="true" root="false"] + 7 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"] + 5 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] + 4 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 0 [comment="type=fiberwrite,mode=vals,tensor=X,size=1*B0_dim*C1_dim,sink=true" label="FiberWrite Vals: X" color=green3 shape=box style=filled type="fiberwrite" tensor="X" mode="vals" size="1*B0_dim*C1_dim" sink="true"] + 6 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] + 9 [comment="type=fiberlookup,index=k,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="0" format="compressed" src="true" root="false"] + 18 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] + 19 [comment="type=crddrop,outer=j,inner=k" label="CrdDrop j,k" color=orange shape=box style=filled type="crddrop" outer="j" inner="k"] + 20 [comment="type=max" label="Max 0" color=orange shape=box style=filled type="max"] + 21 [comment="type=valdrop,outer=j,inner=val" label="ValDropper j,val" color=purple shape=box style=filled type="valdrop" outer="j" inner="val"] + 22 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] + 17 -> 16 [label="crd" style=dashed type="crd" comment=""] + 16 -> 15 [label="crd" style=dashed type="crd"] + 15 -> 14 [label="repsig" style=dotted type="repsig"] + 14 -> 13 [label="ref" style=bold type="ref"] + 13 -> 12 [label="crd" style=dashed type="crd" comment=""] + 12 -> 11 [label="crd" style=dashed type="crd"] + 11 -> 10 [label="repsig" style=dotted type="repsig"] + 10 -> 8 [label="ref" style=bold type="ref"] + 8 -> 7 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 7 -> 5 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 5 -> 4 [label="val" type="val"] + 7 -> 6 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 6 -> 4 [label="val" type="val"] + 8 -> 7 [label="ref_in-B" style=bold type="ref" comment="in-B"] + 13 -> 9 [label="ref" style=bold type="ref" comment=""] + 9 -> 7 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 9 -> 7 [label="ref_in-C" style=bold type="ref" comment="in-C"] + 17 -> 10 [label="ref" style=bold type="ref" comment=""] + + 4 -> 19 [label="val_inner-k" type="val" comment="inner-k"] + 12 -> 19 [label="crd_outer-j" style=dashed type="crd" comment="outer-j"] + 19 -> 3 [label="val_inner-k" type="val" comment="inner-k"] + 3 -> 20 [label="val" type="val" comment="val"] + 20 -> 21 [label="val" type="val" comment="relu-val"] + 18 -> 21 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] + 21 -> 22 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] + 18 -> 22 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] + + 19 -> 18 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] + 16 -> 18 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] + 21 -> 0 [label="val" type="val"] + + 22 -> 2 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] + 22 -> 1 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] +} diff --git a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv new file mode 100644 index 00000000..79740d0a --- /dev/null +++ b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv @@ -0,0 +1,54 @@ +digraph SAM { + comment="X=ss01,B=ss01,C=ss10" + 17 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"] + 16 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 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"] + 15 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"] + 14 [comment="type=repeat,index=i,tensor=C,root=true" label="Repeat i: C" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="C" root="true"] + 13 [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"] + 12 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 1 [comment="type=fiberwrite,index=j,tensor=X,mode=1,format=compressed,segsize=B0_dim+1,crdsize=B0_dim*C1_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*C1_dim" sink="true"] + 11 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"] + 10 [comment="type=repeat,index=j,tensor=B,root=false" label="Repeat j: B" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="B" root="false"] + 8 [comment="type=fiberlookup,index=k,tensor=B,mode=1,format=compressed,src=true,root=false" label="FiberLookup k: B1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="B" mode="1" format="compressed" src="true" root="false"] + 7 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"] + 5 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] + 4 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 0 [comment="type=fiberwrite,mode=vals,tensor=X,size=1*B0_dim*C1_dim,sink=true" label="FiberWrite Vals: X" color=green3 shape=box style=filled type="fiberwrite" tensor="X" mode="vals" size="1*B0_dim*C1_dim" sink="true"] + 6 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] + 9 [comment="type=fiberlookup,index=k,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="0" format="compressed" src="true" root="false"] + 18 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] + 19 [comment="type=crddrop,outer=j,inner=k" label="CrdDrop j,k" color=orange shape=box style=filled type="crddrop" outer="j" inner="k"] + 20 [comment="type=max" label="Max 0" color=orange shape=box style=filled type="max"] + 17 -> 16 [label="crd" style=dashed type="crd" comment=""] + 16 -> 15 [label="crd" style=dashed type="crd"] + 15 -> 14 [label="repsig" style=dotted type="repsig"] + 14 -> 13 [label="ref" style=bold type="ref"] + 13 -> 12 [label="crd" style=dashed type="crd" comment=""] + 12 -> 11 [label="crd" style=dashed type="crd"] + 11 -> 10 [label="repsig" style=dotted type="repsig"] + 10 -> 8 [label="ref" style=bold type="ref"] + 8 -> 7 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 7 -> 5 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 5 -> 4 [label="val" type="val"] + 7 -> 6 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 6 -> 4 [label="val" type="val"] + 8 -> 7 [label="ref_in-B" style=bold type="ref" comment="in-B"] + 13 -> 9 [label="ref" style=bold type="ref" comment=""] + 9 -> 7 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 9 -> 7 [label="ref_in-C" style=bold type="ref" comment="in-C"] + 17 -> 10 [label="ref" style=bold type="ref" comment=""] + + 4 -> 19 [label="val_inner-k" type="val" comment="inner-k"] + 12 -> 19 [label="crd_outer-j" style=dashed type="crd" comment="outer-j"] + 19 -> 3 [label="val_inner-k" type="val" comment="inner-k"] + 3 -> 20 [label="val" type="val" comment="val"] + + 19 -> 18 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] + 16 -> 18 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] + 20 -> 0 [label="val" type="val"] + + 18 -> 2 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] + 18 -> 1 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] +} diff --git a/sam/onyx/hw_nodes/merge_node.py b/sam/onyx/hw_nodes/merge_node.py index dd6339c6..a1ca8d36 100644 --- a/sam/onyx/hw_nodes/merge_node.py +++ b/sam/onyx/hw_nodes/merge_node.py @@ -127,9 +127,11 @@ def configure(self, attributes): # TODO what is this supposed to be? cmrg_stop_lvl = 1 op = 0 + cmrg_mode = 1 # forced to 1 to peform crddrop instead of compression cfg_kwargs = { 'cmrg_enable': cmrg_enable, 'cmrg_stop_lvl': cmrg_stop_lvl, - 'op': op + 'op': op, + 'cmrg_mode': cmrg_mode } - return (cmrg_enable, cmrg_stop_lvl, op), cfg_kwargs + return (cmrg_enable, cmrg_stop_lvl, op, cmrg_mode), cfg_kwargs From 065785496e25b241c83baa03a04775c3db95099a Mon Sep 17 00:00:00 2001 From: Bo-Wun Cheng Date: Fri, 13 Oct 2023 11:15:18 -0700 Subject: [PATCH 2/9] updated the color of max in the graph --- compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv | 2 +- .../sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv index 73d523cc..4d6ba559 100644 --- a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv +++ b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv @@ -20,7 +20,7 @@ digraph SAM { 9 [comment="type=fiberlookup,index=k,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="0" format="compressed" src="true" root="false"] 18 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] 19 [comment="type=crddrop,outer=j,inner=k" label="CrdDrop j,k" color=orange shape=box style=filled type="crddrop" outer="j" inner="k"] - 20 [comment="type=max" label="Max 0" color=orange shape=box style=filled type="max"] + 20 [comment="type=max" label="Max 0" color=brown shape=box style=filled type="max"] 21 [comment="type=valdrop,outer=j,inner=val" label="ValDropper j,val" color=purple shape=box style=filled type="valdrop" outer="j" inner="val"] 22 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] 17 -> 16 [label="crd" style=dashed type="crd" comment=""] diff --git a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv index 79740d0a..d4a2c34a 100644 --- a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv +++ b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv @@ -20,7 +20,7 @@ digraph SAM { 9 [comment="type=fiberlookup,index=k,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="0" format="compressed" src="true" root="false"] 18 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] 19 [comment="type=crddrop,outer=j,inner=k" label="CrdDrop j,k" color=orange shape=box style=filled type="crddrop" outer="j" inner="k"] - 20 [comment="type=max" label="Max 0" color=orange shape=box style=filled type="max"] + 20 [comment="type=max" label="Max 0" color=brown shape=box style=filled type="max"] 17 -> 16 [label="crd" style=dashed type="crd" comment=""] 16 -> 15 [label="crd" style=dashed type="crd"] 15 -> 14 [label="repsig" style=dotted type="repsig"] From e4e64a060f4513d507a920112eae1cc72ac95a93 Mon Sep 17 00:00:00 2001 From: Bo-Wun Cheng Date: Fri, 13 Oct 2023 13:28:24 -0700 Subject: [PATCH 3/9] updated sam graph mapping code to take the new cmrg_mode signal into account --- sam/onyx/hw_nodes/merge_node.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sam/onyx/hw_nodes/merge_node.py b/sam/onyx/hw_nodes/merge_node.py index a1ca8d36..f759b235 100644 --- a/sam/onyx/hw_nodes/merge_node.py +++ b/sam/onyx/hw_nodes/merge_node.py @@ -3,10 +3,11 @@ class MergeNode(HWNode): - def __init__(self, name=None, outer=None, inner=None) -> None: + def __init__(self, name=None, outer=None, inner=None, mode=False) -> None: super().__init__(name=name) self.outer = outer self.inner = inner + self.mode = mode def get_outer(self): return self.outer @@ -127,7 +128,8 @@ def configure(self, attributes): # TODO what is this supposed to be? cmrg_stop_lvl = 1 op = 0 - cmrg_mode = 1 # forced to 1 to peform crddrop instead of compression + # 0 for compression, 1 for crddrop + cmrg_mode = self.mode cfg_kwargs = { 'cmrg_enable': cmrg_enable, 'cmrg_stop_lvl': cmrg_stop_lvl, From 3e78adcaa7b965f74509e9a6772132d3af3edb2f Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Sun, 15 Oct 2023 23:02:03 -0700 Subject: [PATCH 4/9] update data type of the default mode value --- sam/onyx/hw_nodes/merge_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sam/onyx/hw_nodes/merge_node.py b/sam/onyx/hw_nodes/merge_node.py index f759b235..bf0ee8b4 100644 --- a/sam/onyx/hw_nodes/merge_node.py +++ b/sam/onyx/hw_nodes/merge_node.py @@ -3,7 +3,7 @@ class MergeNode(HWNode): - def __init__(self, name=None, outer=None, inner=None, mode=False) -> None: + def __init__(self, name=None, outer=None, inner=None, mode=None) -> None: super().__init__(name=name) self.outer = outer self.inner = inner From 85401559698102ff79cda1faa364af2edfc9cc55 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Mon, 16 Oct 2023 23:47:24 -0700 Subject: [PATCH 5/9] include sam simulation code that models compression using crddrop --- sam/sim/src/base.py | 21 +++++++ sam/sim/src/compression.py | 109 +++++++++++++++++++++++++++++++++++-- 2 files changed, 125 insertions(+), 5 deletions(-) diff --git a/sam/sim/src/base.py b/sam/sim/src/base.py index 38eaa778..c635c881 100644 --- a/sam/sim/src/base.py +++ b/sam/sim/src/base.py @@ -1,5 +1,8 @@ from abc import ABC, abstractmethod +import numpy as np +import warnings +# warnings.simplefilter(action='ignore', category=FutureWarning) def gen_stkns(dim=10): return ['S' + str(i) for i in range(dim)] @@ -24,6 +27,10 @@ def is_valid_crdpt(elem): return isinstance(elem, int) or elem in valid_tkns +def is_valid_num(elem, dim=10): + return isinstance(elem, int) or isinstance(elem, float) + + def is_valid_val(elem, dim=10): valid_tkns = ['', 'D'] + gen_stkns(dim) return isinstance(elem, int) or isinstance(elem, float) or elem in valid_tkns @@ -32,6 +39,9 @@ def is_valid_val(elem, dim=10): def is_0tkn(elem): return elem == 'N' +# Checks if a token is a non-control (numerical) token +def is_nc_tkn(elem, datatype=int): + return isinstance(elem, datatype) def is_stkn(elem): if isinstance(elem, str): @@ -39,6 +49,12 @@ def is_stkn(elem): return False +def is_dtkn(elem): + if isinstance(elem, str): + return elem == 'D' + return False + + def stkn_order(elem): assert is_stkn(elem) return int(elem[1]) @@ -89,6 +105,11 @@ def is_debug(self): def update(self): pass + # Check the input token of something + def valid_token(self, element, datatype=int): + return element != "" and element is not None and \ + (is_dtkn(element) or is_stkn(element) or is_nc_tkn(element, datatype) or is_0tkn(element)) + def reset(self): self.done = False diff --git a/sam/sim/src/compression.py b/sam/sim/src/compression.py index 939768c0..a87c6386 100644 --- a/sam/sim/src/compression.py +++ b/sam/sim/src/compression.py @@ -1,14 +1,26 @@ from .base import * +from .token import EmptyFiberStknDrop, StknDrop -class Compression(Primitive): - def __init__(self, **kwargs): +class ValDropper(Primitive): + def __init__(self, drop_refs=False, **kwargs): super().__init__(**kwargs) self.in_val = [] self.in_crd = [] + self.in_ref = [] self.curr_crd = '' + self.curr_ref = '' + self.curr_val = '' + self.out_crds = '' + self.out_refs = '' + self.out_vals = '' + self.val_stkn_dropper = EmptyFiberStknDrop() + self.crd_stkn_dropper = EmptyFiberStknDrop() + self.ref_stkn_dropper = EmptyFiberStknDrop() + self.drop_refs = drop_refs + if self.backpressure_en: self.ready_backpressure = True self.data_valid = True @@ -49,13 +61,86 @@ def update(self): if len(self.in_val) > 0 or len(self.in_crd) > 0: self.block_start = False - icrd = "" + icrd = '' + ival = '' if self.done: self.curr_crd = '' + self.curr_val = '' + self.out_crds = '' + self.out_vals = '' + if self.drop_refs: + self.curr_ref = '' + self.out_refs = '' return + elif (len(self.in_val) > 0 and len(self.in_crd) == 0) or (len(self.in_crd) > 0 and len(self.in_val) == 0) or (len(self.in_val) == 0 and len(self.in_crd) == 0): + self.out_crds = '' + self.out_vals = '' + if self.drop_refs: + self.out_refs = '' elif len(self.in_val) > 0 and len(self.in_crd) > 0: - icrd = self + ival = self.in_val.pop(0) + icrd = self.in_crd.pop(0) + iref = '' + if self.drop_refs: + iref = self.in_ref.pop(0) + + # print("ival:", ival) + # print("icrd:", icrd) + + assert ival != '', "ival is an empty str" + + if is_valid_num(ival): + # assert isinstance(icrd, int), "both val and crd need ot match" + if not isinstance(icrd, int) and icrd != 'N': + print("Both val and icrd need to match") + print(icrd, ival) + exit(1) + if ival == 0.0: + self.curr_crd = '' + self.curr_ref = '' + self.curr_val = '' + else: + self.curr_crd = icrd + self.curr_val = ival + if self.drop_refs: + self.curr_ref = iref + elif isinstance(ival, str) and ival != 'D': + assert isinstance(icrd, str), "both val and coord need to match" + self.curr_crd = icrd + self.curr_val = ival + if self.drop_refs: + self.curr_ref = iref + elif ival == 'D': + assert icrd == 'D' + self.curr_val = ival + self.curr_crd = icrd + if self.drop_refs: + self.curr_ref = iref + self.done = True + else: + self.curr_crd = icrd + self.curr_val = ival + if self.drop_refs: + self.curr_ref = iref + + # if self.curr_crd == self.out_crds or icrd == self.out_crds: + # self.out_crds = '' + # self.out_vals = '' + # self.out_refs = '' + # else: + self.val_stkn_dropper.set_in_stream(self.curr_val) + self.crd_stkn_dropper.set_in_stream(self.curr_crd) + self.val_stkn_dropper.update() + self.crd_stkn_dropper.update() + # self.out_crds = self.crd_stkn_dropper.out_val() + # self.out_vals = self.val_stkn_dropper.out_val() + self.out_crds = self.curr_crd + self.out_vals = self.curr_val + if self.drop_refs: + self.ref_stkn_dropper.set_in_stream(self.curr_ref) + self.ref_stkn_dropper.update() + self.out_refs = self.curr_ref if self.debug: print("Curr OuterCrd:", self.curr_ocrd, "\tCurr InnerCrd:", icrd, "\t Curr OutputCrd:", self.curr_crd, @@ -74,6 +159,20 @@ def set_crd(self, crd, parent=None): if self.backpressure_en: parent.set_backpressure(self.fifo_avail_crd) + def set_ref(self, ref, parent=None): + if ref != '' and ref is not None: + self.in_ref.append(ref) + if self.backpressure_en: + parent.set_backpressure(self.fifo_avail_crd) + def out_crd(self): if (self.backpressure_en and self.data_valid) or not self.backpressure_en: - return self.curr_crd + return self.out_crds + + def out_ref(self): + if (self.backpressure_en and self.data_valid) or not self.backpressure_en: + return self.out_refs + + def out_val(self): + if (self.backpressure_en and self.data_valid) or not self.backpressure_en: + return self.out_vals From 05323c77d540bbc4be80387bfa20330ad3d38e86 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 17 Oct 2023 09:52:04 -0700 Subject: [PATCH 6/9] fixed style issues that are failing the CI --- compiler/sam-outputs/onyx-dot/mat_mask_tri.gv | 62 ++++++++ .../sam-outputs/onyx-dot/mat_vecmul_iter.gv | 140 ++++++++++++++++++ sam/sim/src/base.py | 3 + sam/sim/src/compression.py | 6 +- 4 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 compiler/sam-outputs/onyx-dot/mat_mask_tri.gv create mode 100644 compiler/sam-outputs/onyx-dot/mat_vecmul_iter.gv diff --git a/compiler/sam-outputs/onyx-dot/mat_mask_tri.gv b/compiler/sam-outputs/onyx-dot/mat_mask_tri.gv new file mode 100644 index 00000000..2af91546 --- /dev/null +++ b/compiler/sam-outputs/onyx-dot/mat_mask_tri.gv @@ -0,0 +1,62 @@ +digraph SAM { + comment="x=none,B=ss01,C=ss01,D=ss10" + 22 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"] + 21 [comment="type=intersect,index=i" label="intersect i" color=purple shape=box style=filled type="intersect" index="i"] + 20 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"] + 19 [comment="type=repeat,index=i,tensor=D,root=true" label="Repeat i: D" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="D" root="true"] + 18 [comment="type=fiberlookup,index=j,tensor=D,mode=1,format=compressed,src=true,root=false" label="FiberLookup j: D1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="D" mode="1" format="compressed" src="true" root="false"] + 16 [comment="type=intersect,index=j" label="intersect j" color=purple shape=box style=filled type="intersect" index="j"] + 15 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"] + 14 [comment="type=repeat,index=j,tensor=C,root=false" label="Repeat j: C" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="C" root="false"] + 12 [comment="type=fiberlookup,index=k,tensor=C,mode=1,format=compressed,src=true,root=false" label="FiberLookup k: C1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="1" format="compressed" src="true" root="false"] + 11 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"] + 10 [comment="type=repsiggen,index=k" label="RepeatSignalGenerator k" color=cyan3 shape=box style=filled type="repsiggen" index="k"] + 9 [comment="type=repeat,index=k,tensor=B,root=false" label="Repeat k: B" color=cyan2 shape=box style=filled type="repeat" index="k" tensor="B" root="false"] + 6 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] + 5 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 4 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 2 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 1 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 0 [comment="type=fiberwrite,mode=vals,tensor=x,size=1,sink=true" label="FiberWrite Vals: x" color=green3 shape=box style=filled type="fiberwrite" tensor="x" mode="vals" size="1" sink="true"] + 7 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] + 8 [comment="type=arrayvals,tensor=D" label="Array Vals: D" color=green2 shape=box style=filled type="arrayvals" tensor="D"] + 13 [comment="type=fiberlookup,index=k,tensor=D,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: D0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="D" mode="0" format="compressed" src="true" root="false"] + 17 [comment="type=fiberlookup,index=j,tensor=B,mode=1,format=compressed,src=true,root=false" label="FiberLookup j: B1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="B" mode="1" format="compressed" src="true" root="false"] + 23 [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"] + 22 -> 21 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 21 -> 20 [label="crd" style=dashed type="crd"] + 20 -> 19 [label="repsig" style=dotted type="repsig"] + 19 -> 18 [label="ref" style=bold type="ref"] + 18 -> 16 [label="crd_in-D" style=dashed type="crd" comment="in-D"] + 16 -> 15 [label="crd" style=dashed type="crd"] + 15 -> 14 [label="repsig" style=dotted type="repsig"] + 14 -> 12 [label="ref" style=bold type="ref"] + 12 -> 11 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 11 -> 10 [label="crd" style=dashed type="crd"] + 10 -> 9 [label="repsig" style=dotted type="repsig"] + 9 -> 6 [label="ref" style=bold type="ref"] + 6 -> 5 [label="val" type="val"] + 5 -> 4 [label="val" type="val"] + 4 -> 3 [label="val" type="val"] + 3 -> 2 [label="val" type="val"] + 2 -> 1 [label="val" type="val"] + 1 -> 0 [label="val" type="val"] + 11 -> 7 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 7 -> 5 [label="val" type="val"] + 11 -> 8 [label="ref_out-D" style=bold type="ref" comment="out-D"] + 8 -> 4 [label="val" type="val"] + 12 -> 11 [label="ref_in-C" style=bold type="ref" comment="in-C"] + 16 -> 9 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 16 -> 13 [label="ref_out-D" style=bold type="ref" comment="out-D"] + 13 -> 11 [label="crd_in-D" style=dashed type="crd" comment="in-D"] + 13 -> 11 [label="ref_in-D" style=bold type="ref" comment="in-D"] + 18 -> 16 [label="ref_in-D" style=bold type="ref" comment="in-D"] + 21 -> 17 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 17 -> 16 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 17 -> 16 [label="ref_in-B" style=bold type="ref" comment="in-B"] + 21 -> 14 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 22 -> 21 [label="ref_in-B" style=bold type="ref" comment="in-B"] + 23 -> 21 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 23 -> 21 [label="ref_in-C" style=bold type="ref" comment="in-C"] +} diff --git a/compiler/sam-outputs/onyx-dot/mat_vecmul_iter.gv b/compiler/sam-outputs/onyx-dot/mat_vecmul_iter.gv new file mode 100644 index 00000000..532312f6 --- /dev/null +++ b/compiler/sam-outputs/onyx-dot/mat_vecmul_iter.gv @@ -0,0 +1,140 @@ +digraph SAM { + comment="x=s0,B=ss01,C=ss01,D=ss01,E=ss01,f=s0" + 54 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"] + 53 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 1 [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"] + 52 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"] + 51 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 47 [comment="type=repeat,index=i,tensor=C,root=true" label="Repeat i: C" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="C" root="true"] + 46 [comment="type=fiberlookup,index=j,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup j: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="C" mode="0" format="compressed" src="true" root="false"] + 44 [comment="type=intersect,index=j" label="intersect j" color=purple shape=box style=filled type="intersect" index="j"] + 43 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"] + 42 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 39 [comment="type=repeat,index=j,tensor=D,root=false" label="Repeat j: D" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="D" root="false"] + 38 [comment="type=fiberlookup,index=k,tensor=D,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: D0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="D" mode="0" format="compressed" src="true" root="false"] + 36 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"] + 35 [comment="type=repsiggen,index=k" label="RepeatSignalGenerator k" color=cyan3 shape=box style=filled type="repsiggen" index="k"] + 34 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 31 [comment="type=repeat,index=k,tensor=B,root=false" label="Repeat k: B" color=cyan2 shape=box style=filled type="repeat" index="k" tensor="B" root="false"] + 23 [comment="type=repeat,index=l,tensor=B,root=false" label="Repeat l: B" color=cyan2 shape=box style=filled type="repeat" index="l" tensor="B" root="false"] + 15 [comment="type=repeat,index=m,tensor=B,root=false" label="Repeat m: B" color=cyan2 shape=box style=filled type="repeat" index="m" tensor="B" root="false"] + 10 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] + 9 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 8 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 7 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 6 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] + 5 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 4 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 2 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] + 0 [comment="type=fiberwrite,mode=vals,tensor=x,size=1*B0_dim,sink=true" label="FiberWrite Vals: x" color=green3 shape=box style=filled type="fiberwrite" tensor="x" mode="vals" size="1*B0_dim" sink="true"] + 32 [comment="type=repeat,index=k,tensor=E,root=false" label="Repeat k: E" color=cyan2 shape=box style=filled type="repeat" index="k" tensor="E" root="false"] + 30 [comment="type=fiberlookup,index=l,tensor=E,mode=0,format=compressed,src=true,root=false" label="FiberLookup l: E0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="l" tensor="E" mode="0" format="compressed" src="true" root="false"] + 28 [comment="type=intersect,index=l" label="intersect l" color=purple shape=box style=filled type="intersect" index="l"] + 27 [comment="type=repsiggen,index=l" label="RepeatSignalGenerator l" color=cyan3 shape=box style=filled type="repsiggen" index="l"] + 26 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 24 [comment="type=repeat,index=l,tensor=C,root=false" label="Repeat l: C" color=cyan2 shape=box style=filled type="repeat" index="l" tensor="C" root="false"] + 16 [comment="type=repeat,index=m,tensor=C,root=false" label="Repeat m: C" color=cyan2 shape=box style=filled type="repeat" index="m" tensor="C" root="false"] + 11 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] + 25 [comment="type=repeat,index=l,tensor=f,root=false" label="Repeat l: f" color=cyan2 shape=box style=filled type="repeat" index="l" tensor="f" root="false"] + 22 [comment="type=fiberlookup,index=m,tensor=f,mode=0,format=compressed,src=true,root=false" label="FiberLookup m: f0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="m" tensor="f" mode="0" format="compressed" src="true" root="false"] + 20 [comment="type=intersect,index=m" label="intersect m" color=purple shape=box style=filled type="intersect" index="m"] + 19 [comment="type=repsiggen,index=m" label="RepeatSignalGenerator m" color=cyan3 shape=box style=filled type="repsiggen" index="m"] + 18 [comment="type=broadcast" shape=point style=invis type="broadcast"] + 17 [comment="type=repeat,index=m,tensor=D,root=false" label="Repeat m: D" color=cyan2 shape=box style=filled type="repeat" index="m" tensor="D" root="false"] + 12 [comment="type=arrayvals,tensor=D" label="Array Vals: D" color=green2 shape=box style=filled type="arrayvals" tensor="D"] + 13 [comment="type=arrayvals,tensor=E" label="Array Vals: E" color=green2 shape=box style=filled type="arrayvals" tensor="E"] + 14 [comment="type=arrayvals,tensor=f" label="Array Vals: f" color=green2 shape=box style=filled type="arrayvals" tensor="f"] + 21 [comment="type=fiberlookup,index=m,tensor=E,mode=1,format=compressed,src=true,root=false" label="FiberLookup m: E1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="m" tensor="E" mode="1" format="compressed" src="true" root="false"] + 33 [comment="type=repeat,index=k,tensor=f,root=false" label="Repeat k: f" color=cyan2 shape=box style=filled type="repeat" index="k" tensor="f" root="false"] + 29 [comment="type=fiberlookup,index=l,tensor=D,mode=1,format=compressed,src=true,root=false" label="FiberLookup l: D1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="l" tensor="D" mode="1" format="compressed" src="true" root="false"] + 40 [comment="type=repeat,index=j,tensor=E,root=false" label="Repeat j: E" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="E" root="false"] + 41 [comment="type=repeat,index=j,tensor=f,root=false" label="Repeat j: f" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="f" root="false"] + 37 [comment="type=fiberlookup,index=k,tensor=C,mode=1,format=compressed,src=true,root=false" label="FiberLookup k: C1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="1" format="compressed" src="true" root="false"] + 48 [comment="type=repeat,index=i,tensor=D,root=true" label="Repeat i: D" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="D" root="true"] + 49 [comment="type=repeat,index=i,tensor=E,root=true" label="Repeat i: E" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="E" root="true"] + 50 [comment="type=repeat,index=i,tensor=f,root=true" label="Repeat i: f" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="f" root="true"] + 45 [comment="type=fiberlookup,index=j,tensor=B,mode=1,format=compressed,src=true,root=false" label="FiberLookup j: B1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="j" tensor="B" mode="1" format="compressed" src="true" root="false"] + 54 -> 53 [label="crd" style=dashed type="crd" comment=""] + 53 -> 1 [label="crd" style=dashed type="crd"] + 53 -> 52 [label="crd" style=dashed type="crd"] + 52 -> 51 [label="repsig" style=dotted type="repsig"] + 51 -> 47 [label="repsig" style=dotted type="repsig"] + 47 -> 46 [label="ref" style=bold type="ref"] + 46 -> 44 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 44 -> 43 [label="crd" style=dashed type="crd"] + 43 -> 42 [label="repsig" style=dotted type="repsig"] + 42 -> 39 [label="repsig" style=dotted type="repsig"] + 39 -> 38 [label="ref" style=bold type="ref"] + 38 -> 36 [label="crd_in-D" style=dashed type="crd" comment="in-D"] + 36 -> 35 [label="crd" style=dashed type="crd"] + 35 -> 34 [label="repsig" style=dotted type="repsig"] + 34 -> 31 [label="repsig" style=dotted type="repsig"] + 31 -> 23 [label="ref" style=bold type="ref"] + 23 -> 15 [label="ref" style=bold type="ref"] + 15 -> 10 [label="ref" style=bold type="ref"] + 10 -> 9 [label="val" type="val"] + 9 -> 8 [label="val" type="val"] + 8 -> 7 [label="val" type="val"] + 7 -> 6 [label="val" type="val"] + 6 -> 5 [label="val" type="val"] + 5 -> 4 [label="val" type="val"] + 4 -> 3 [label="val" type="val"] + 3 -> 2 [label="val" type="val"] + 2 -> 0 [label="val" type="val"] + 34 -> 32 [label="repsig" style=dotted type="repsig"] + 32 -> 30 [label="ref" style=bold type="ref"] + 30 -> 28 [label="crd_in-E" style=dashed type="crd" comment="in-E"] + 28 -> 27 [label="crd" style=dashed type="crd"] + 27 -> 26 [label="repsig" style=dotted type="repsig"] + 26 -> 23 [label="repsig" style=dotted type="repsig"] + 26 -> 24 [label="repsig" style=dotted type="repsig"] + 24 -> 16 [label="ref" style=bold type="ref"] + 16 -> 11 [label="ref" style=bold type="ref"] + 11 -> 9 [label="val" type="val"] + 26 -> 25 [label="repsig" style=dotted type="repsig"] + 25 -> 22 [label="ref" style=bold type="ref"] + 22 -> 20 [label="crd_in-f" style=dashed type="crd" comment="in-f"] + 20 -> 19 [label="crd" style=dashed type="crd"] + 19 -> 18 [label="repsig" style=dotted type="repsig"] + 18 -> 15 [label="repsig" style=dotted type="repsig"] + 18 -> 16 [label="repsig" style=dotted type="repsig"] + 18 -> 17 [label="repsig" style=dotted type="repsig"] + 17 -> 12 [label="ref" style=bold type="ref"] + 12 -> 8 [label="val" type="val"] + 20 -> 13 [label="ref_out-E" style=bold type="ref" comment="out-E"] + 13 -> 7 [label="val" type="val"] + 20 -> 14 [label="ref_out-f" style=bold type="ref" comment="out-f"] + 14 -> 6 [label="val" type="val"] + 22 -> 20 [label="ref_in-f" style=bold type="ref" comment="in-f"] + 28 -> 17 [label="ref_out-D" style=bold type="ref" comment="out-D"] + 28 -> 21 [label="ref_out-E" style=bold type="ref" comment="out-E"] + 21 -> 20 [label="crd_in-E" style=dashed type="crd" comment="in-E"] + 21 -> 20 [label="ref_in-E" style=bold type="ref" comment="in-E"] + 30 -> 28 [label="ref_in-E" style=bold type="ref" comment="in-E"] + 34 -> 33 [label="repsig" style=dotted type="repsig"] + 33 -> 25 [label="ref" style=bold type="ref"] + 36 -> 24 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 36 -> 29 [label="ref_out-D" style=bold type="ref" comment="out-D"] + 29 -> 28 [label="crd_in-D" style=dashed type="crd" comment="in-D"] + 29 -> 28 [label="ref_in-D" style=bold type="ref" comment="in-D"] + 38 -> 36 [label="ref_in-D" style=bold type="ref" comment="in-D"] + 42 -> 40 [label="repsig" style=dotted type="repsig"] + 40 -> 32 [label="ref" style=bold type="ref"] + 42 -> 41 [label="repsig" style=dotted type="repsig"] + 41 -> 33 [label="ref" style=bold type="ref"] + 44 -> 31 [label="ref_out-B" style=bold type="ref" comment="out-B"] + 44 -> 37 [label="ref_out-C" style=bold type="ref" comment="out-C"] + 37 -> 36 [label="crd_in-C" style=dashed type="crd" comment="in-C"] + 37 -> 36 [label="ref_in-C" style=bold type="ref" comment="in-C"] + 46 -> 44 [label="ref_in-C" style=bold type="ref" comment="in-C"] + 51 -> 48 [label="repsig" style=dotted type="repsig"] + 48 -> 39 [label="ref" style=bold type="ref"] + 51 -> 49 [label="repsig" style=dotted type="repsig"] + 49 -> 40 [label="ref" style=bold type="ref"] + 51 -> 50 [label="repsig" style=dotted type="repsig"] + 50 -> 41 [label="ref" style=bold type="ref"] + 54 -> 45 [label="ref" style=bold type="ref" comment=""] + 45 -> 44 [label="crd_in-B" style=dashed type="crd" comment="in-B"] + 45 -> 44 [label="ref_in-B" style=bold type="ref" comment="in-B"] +} diff --git a/sam/sim/src/base.py b/sam/sim/src/base.py index c635c881..2ba86530 100644 --- a/sam/sim/src/base.py +++ b/sam/sim/src/base.py @@ -4,6 +4,7 @@ # warnings.simplefilter(action='ignore', category=FutureWarning) + def gen_stkns(dim=10): return ['S' + str(i) for i in range(dim)] @@ -39,10 +40,12 @@ def is_valid_val(elem, dim=10): def is_0tkn(elem): return elem == 'N' + # Checks if a token is a non-control (numerical) token def is_nc_tkn(elem, datatype=int): return isinstance(elem, datatype) + def is_stkn(elem): if isinstance(elem, str): return elem.startswith('S') and (len(elem) == 2) diff --git a/sam/sim/src/compression.py b/sam/sim/src/compression.py index a87c6386..ad96eb2e 100644 --- a/sam/sim/src/compression.py +++ b/sam/sim/src/compression.py @@ -73,7 +73,9 @@ def update(self): self.curr_ref = '' self.out_refs = '' return - elif (len(self.in_val) > 0 and len(self.in_crd) == 0) or (len(self.in_crd) > 0 and len(self.in_val) == 0) or (len(self.in_val) == 0 and len(self.in_crd) == 0): + elif (len(self.in_val) > 0 and len(self.in_crd) == 0) \ + or (len(self.in_crd) > 0 and len(self.in_val) == 0) \ + or (len(self.in_val) == 0 and len(self.in_crd) == 0): self.out_crds = '' self.out_vals = '' if self.drop_refs: @@ -168,7 +170,7 @@ def set_ref(self, ref, parent=None): def out_crd(self): if (self.backpressure_en and self.data_valid) or not self.backpressure_en: return self.out_crds - + def out_ref(self): if (self.backpressure_en and self.data_valid) or not self.backpressure_en: return self.out_refs From cdbea75071c58ff64c05340535b2d7452bfb40c0 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 17 Oct 2023 09:56:08 -0700 Subject: [PATCH 7/9] fixed style issues that are failing the CI --- sam/onyx/hw_nodes/merge_node.py | 2 +- sam/sim/src/compression.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sam/onyx/hw_nodes/merge_node.py b/sam/onyx/hw_nodes/merge_node.py index bf0ee8b4..9b1f1ae7 100644 --- a/sam/onyx/hw_nodes/merge_node.py +++ b/sam/onyx/hw_nodes/merge_node.py @@ -129,7 +129,7 @@ def configure(self, attributes): cmrg_stop_lvl = 1 op = 0 # 0 for compression, 1 for crddrop - cmrg_mode = self.mode + cmrg_mode = self.mode cfg_kwargs = { 'cmrg_enable': cmrg_enable, 'cmrg_stop_lvl': cmrg_stop_lvl, diff --git a/sam/sim/src/compression.py b/sam/sim/src/compression.py index ad96eb2e..f344a12a 100644 --- a/sam/sim/src/compression.py +++ b/sam/sim/src/compression.py @@ -75,7 +75,7 @@ def update(self): return elif (len(self.in_val) > 0 and len(self.in_crd) == 0) \ or (len(self.in_crd) > 0 and len(self.in_val) == 0) \ - or (len(self.in_val) == 0 and len(self.in_crd) == 0): + or (len(self.in_val) == 0 and len(self.in_crd) == 0): self.out_crds = '' self.out_vals = '' if self.drop_refs: From 0fb04fda60d61adc2287dbe340f5ce27e7190407 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 17 Oct 2023 10:09:44 -0700 Subject: [PATCH 8/9] removed opal graphs that are not ready yet --- .../opal-dot/matmul_ijk_crddrop_relu.gv | 60 ------------------- .../matmul_ijk_crddrop_relu_no_valdrop.gv | 54 ----------------- 2 files changed, 114 deletions(-) delete mode 100644 compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv delete mode 100644 compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv diff --git a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv deleted file mode 100644 index 4d6ba559..00000000 --- a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu.gv +++ /dev/null @@ -1,60 +0,0 @@ -digraph SAM { - comment="X=ss01,B=ss01,C=ss10" - 17 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"] - 16 [comment="type=broadcast" shape=point style=invis type="broadcast"] - 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"] - 15 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"] - 14 [comment="type=repeat,index=i,tensor=C,root=true" label="Repeat i: C" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="C" root="true"] - 13 [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"] - 12 [comment="type=broadcast" shape=point style=invis type="broadcast"] - 1 [comment="type=fiberwrite,index=j,tensor=X,mode=1,format=compressed,segsize=B0_dim+1,crdsize=B0_dim*C1_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*C1_dim" sink="true"] - 11 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"] - 10 [comment="type=repeat,index=j,tensor=B,root=false" label="Repeat j: B" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="B" root="false"] - 8 [comment="type=fiberlookup,index=k,tensor=B,mode=1,format=compressed,src=true,root=false" label="FiberLookup k: B1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="B" mode="1" format="compressed" src="true" root="false"] - 7 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"] - 5 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] - 4 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] - 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] - 0 [comment="type=fiberwrite,mode=vals,tensor=X,size=1*B0_dim*C1_dim,sink=true" label="FiberWrite Vals: X" color=green3 shape=box style=filled type="fiberwrite" tensor="X" mode="vals" size="1*B0_dim*C1_dim" sink="true"] - 6 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] - 9 [comment="type=fiberlookup,index=k,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="0" format="compressed" src="true" root="false"] - 18 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] - 19 [comment="type=crddrop,outer=j,inner=k" label="CrdDrop j,k" color=orange shape=box style=filled type="crddrop" outer="j" inner="k"] - 20 [comment="type=max" label="Max 0" color=brown shape=box style=filled type="max"] - 21 [comment="type=valdrop,outer=j,inner=val" label="ValDropper j,val" color=purple shape=box style=filled type="valdrop" outer="j" inner="val"] - 22 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] - 17 -> 16 [label="crd" style=dashed type="crd" comment=""] - 16 -> 15 [label="crd" style=dashed type="crd"] - 15 -> 14 [label="repsig" style=dotted type="repsig"] - 14 -> 13 [label="ref" style=bold type="ref"] - 13 -> 12 [label="crd" style=dashed type="crd" comment=""] - 12 -> 11 [label="crd" style=dashed type="crd"] - 11 -> 10 [label="repsig" style=dotted type="repsig"] - 10 -> 8 [label="ref" style=bold type="ref"] - 8 -> 7 [label="crd_in-B" style=dashed type="crd" comment="in-B"] - 7 -> 5 [label="ref_out-B" style=bold type="ref" comment="out-B"] - 5 -> 4 [label="val" type="val"] - 7 -> 6 [label="ref_out-C" style=bold type="ref" comment="out-C"] - 6 -> 4 [label="val" type="val"] - 8 -> 7 [label="ref_in-B" style=bold type="ref" comment="in-B"] - 13 -> 9 [label="ref" style=bold type="ref" comment=""] - 9 -> 7 [label="crd_in-C" style=dashed type="crd" comment="in-C"] - 9 -> 7 [label="ref_in-C" style=bold type="ref" comment="in-C"] - 17 -> 10 [label="ref" style=bold type="ref" comment=""] - - 4 -> 19 [label="val_inner-k" type="val" comment="inner-k"] - 12 -> 19 [label="crd_outer-j" style=dashed type="crd" comment="outer-j"] - 19 -> 3 [label="val_inner-k" type="val" comment="inner-k"] - 3 -> 20 [label="val" type="val" comment="val"] - 20 -> 21 [label="val" type="val" comment="relu-val"] - 18 -> 21 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] - 21 -> 22 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] - 18 -> 22 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] - - 19 -> 18 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] - 16 -> 18 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] - 21 -> 0 [label="val" type="val"] - - 22 -> 2 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] - 22 -> 1 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] -} diff --git a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv b/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv deleted file mode 100644 index d4a2c34a..00000000 --- a/compiler/sam-outputs/opal-dot/matmul_ijk_crddrop_relu_no_valdrop.gv +++ /dev/null @@ -1,54 +0,0 @@ -digraph SAM { - comment="X=ss01,B=ss01,C=ss10" - 17 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"] - 16 [comment="type=broadcast" shape=point style=invis type="broadcast"] - 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"] - 15 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"] - 14 [comment="type=repeat,index=i,tensor=C,root=true" label="Repeat i: C" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="C" root="true"] - 13 [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"] - 12 [comment="type=broadcast" shape=point style=invis type="broadcast"] - 1 [comment="type=fiberwrite,index=j,tensor=X,mode=1,format=compressed,segsize=B0_dim+1,crdsize=B0_dim*C1_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*C1_dim" sink="true"] - 11 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"] - 10 [comment="type=repeat,index=j,tensor=B,root=false" label="Repeat j: B" color=cyan2 shape=box style=filled type="repeat" index="j" tensor="B" root="false"] - 8 [comment="type=fiberlookup,index=k,tensor=B,mode=1,format=compressed,src=true,root=false" label="FiberLookup k: B1\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="B" mode="1" format="compressed" src="true" root="false"] - 7 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"] - 5 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"] - 4 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"] - 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce"] - 0 [comment="type=fiberwrite,mode=vals,tensor=X,size=1*B0_dim*C1_dim,sink=true" label="FiberWrite Vals: X" color=green3 shape=box style=filled type="fiberwrite" tensor="X" mode="vals" size="1*B0_dim*C1_dim" sink="true"] - 6 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"] - 9 [comment="type=fiberlookup,index=k,tensor=C,mode=0,format=compressed,src=true,root=false" label="FiberLookup k: C0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="C" mode="0" format="compressed" src="true" root="false"] - 18 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"] - 19 [comment="type=crddrop,outer=j,inner=k" label="CrdDrop j,k" color=orange shape=box style=filled type="crddrop" outer="j" inner="k"] - 20 [comment="type=max" label="Max 0" color=brown shape=box style=filled type="max"] - 17 -> 16 [label="crd" style=dashed type="crd" comment=""] - 16 -> 15 [label="crd" style=dashed type="crd"] - 15 -> 14 [label="repsig" style=dotted type="repsig"] - 14 -> 13 [label="ref" style=bold type="ref"] - 13 -> 12 [label="crd" style=dashed type="crd" comment=""] - 12 -> 11 [label="crd" style=dashed type="crd"] - 11 -> 10 [label="repsig" style=dotted type="repsig"] - 10 -> 8 [label="ref" style=bold type="ref"] - 8 -> 7 [label="crd_in-B" style=dashed type="crd" comment="in-B"] - 7 -> 5 [label="ref_out-B" style=bold type="ref" comment="out-B"] - 5 -> 4 [label="val" type="val"] - 7 -> 6 [label="ref_out-C" style=bold type="ref" comment="out-C"] - 6 -> 4 [label="val" type="val"] - 8 -> 7 [label="ref_in-B" style=bold type="ref" comment="in-B"] - 13 -> 9 [label="ref" style=bold type="ref" comment=""] - 9 -> 7 [label="crd_in-C" style=dashed type="crd" comment="in-C"] - 9 -> 7 [label="ref_in-C" style=bold type="ref" comment="in-C"] - 17 -> 10 [label="ref" style=bold type="ref" comment=""] - - 4 -> 19 [label="val_inner-k" type="val" comment="inner-k"] - 12 -> 19 [label="crd_outer-j" style=dashed type="crd" comment="outer-j"] - 19 -> 3 [label="val_inner-k" type="val" comment="inner-k"] - 3 -> 20 [label="val" type="val" comment="val"] - - 19 -> 18 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] - 16 -> 18 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] - 20 -> 0 [label="val" type="val"] - - 18 -> 2 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] - 18 -> 1 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] -} From 5dd14cd3e5f9d3f554db5af2db6f308313a5d916 Mon Sep 17 00:00:00 2001 From: Bo Wun Cheng Date: Tue, 17 Oct 2023 10:47:04 -0700 Subject: [PATCH 9/9] added unit test for valdropper --- sam/sim/test/primitives/test_compression.py | 85 +++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 sam/sim/test/primitives/test_compression.py diff --git a/sam/sim/test/primitives/test_compression.py b/sam/sim/test/primitives/test_compression.py new file mode 100644 index 00000000..b3163dbc --- /dev/null +++ b/sam/sim/test/primitives/test_compression.py @@ -0,0 +1,85 @@ +import pytest +from sam.sim.src.compression import ValDropper +from sam.sim.src.base import remove_emptystr +from sam.sim.test.test import TIMEOUT +import numpy as np + + +@pytest.mark.parametrize("dim1", [8]) +def test_compress_1d(dim1, debug_sim): + nums = np.random.choice([0, 1], size=dim1, p=[.4, .6]) + in1 = nums.tolist() + ['S0', 'D'] + crd_nums = np.arange(dim1) + crd = crd_nums.tolist() + ['S0', 'D'] + # assert (len(in1) == len(in1)) + + gold_val = nums[nums != 0].tolist() + ['S0', 'D'] + gold_crd = np.delete(crd_nums, np.where(nums == 0)).tolist() + ['S0', 'D'] + + comp = ValDropper(debug=debug_sim) + + done = False + time = 0 + + out_val = [] + out_crd = [] + + while not done and time < TIMEOUT: + + if len(in1) > 0: + comp.set_val(in1.pop(0)) + comp.set_crd(crd.pop(0)) + + comp.update() + out_val.append(comp.out_val()) + out_crd.append(comp.out_crd()) + + if debug_sim: + print("Timestep", time, "\t Out:", comp.out_val()) + + done = comp.out_done() + time += 1 + + out_val = remove_emptystr(out_val) + out_crd = remove_emptystr(out_crd) + print("Ref val:", gold_val) + print("Out val:", out_val) + + print("Ref crd:", gold_crd) + print("Out crd:", out_crd) + + assert (out_val == gold_val) + assert (out_crd == gold_crd) + +# @pytest.mark.parametrize("dim1", [4, 16, 32, 64]) +# def test_exp_1d(dim1, debug_sim): +# in1 = [x for x in range(dim1)] + ['S0', 'D'] +# in2 = None +# # assert (len(in1) == len(in1)) + +# gold_val = np.exp(np.arange(dim1)).tolist() + ['S0', 'D'] + +# exp1 = Exp(debug=debug_sim) + +# done = False +# time = 0 +# out_val = [] +# exp1.set_in2(in2) +# while not done and time < TIMEOUT: +# if len(in1) > 0: +# exp1.set_in1(in1.pop(0)) + +# exp1.update() + +# out_val.append(exp1.out_val()) + +# print("Timestep", time, "\t Out:", exp1.out_val()) + +# done = exp1.out_done() +# time += 1 + +# out_val = remove_emptystr(out_val) +# print("Ref:", gold_val) +# print("Out:", out_val) + +# assert (out_val == gold_val)