Skip to content

Commit

Permalink
Merge pull request #102 from weiya711/vector-accum-mapping
Browse files Browse the repository at this point in the history
Vector accum mapping
  • Loading branch information
mcoduoza authored Nov 17, 2023
2 parents cade108 + 8b313f8 commit 5deea43
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 132 deletions.
44 changes: 44 additions & 0 deletions compiler/sam-outputs/onyx-dot/matmul_ikj.gv
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
digraph SAM {
comment="X=ss01,B=ss01,C=ss01"
20 [comment="type=vectorreducer,index=j" label="VectorReducer j" color=brown shape=box style=filled type="vectorreducer" accum_index="j"]
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"]
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"]
19 [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"]
18 [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"]
17 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"]
16 [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"]
15 [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"]
13 [comment="type=intersect,index=k" label="intersect k" color=purple shape=box style=filled type="intersect" index="k"]
9 [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"]
7 [comment="type=arrayvals,tensor=B" label="Array Vals: B" color=green2 shape=box style=filled type="arrayvals" tensor="B"]
6 [comment="type=mul" label="Mul" color=brown shape=box style=filled type="mul"]
12 [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=broadcast" shape=point style=invis type="broadcast"]
10 [comment="type=repsiggen,index=j" label="RepeatSignalGenerator j" color=cyan3 shape=box style=filled type="repsiggen" index="j"]
8 [comment="type=arrayvals,tensor=C" label="Array Vals: C" color=green2 shape=box style=filled type="arrayvals" tensor="C"]
14 [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"]
19 -> 18 [label="crd" style=dashed type="crd" comment=""]
18 -> 17 [label="crd" style=dashed type="crd" comment=""]
17 -> 16 [label="repsig" style=dotted type="repsig"]
16 -> 15 [label="ref" style=bold type="ref"]
15 -> 13 [label="crd_in-C" style=dashed type="crd" comment="in-C"]
13 -> 9 [label="ref_out-B" style=bold type="ref" comment="out-B"]
9 -> 7 [label="ref" style=bold type="ref"]
7 -> 6 [label="val" type="val"]
13 -> 12 [label="ref_out-C" style=bold type="ref" comment="out-C"]
12 -> 11 [label="crd" style=dashed type="crd" comment=""]
19 -> 2 [label="crd_i" style=dashed type="crd" comment="i"]
11 -> 20 [label="crd_j" style=dashed type="crd" comment="j" special="true"]
11 -> 10 [label="crd" style=dashed type="crd" comment=""]
10 -> 9 [label="repsig" style=dotted type="repsig"]
12 -> 8 [label="ref" style=bold type="ref" comment=""]
8 -> 6 [label="val" type="val"]
15 -> 13 [label="ref_in-C" style=bold type="ref" comment="in-C"]
19 -> 14 [label="ref" style=bold type="ref" comment=""]
14 -> 13 [label="crd_in-B" style=dashed type="crd" comment="in-B"]
14 -> 13 [label="ref_in-B" style=bold type="ref" comment="in-B"]
6 -> 20 [label="mul_val_out" type="val"]
20 -> 0 [label="final_vals" type="val"]
20 -> 1 [label="crd_out-j" style=dashed type="crd" comment="out-j"]
}
12 changes: 10 additions & 2 deletions sam/onyx/hw_nodes/buffet_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ def configure(self, attributes):
cap0 = kratos.clog2(capacity_0) - fetch_width_log
cap1 = kratos.clog2(capacity_1) - fetch_width_log

if 'vector_reduce_mode' in attributes:
is_in_vr_mode = attributes['vector_reduce_mode'].strip('"')
if is_in_vr_mode == "true":
vr_mode = 1
else:
vr_mode = 0

cfg_kwargs = {
'capacity_0': cap0,
'capacity_1': cap1
'capacity_1': cap1,
'vr_mode': vr_mode
}
return (capacity_0, capacity_1), cfg_kwargs
return (capacity_0, capacity_1, vr_mode), cfg_kwargs
14 changes: 9 additions & 5 deletions sam/onyx/hw_nodes/compute_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ def connect(self, other, edge, kwargs=None):
pe = self.get_name()
# isect_conn = other.get_num_inputs()

if 'tensor' not in edge.get_attributes():
# Taking some liberties here - but technically this is the combo val
# isect_conn = other.get_connection_from_tensor('B')
isect_conn = other.get_connection_from_tensor('C')
if 'vector_reduce_mode' in edge.get_attributes():
if edge.get_attributes()['vector_reduce_mode']:
isect_conn = 0
else:
isect_conn = other.get_connection_from_tensor(edge.get_tensor())
if 'tensor' not in edge.get_attributes():
# Taking some liberties here - but technically this is the combo val
# isect_conn = other.get_connection_from_tensor('B')
isect_conn = other.get_connection_from_tensor('C')
else:
isect_conn = other.get_connection_from_tensor(edge.get_tensor())

new_conns = {
f'pe_to_isect_{in_str}_{isect_conn}': [
Expand Down
9 changes: 6 additions & 3 deletions sam/onyx/hw_nodes/fiberaccess_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ def configure(self, attributes, flavor):

cfg_tuple, cfg_kwargs = self.get_flavor(flavor=flavor).configure(attributes)
cfg_kwargs['flavor'] = flavor
print("THESE ARE MY CONFIG KWARGS")
print(cfg_kwargs)
# breakpoint()

vr_mode = 0
cfg_tuple += (vr_mode,)
cfg_kwargs["vr_mode"] = vr_mode
# vr_mode = 0
# cfg_tuple += (vr_mode,)
# cfg_kwargs["vr_mode"] = vr_mode

return cfg_tuple, cfg_kwargs
2 changes: 1 addition & 1 deletion sam/onyx/hw_nodes/hw_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HWNodeType(Enum):
Broadcast = 12
RepSigGen = 13
CrdHold = 14
SpAccumulator = 15
VectorReducer = 15
FiberAccess = 16


Expand Down
13 changes: 11 additions & 2 deletions sam/onyx/hw_nodes/intersect_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def connect(self, other, edge, kwargs=None):
print(edge.get_attributes())
edge_comment = edge.get_attributes()['comment'].strip('"')
tensor = edge_comment.split('-')[1]
print(self.tensor_to_conn)
out_conn = self.tensor_to_conn[tensor]
compute_conn = compute.get_num_inputs()
new_conns = {
Expand Down Expand Up @@ -248,6 +249,14 @@ def configure(self, attributes):
cmrg_enable = 0
cmrg_stop_lvl = 0
type_op = attributes['type'].strip('"')

if 'vector_reduce_mode' in attributes:
is_in_vr_mode = attributes['vector_reduce_mode'].strip('"')
if is_in_vr_mode == "true":
vr_mode = 1
else:
vr_mode = 0

if type_op == "intersect":
op = JoinerOp.INTERSECT.value
elif type_op == "union":
Expand All @@ -258,6 +267,6 @@ def configure(self, attributes):
'cmrg_enable': cmrg_enable,
'cmrg_stop_lvl': cmrg_stop_lvl,
'op': op,
'vr_mode': 0
'vr_mode': vr_mode
}
return (cmrg_enable, cmrg_stop_lvl, op, 0), cfg_kwargs
return (cmrg_enable, cmrg_stop_lvl, op, vr_mode), cfg_kwargs
11 changes: 10 additions & 1 deletion sam/onyx/hw_nodes/merge_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ def connect(self, other, edge, kwargs=None):

return new_conns
elif other_type == IntersectNode:
raise NotImplementedError(f'Cannot connect MergeNode to {other_type}')
isect = other.get_name()
print("MERGE TO UNION FOR VECTOR REDUCE")
new_conns = {
f'merge_to_union_inner': [
([(merge, f"cmrg_coord_out_{0}"), (isect, f"coord_in_{0}")], 17),
]
}

return new_conns
# raise NotImplementedError(f'Cannot connect MergeNode to {other_type}')
elif other_type == ReduceNode:
# raise NotImplementedError(f'Cannot connect MergeNode to {other_type}')
other_red = other.get_name()
Expand Down
37 changes: 27 additions & 10 deletions sam/onyx/hw_nodes/read_scanner_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def connect(self, other, edge, kwargs=None):
edge_attr = edge.get_attributes()
if 'use_alt_out_port' in edge_attr:
out_conn = 'block_rd_out'
elif ('vector_reduce_mode' in edge_attr):
if (edge_attr['vector_reduce_mode']):
out_conn = 'pos_out'
else:
out_conn = 'coord_out'

Expand All @@ -102,7 +105,13 @@ def connect(self, other, edge, kwargs=None):
elif other_type == IntersectNode:
# Send both....
isect = other.get_name()
isect_conn = other.get_connection_from_tensor(self.get_tensor())
if 'vector_reduce_mode' in edge.get_attributes():
if edge.get_attributes()['vector_reduce_mode']:
isect_conn = 1
elif 'special' in edge.get_attributes():
isect_conn = 0
else:
isect_conn = other.get_connection_from_tensor(self.get_tensor())

e_attr = edge.get_attributes()
# isect_conn = 0
Expand Down Expand Up @@ -247,12 +256,12 @@ def configure(self, attributes):
dim_size = 1
stop_lvl = 0

if 'spacc' in attributes:
spacc_mode = 1
assert 'stop_lvl' in attributes
stop_lvl = int(attributes['stop_lvl'].strip('"'))
else:
spacc_mode = 0
# if 'spacc' in attributes:
# spacc_mode = 1
# assert 'stop_lvl' in attributes
# stop_lvl = int(attributes['stop_lvl'].strip('"'))
# else:
# spacc_mode = 0

# This is a fiberwrite's opposing read scanner for comms with GLB
if attributes['type'].strip('"') == 'fiberwrite':
Expand Down Expand Up @@ -283,6 +292,13 @@ def configure(self, attributes):
lookup = 0
block_mode = int(attributes['type'].strip('"') == 'fiberwrite')

if 'vector_reduce_mode' in attributes:
is_in_vr_mode = attributes['vector_reduce_mode'].strip('"')
if is_in_vr_mode == "true":
vr_mode = 1
else:
vr_mode = 0

cfg_kwargs = {
'dense': dense,
'dim_size': dim_size,
Expand All @@ -294,11 +310,12 @@ def configure(self, attributes):
'do_repeat': do_repeat,
'repeat_outer': repeat_outer,
'repeat_factor': repeat_factor,
'stop_lvl': stop_lvl,
# 'stop_lvl': stop_lvl,
'block_mode': block_mode,
'lookup': lookup,
'spacc_mode': spacc_mode
# 'spacc_mode': spacc_mode
'vr_mode': vr_mode
}

return (inner_offset, max_outer_dim, strides, ranges, is_root, do_repeat,
repeat_outer, repeat_factor, stop_lvl, block_mode, lookup, spacc_mode), cfg_kwargs
repeat_outer, repeat_factor, block_mode, lookup, vr_mode), cfg_kwargs
31 changes: 20 additions & 11 deletions sam/onyx/hw_nodes/write_scanner_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def connect(self, other, edge, kwargs=None):
def configure(self, attributes):

stop_lvl = 0
init_blank = 0

# compressed = int(attributes['format'] == 'compressed')
if 'format' in attributes and 'vals' in attributes['format'].strip('"'):
Expand All @@ -89,14 +90,14 @@ def configure(self, attributes):
else:
compressed = 1

if 'spacc' in attributes:
spacc_mode = 1
init_blank = 1
assert 'stop_lvl' in attributes
stop_lvl = int(attributes['stop_lvl'].strip('"'))
else:
spacc_mode = 0
init_blank = 0
# if 'spacc' in attributes:
# spacc_mode = 1
# init_blank = 1
# assert 'stop_lvl' in attributes
# stop_lvl = int(attributes['stop_lvl'].strip('"'))
# else:
# spacc_mode = 0
# init_blank = 0

# compressed = int(attributes['format'] == 'compressed')
if attributes['type'].strip('"') == 'arrayvals':
Expand All @@ -112,16 +113,24 @@ def configure(self, attributes):
else:
block_mode = 0

if 'vector_reduce_mode' in attributes:
is_in_vr_mode = attributes['vector_reduce_mode'].strip('"')
if is_in_vr_mode == "true":
vr_mode = 1
else:
vr_mode = 0

# block_mode = int(attributes['type'].strip('"') == 'fiberlookup')
# cfg_tuple = (inner_offset, compressed, lowest_level, stop_lvl, block_mode)
cfg_tuple = (compressed, lowest_level, stop_lvl, block_mode, init_blank, spacc_mode)
cfg_tuple = (compressed, lowest_level, stop_lvl, block_mode, vr_mode, init_blank)
cfg_kwargs = {
# 'inner_offset': inner_offset,
'compressed': compressed,
'lowest_level': lowest_level,
'stop_lvl': stop_lvl,
'block_mode': block_mode,
'init_blank': init_blank,
'spacc_mode': spacc_mode
'vr_mode': vr_mode,
'init_blank': init_blank
# 'spacc_mode': spacc_mode
}
return cfg_tuple, cfg_kwargs
Loading

0 comments on commit 5deea43

Please sign in to comment.