From c1da2dae4a757c6548a257ae8c548c57b8ab184c Mon Sep 17 00:00:00 2001
From: root <kalhankoul96@gmail.com>
Date: Thu, 16 May 2024 12:29:14 -0700
Subject: [PATCH 1/3] allow empty line in output sim

---
 sam/onyx/generate_matrices.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sam/onyx/generate_matrices.py b/sam/onyx/generate_matrices.py
index 9cd07b79..4469a204 100644
--- a/sam/onyx/generate_matrices.py
+++ b/sam/onyx/generate_matrices.py
@@ -513,6 +513,8 @@ def convert_aha_glb_output_file(glbfile, output_dir, tiles):
             sp_line = line.strip().split(" ")
             for sp_line_tok in sp_line:
                 sp_line_tok_stripped = sp_line_tok.strip()
+                if(sp_line_tok_stripped == ""):
+                    continue
                 straightline.append(int(sp_line_tok_stripped, base=16))
 
     # Now we have straightline having the items in order

From adf6e262cc894848654449408a7e5bcdf60bd7de Mon Sep 17 00:00:00 2001
From: root <kalhankoul96@gmail.com>
Date: Fri, 17 May 2024 15:53:51 -0700
Subject: [PATCH 2/3] support for back2back aha test with sparse tile
 pipelining

---
 sam/onyx/generate_matrices.py | 45 ++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/sam/onyx/generate_matrices.py b/sam/onyx/generate_matrices.py
index 4469a204..43734eb0 100644
--- a/sam/onyx/generate_matrices.py
+++ b/sam/onyx/generate_matrices.py
@@ -489,20 +489,22 @@ def create_matrix_from_point_list(name, pt_list, shape, use_fp=False) -> MatrixG
     return mg
 
 
-def convert_aha_glb_output_file(glbfile, output_dir, tiles):
+def convert_aha_glb_output_file(glbfile, output_dir, tiles, batches):
 
     glbfile_s = os.path.basename(glbfile).rstrip(".txt")
 
     files = []
     if 'mode_vals' in glbfile:
         # num_blocks = 1
-        for i in range(tiles):
-            files.append(f"{output_dir}/{glbfile_s}_tile{i}")
+        for j in range(batches):
+            for i in range(tiles):
+                files.append(f"{output_dir}/{glbfile_s}_batch{j}_tile{i}")
     else:
         # num_blocks = 2
-        for i in range(tiles):
-            files.append(f"{output_dir}/{glbfile_s}_seg_tile{i}")
-            files.append(f"{output_dir}/{glbfile_s}_crd_tile{i}")
+        for j in range(batches):
+            for i in range(tiles):
+                files.append(f"{output_dir}/{glbfile_s}_seg_batch{j}_tile{i}")
+                files.append(f"{output_dir}/{glbfile_s}_crd_batch{j}_tile{i}")
 
     straightline = []
 
@@ -517,17 +519,42 @@ def convert_aha_glb_output_file(glbfile, output_dir, tiles):
                     continue
                 straightline.append(int(sp_line_tok_stripped, base=16))
 
+
     # Now we have straightline having the items in order
     # Now write them to the output
+ 
+    
+    if 'mode_vals' in glbfile:
+        num_blocks = 1
+    else:
+        num_blocks = 2
+
     sl_ptr = 0
+    tile = 0
+    batch = 0
+    block = 0
     for file_path in files:
         num_items = straightline[sl_ptr]
         sl_ptr += 1
         with open(file_path, "w+") as fh_:
-            for _ in range(num_items):
+            # Edge case, write out 0 is this correct?
+            if num_items == 0:
                 fh_.write(f"{straightline[sl_ptr]:04X}\n")
-                sl_ptr += 1
-
+            else:
+                for _ in range(num_items):
+                    fh_.write(f"{straightline[sl_ptr]:04X}\n")
+                    sl_ptr += 1
+        block += 1
+        if block == num_blocks:
+            block = 0
+            tile += 1
+        if tile == tiles:
+            tile = 0
+            batch = batch + 1
+            #TODO hardcoded value for now
+            sl_ptr = 32768*batch # size of glb
+
+     
 
 def find_file_based_on_sub_string(files_dir, sub_string_list):
     """Return the file name in a directory, if the file name

From 084edae4ae9fadf31b977e077f225ece515297ca Mon Sep 17 00:00:00 2001
From: root <kalhankoul96@gmail.com>
Date: Fri, 17 May 2024 16:29:59 -0700
Subject: [PATCH 3/3] lint fixes

---
 sam/onyx/generate_matrices.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/sam/onyx/generate_matrices.py b/sam/onyx/generate_matrices.py
index 43734eb0..5fdeaa27 100644
--- a/sam/onyx/generate_matrices.py
+++ b/sam/onyx/generate_matrices.py
@@ -515,15 +515,13 @@ def convert_aha_glb_output_file(glbfile, output_dir, tiles, batches):
             sp_line = line.strip().split(" ")
             for sp_line_tok in sp_line:
                 sp_line_tok_stripped = sp_line_tok.strip()
-                if(sp_line_tok_stripped == ""):
+                if (sp_line_tok_stripped == ""):
                     continue
                 straightline.append(int(sp_line_tok_stripped, base=16))
 
-
     # Now we have straightline having the items in order
     # Now write them to the output
- 
-    
+
     if 'mode_vals' in glbfile:
         num_blocks = 1
     else:
@@ -551,10 +549,9 @@ def convert_aha_glb_output_file(glbfile, output_dir, tiles, batches):
         if tile == tiles:
             tile = 0
             batch = batch + 1
-            #TODO hardcoded value for now
-            sl_ptr = 32768*batch # size of glb
+            # TODO hardcoded value for now
+            sl_ptr = 32768 * batch  # size of glb
 
-     
 
 def find_file_based_on_sub_string(files_dir, sub_string_list):
     """Return the file name in a directory, if the file name