From 48b6299618d1eb63cc9d813bae0f16eb1e0a0574 Mon Sep 17 00:00:00 2001
From: Hashim Sharif <hsharif3@miranda.cs.illinois.edu>
Date: Fri, 2 Jul 2021 04:40:03 -0500
Subject: [PATCH] Adding weight manipulation scripts (FP16 + Transpose)

---
 .../scripts/transpose_dense.py                | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/transpose_dense.py

diff --git a/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/transpose_dense.py b/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/transpose_dense.py
new file mode 100644
index 0000000000..3505e04a1d
--- /dev/null
+++ b/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/transpose_dense.py
@@ -0,0 +1,47 @@
+
+import numpy as np
+import os
+import sys
+
+
+if __name__ == "__main__":
+
+    weights_dir = sys.argv[1]
+    list_dir = os.listdir(weights_dir)
+    print (list_dir)
+
+    for file_name in list_dir:
+        if "_b" not in file_name and "dense" in file_name and "fp16" in file_name:
+            print ("name = ", file_name)
+            f_path = weights_dir + "/" + file_name
+
+            x = np.fromfile(f_path, dtype='float16')
+            x_reshaped = np.reshape(x, (10, 4096))
+            x_transposed = np.transpose(x_reshaped, (1, 0))
+
+            print (x_reshaped)
+            
+            print ("x_trans = ", x_transposed)
+            
+            x_flat = x_transposed.flatten()
+            x_fp16 = x_flat.astype(np.float16)
+
+            outfile = open("transpose.bin", "w+")
+            x_fp16.tofile(outfile)
+
+            outfile.close()
+
+            # Double transpose to check corectness
+            x_double_transposed = np.transpose(x_transposed, (1, 0))
+
+            print ("double_tranposed = ", x_double_transposed)
+            
+            x2_flat = x_double_transposed.flatten()
+            x2_fp16 = x2_flat.astype(np.float16)
+
+            outfile = open("double_transpose.bin", "w+")
+            x2_fp16.tofile(outfile)
+
+            outfile.close()
+
+            
-- 
GitLab