Skip to content
Snippets Groups Projects
Commit 717c88c5 authored by Elizabeth's avatar Elizabeth
Browse files

Fixed bug in the way quantization costs were cached

parent 9636b220
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ class TableGenerator:
3. Writes the internal table to <network_name>_tensors.txt file and uses the
<network_name>_ops.txt file as a guideline in terms of row order
'''
self.__run_inputted_binaries()
#self.__run_inputted_binaries()
self.__build_internal_table()
self.__output_table_to_file()
......@@ -117,11 +117,9 @@ class TableGenerator:
approx_type = self.__get_approximation_type(results_file_name)
results_file = open(os.path.join(self.__results_dir_path, results_file_name), "r")
for line in results_file:
line = line.strip()
op_name, total_time, total_energy = self.__parse_tensor_operation_line(line)
# If the current operation is f2h or h2f
if any(op_name.endswith(prec_conv) for prec_conv in TableGenerator.precision_conversions):
# Get the original operation name (without the f2h/h2f) and the conversion type
......@@ -132,8 +130,9 @@ class TableGenerator:
exit(1)
# Store f2h and h2f as columns in the row belonging to the original operation
self.__table[orig_op_name][conversion_type][TableGenerator.__time_col_name] = total_time
self.__table[orig_op_name][conversion_type][TableGenerator.__energy_col_name] = total_energy
approx_type_no_fp_prefix = approx_type[5 : ]
self.__table[orig_op_name][conversion_type + "_" + approx_type_no_fp_prefix][TableGenerator.__time_col_name] = total_time
self.__table[orig_op_name][conversion_type + "_" + approx_type_no_fp_prefix][TableGenerator.__energy_col_name] = total_energy
# Create a new row in the dictionary
else:
......@@ -152,8 +151,6 @@ class TableGenerator:
time and the energy
'''
table_file_path = os.path.join(self.__results_dir_path, self.__table_filename)
print("FILE PATH: ", table_file_path)
soc_operations_file = open(self.__soc_ops_filename, "r")
table_file = open(table_file_path, "w")
......@@ -173,7 +170,6 @@ class TableGenerator:
# or everything breaks bc the header is per layer, not per operation
header = [TableGenerator.__table_header_delimter, layer_name, str(num_ops)]
found_h2f = found_f2h = False
# Iterate through all operations within the layer
for op_in_layer_count in range(num_ops):
# Contains the operation name
......@@ -182,45 +178,29 @@ class TableGenerator:
# Stores a list of elements that will be joined to make up a row
curr_op = [curr_line]
operation_data = self.__table[curr_line]
# Iterate through time/energy data for each approximation type corresponding
# to the current operation
found_h2f_op = found_f2h_op = False
for approx_type in operation_data:
if approx_type == "f2h":
found_f2h = found_f2h_op = True
if approx_type == "h2f":
found_h2f = found_h2f_op = True
if approx_type == "f2h" or approx_type == "h2f": print(curr_op, "approx type", approx_type)
op_time = operation_data[approx_type][TableGenerator.__time_col_name]
op_energy = operation_data[approx_type][TableGenerator.__energy_col_name]
# self.__table[op_name][approx_type][TableGenerator.__energy_col_name] = total_energy
if approx_type == "f2h" or approx_type == "h2f": print(curr_op, op_time, op_energy, op_in_layer_count)
curr_op.append(op_time)
curr_op.append(op_energy)
if op_in_layer_count == 0:
if approx_type == "f2h" or approx_type == "h2f":
print("found approx type!")
header.append("%s_time" % approx_type)
header.append("%s_energy" % approx_type)
'''if not found_h2f_op and found_h2f:
curr_op.append(0)
curr_op.append(0)
if not found_f2h_op and found_f2h:
curr_op.append(0)
curr_op.append(0)'''
if approx_type == "fp32_perf20":
header.append("fp32_time")
header.append("fp32_energy")
elif approx_type == "fp16_perf20":
header.append("fp16_time")
header.append("fp16_energy")
elif approx_type.find("f2h_perf20") != -1:
header.append("f2h_time")
header.append("f2h_energy")
else:
header.append("%s_time" % approx_type)
header.append("%s_energy" % approx_type)
ops_in_layer.append(' '.join(curr_op))
# Getting all operation rows and then writing everything because
# calls to write() are slow (memory vs time tradeoff)
'''if found_h2f:
header.append("h2f_time")
header.append("h2f_energy")
if found_f2h:
header.append("f2h_time")
header.append("f2h_energy")'''
table_file.write("%s\n%s\n" % (' '.join(header), '\n'.join(ops_in_layer)))
curr_line = soc_operations_file.readline().strip()
......@@ -250,8 +230,7 @@ class TableGenerator:
Returns:
the approximation technique (ex: fp16)
'''
approx_type_start_ind = results_filename.find(self.__network_name) \
+ len(self.__network_name) + 1 # + 1 to account for _ delimiter
approx_type_start_ind = results_filename.find("_", results_filename.find("_") + 1) + 1
approx_type_end_ind = results_filename.find(".txt")
return results_filename[approx_type_start_ind : approx_type_end_ind]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment