Skip to content
Snippets Groups Projects

Merge NMED functionality.

Closed Syed Aman Rashid - (sar215) requested to merge NMED into nam
380+ files
+ 49966
9
Compare changes
  • Side-by-side
  • Inline
Files
380+
@@ -2,6 +2,14 @@ import gzip
import sys
import numpy as np
SVERILOG_BATCH_COUNT = 100
SVERILOG_BATCH_SIZE = 1
ROOT_DIR = "../results/"
SVERILOG_FIRST_LAYER = 0
SVERILOG_SECOND_LAYER = 1
SVERILOG_FINAL_LAYER = 2
MAX_VALUE = 16129 # 127 * 127
VERSION = sys.argv[1]
def twoscomp_to_decimal(inarray, bits_in_word):
inputs = []
@@ -13,7 +21,6 @@ def twoscomp_to_decimal(inarray, bits_in_word):
inputs = np.array(inputs)
return inputs
test_y = None
with open("../data/t10k-labels-idx1-ubyte.gz", "rb") as f:
data = f.read()
@@ -21,14 +28,6 @@ with open("../data/t10k-labels-idx1-ubyte.gz", "rb") as f:
test_y = test_y[8:]
# print(sys.argv)
SVERILOG_BATCH_COUNT = 100
SVERILOG_BATCH_SIZE = 1
ROOT_DIR = "../results/"
SVERILOG_FINAL_LAYER = 2
VERSION = sys.argv[1]
acc = 0
for i in range(0, SVERILOG_BATCH_COUNT):
predictions_bin = []
@@ -44,3 +43,61 @@ for i in range(0, SVERILOG_BATCH_COUNT):
acc += 1
print("Acc: ", acc * 100 / SVERILOG_BATCH_COUNT)
"""
Calculate the Normalized Mean Error Distance (NMED) for the layers provided.
Args:
layer: Specify the layer number for 3x3 Convolutional layers of DNN
Returns:
Normalied Mean Error Distance (nmed)
"""
def calculate_nmed_layer(layer):
count = 0
EMAC = 0
NMED = 0
for i in range(0, SVERILOG_BATCH_COUNT):
VERSION = "exact"
predictions_bin = []
with open(
ROOT_DIR
+ "mult{}_{}in_layer{}_out.txt".format(VERSION, i, layer)
) as pfile:
predictions_bin = pfile.readlines()
predictions_exact = twoscomp_to_decimal(predictions_bin, 8)
VERSION = "approx_lastlayer"
predictions_bin2 = []
with open(
ROOT_DIR
+ "mult{}_{}in_layer{}_out.txt".format(VERSION, i, layer)
) as pfile:
predictions_bin2 = pfile.readlines()
predictions_approx = twoscomp_to_decimal(predictions_bin2, 8)
for i in range(0, len(predictions_exact)):
EMAC += abs(predictions_approx[i] - predictions_exact[i])
count += 1
mean_abs_difference = (EMAC / count)
#print("MAD: ", mean_abs_difference)
NMED = mean_abs_difference / (MAX_VALUE)
return NMED
# Calculate and print NMED of each layer.
if VERSION != "approx_lastlayer":
nmed1 = calculate_nmed_layer(0)
nmed2 = calculate_nmed_layer(1)
nmed3 = calculate_nmed_layer(2)
print("NMED Layer 1: ", nmed1)
print("NMED Layer 2: ", nmed2)
print("NMED Layer 3: ", nmed3)
elif VERSION == "approx_lastlayer":
nmed3 = calculate_nmed_layer(2)
print("NMED Last Layer: ", nmed3)
else:
print("Error - Please input correct arg[1] to calculate NMED")
Loading