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 0000000000000000000000000000000000000000..3505e04a1de22de3535dee14e736d2638fb316ab --- /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() + +