From d1ed8f703f7378338ba49509a79efc756340d7e9 Mon Sep 17 00:00:00 2001 From: Samidh Mehta Date: Wed, 28 Feb 2024 17:01:51 -0800 Subject: [PATCH 1/3] 1. Adding floating point capabilities to reduce block. 2. Fix for generate matrix BF16 compressed mode --- sam/onyx/generate_matrices.py | 9 ++++++--- sam/onyx/hw_nodes/reduce_node.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sam/onyx/generate_matrices.py b/sam/onyx/generate_matrices.py index 83c7443f..d8eb0532 100644 --- a/sam/onyx/generate_matrices.py +++ b/sam/onyx/generate_matrices.py @@ -195,10 +195,13 @@ def dump_outputs(self, format=None, tpose=False, dump_shape=True, flat_array.append(val) if glb_override: lines = [len(flat_array), *flat_array] - self.write_array(lines, name=f"tensor_{self.name}_mode_vals{suffix}", dump_dir=use_dir, dump_hex=print_hex) + self.write_array(lines, name=f"tensor_{self.name}_mode_vals{suffix}", + dump_dir=use_dir, dump_hex=print_hex, is_val=True) else: - self.write_array(flat_array, name=f"tensor_{self.name}_mode_vals{suffix}", dump_dir=use_dir, - dump_hex=print_hex) + self.write_array(flat_array, name=f"tensor_{self.name}_mode_vals{suffix}", + dump_dir=use_dir, dump_hex=print_hex, is_val=True) + + elif self.format == "COO": crd_dict = dict() order = len(self.array.shape) diff --git a/sam/onyx/hw_nodes/reduce_node.py b/sam/onyx/hw_nodes/reduce_node.py index 0700373e..96edda0e 100644 --- a/sam/onyx/hw_nodes/reduce_node.py +++ b/sam/onyx/hw_nodes/reduce_node.py @@ -112,7 +112,16 @@ def configure(self, attributes): # TODO: make this use the metamapper instr_type = strip_modifiers(lassen_fc.Py.input_t.field_dict['inst']) asm_ = Assembler(instr_type) - op = int(asm_.assemble(asm.add())) + + if 'fp' in attributes: + is_fp = attributes['fp'].strip('"') + if (is_fp == 'true'): + op = int(asm_.assemble(asm.fp_add())) + else: + op = int(asm_.assemble(asm.add())) + else: + op = int(asm_.assemble(asm.add())) + cfg_kwargs = { 'stop_lvl': stop_lvl, 'pe_connected_to_reduce': pe_connected_to_reduce, From ba9284d25aa543dc677fa593760452fd0b6e5fd8 Mon Sep 17 00:00:00 2001 From: Samidh Mehta Date: Wed, 28 Feb 2024 17:10:01 -0800 Subject: [PATCH 2/3] Adding spmm_ijk_crddrop_fp graph (Dense Matrix-Sparse Matrix matmul floating point) --- .../onyx-dot/spmm_ijk_crddrop_fp.gv | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 compiler/sam-outputs/onyx-dot/spmm_ijk_crddrop_fp.gv diff --git a/compiler/sam-outputs/onyx-dot/spmm_ijk_crddrop_fp.gv b/compiler/sam-outputs/onyx-dot/spmm_ijk_crddrop_fp.gv new file mode 100644 index 00000000..bbaae0b6 --- /dev/null +++ b/compiler/sam-outputs/onyx-dot/spmm_ijk_crddrop_fp.gv @@ -0,0 +1,55 @@ +digraph SAM { + comment="X=ss01,B=dd01,C=ss10" + 17 [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"] + 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=dense,src=true,root=false" label="FiberLookup k: B1\ndense" color=green4 shape=box style=filled type="fiberlookup" index="k" tensor="B" mode="1" format="dense" 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=fp_mul" label="FP_Mul" color=brown shape=box style=filled type="fp_mul"] + 3 [comment="type=reduce" label="Reduce" color=brown shape=box style=filled type="reduce", fp="true"] + 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"] + + 17 -> 16 [label="crd" style=dashed type="crd" comment=""] + # 16 -> 2 [label="crd" style=dashed type="crd"] + 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 -> 1 [label="crd" style=dashed type="crd"] + 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"] + # 4 -> 3 [label="val" type="val"] + 3 -> 0 [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"] + 18 -> 1 [label="crd_inner-j" style=dashed type="crd" comment="inner-j"] + 19 -> 3 [label="val_inner-k" type="val" comment="inner-k"] + + 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"] + 18 -> 2 [label="crd_outer-i" style=dashed type="crd" comment="outer-i"] +} From cbd63fcf584ed0d58e90f62c83f3e5247deb2c7d Mon Sep 17 00:00:00 2001 From: Samidh Mehta Date: Fri, 1 Mar 2024 15:58:12 -0800 Subject: [PATCH 3/3] formatting changes --- sam/onyx/generate_matrices.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sam/onyx/generate_matrices.py b/sam/onyx/generate_matrices.py index d8eb0532..0a3e4338 100644 --- a/sam/onyx/generate_matrices.py +++ b/sam/onyx/generate_matrices.py @@ -195,13 +195,11 @@ def dump_outputs(self, format=None, tpose=False, dump_shape=True, flat_array.append(val) if glb_override: lines = [len(flat_array), *flat_array] - self.write_array(lines, name=f"tensor_{self.name}_mode_vals{suffix}", + self.write_array(lines, name=f"tensor_{self.name}_mode_vals{suffix}", dump_dir=use_dir, dump_hex=print_hex, is_val=True) else: - self.write_array(flat_array, name=f"tensor_{self.name}_mode_vals{suffix}", + self.write_array(flat_array, name=f"tensor_{self.name}_mode_vals{suffix}", dump_dir=use_dir, dump_hex=print_hex, is_val=True) - - elif self.format == "COO": crd_dict = dict() order = len(self.array.shape)