Skip to content
Snippets Groups Projects
Commit 6b290187 authored by Elizabeth's avatar Elizabeth
Browse files

Debugged internal dict representation

parent 80176cd7
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ class TableGenerator: ...@@ -19,6 +19,8 @@ class TableGenerator:
self.__profiler_binary_name = profiler_binary_name self.__profiler_binary_name = profiler_binary_name
self.__results_dir_name = "%s_results" % self.__dir_name self.__results_dir_name = "%s_results" % self.__dir_name
self.__table_filename = "%s_tensors.txt" % self.__network_name
def __is_binary(self, file_path): def __is_binary(self, file_path):
# Binary name must start with the network name as per our naming standards # Binary name must start with the network name as per our naming standards
...@@ -78,6 +80,7 @@ class TableGenerator: ...@@ -78,6 +80,7 @@ class TableGenerator:
underscore_ind = op_name.find("_") underscore_ind = op_name.find("_")
return op_name[ : underscore_ind], op_name[underscore_ind + 1 : ] return op_name[ : underscore_ind], op_name[underscore_ind + 1 : ]
def generate_table(self): def generate_table(self):
self.__table = self.__build_nested_default_dict() self.__table = self.__build_nested_default_dict()
self.__build_internal_table() self.__build_internal_table()
...@@ -86,25 +89,22 @@ class TableGenerator: ...@@ -86,25 +89,22 @@ class TableGenerator:
def __build_internal_table(self): def __build_internal_table(self):
for results_file_name in os.listdir(self.__results_dir_name): for results_file_name in os.listdir(self.__results_dir_name):
print(results_file_name, self.__network_name)
# Ignore if it's not a results file # Ignore if it's not a results file
if results_file_name.startswith(self.__network_name): if results_file_name == self.__table_filename or \
not results_file_name.startswith(self.__network_name):
continue continue
approx_type = self.__get_approximation_type(results_file_name) approx_type = self.__get_approximation_type(results_file_name)
print(approx_type)
results_file = open(os.path.join(self.__results_dir_name, results_file_name), "r") results_file = open(os.path.join(self.__results_dir_name, results_file_name), "r")
for line in results_file: for line in results_file:
line = line.strip() line = line.strip()
op_name, total_time, total_energy = self.__parse_tensor_operation_line(line) op_name, total_time, total_energy = self.__parse_tensor_operation_line(line)
print(op_name, total_time, total_energy)
# Handle _f2h and _h2f output for tensor operation # Handle _f2h and _h2f output for tensor operation
# Store as columns of original operation rather than independent rows # Store as columns of original operation rather than independent rows
if any(op_name.endswith(prec_conv) for prec_conv in TableGenerator.precision_conversions): if any(op_name.endswith(prec_conv) for prec_conv in TableGenerator.precision_conversions):
orig_op_name, conversion_type = self.__get_original_operation_name(op_name) orig_op_name, conversion_type = self.__get_original_operation_name(op_name)
print("f2h/h2f", orig_op_name, conversion_type)
# Error bc original op name should ALWAYS be in the table # Error bc original op name should ALWAYS be in the table
if orig_op_name not in self.__table: if orig_op_name not in self.__table:
print("ERROR: Conversion found but original %s is not in the table" % orig_op_name) print("ERROR: Conversion found but original %s is not in the table" % orig_op_name)
...@@ -120,15 +120,13 @@ class TableGenerator: ...@@ -120,15 +120,13 @@ class TableGenerator:
results_file.close() results_file.close()
def __output_table(self): def __output_table(self):
# Copy ops file to results directory to use as empty table table_file_path = os.path.join(self.__results_dir_name, self.__table_filename)
table_filename = "%s_tensors.txt" % self.__network_name
table_file_path = os.path.join(self.__results_dir_name, table_filename)
# TODO un hard code this # TODO un hard code this
soc_operations_file_name = os.path.join("/home/nvidia/soc_simulator", "%s_cifar10" % self.__network_name, "%s_ops.txt" % self.__network_name) soc_operations_file_name = os.path.join("/home/nvidia/soc_simulator", "%s_cifar10" % self.__network_name, "%s_ops.txt" % self.__network_name)
# Don't need to copy the file over --> can use the original file as a reference # Don't need to copy the file over --> can use the original file as a reference
soc_operations_file = open(soc_operations_file_name, "r") soc_operations_file = open(soc_operations_file_name, "r")
table_file = open(table_filename, "w") table_file = open(self.__table_filename, "w")
# Read header line to get layer name and # operations in layer # Read header line to get layer name and # operations in layer
# Get ops in each layer using the dict # Get ops in each layer using the dict
...@@ -141,17 +139,18 @@ class TableGenerator: ...@@ -141,17 +139,18 @@ class TableGenerator:
while curr_line: while curr_line:
# First line is always the layers line (#layer_name,num_ops) # First line is always the layers line (#layer_name,num_ops)
layer_name, num_ops = self.__parse_layer_info_line(curr_line) layer_name, num_ops = self.__parse_layer_info_line(curr_line)
print("FIRST LINE", layer_name, num_ops)
# Get each operation in the layer # Get each operation in the layer
ops_in_layer = [] ops_in_layer = []
header = [] header = ["**", layer_name, str(num_ops), "_"]
for op_in_layer_count in range(num_ops): for op_in_layer_count in range(num_ops):
# Each line consists of operation name # Each line consists of operation name
curr_line = soc_operations_file.readline().strip() curr_line = soc_operations_file.readline().strip()
curr_op = [curr_line] # Join into a string later curr_op = [curr_line] # Join into a string later
operation_data = self.__table[curr_line] operation_data = self.__table[curr_line]
# Iterate through time/energy data for each approx type # Iterate through time/energy data for each approx type
for approx_type in operation_data: for approx_type in operation_data:
curr_op.append(operation_data[approx_type]["time"]) curr_op.append(operation_data[approx_type]["time"])
...@@ -161,12 +160,12 @@ class TableGenerator: ...@@ -161,12 +160,12 @@ class TableGenerator:
# Only fill out the header once for the layer # Only fill out the header once for the layer
if op_in_layer_count == 0: if op_in_layer_count == 0:
header.append(approx_type) header.append(approx_type)
ops_in_layer.append(' '.join(curr_op)) ops_in_layer.append(' '.join(curr_op))
# Getting all operation rows and then writing everything because # Getting all operation rows and then writing everything because
# calls to write() are slow (memory vs time tradeoff) # calls to write() are slow (memory vs time tradeoff)
print("%s" % ' '.join(header)) #print("%s" % ' '.join(header))
print("%s" % '\n'.join(ops_in_layer)) #print("%s" % '\n'.join(ops_in_layer))
table_file.write("%s\n" % ' '.join(header)) table_file.write("%s\n" % ' '.join(header))
table_file.write("%s\n" % '\n'.join(ops_in_layer)) table_file.write("%s\n" % '\n'.join(ops_in_layer))
...@@ -174,7 +173,8 @@ class TableGenerator: ...@@ -174,7 +173,8 @@ class TableGenerator:
def __parse_layer_info_line(self, layer_info_line): #layer_name,num_ops def __parse_layer_info_line(self, layer_info_line): #layer_name,num_ops
comma_ind = layer_info_line.find(",") comma_ind = layer_info_line.find(",")
return layer_info_line[layer_info_line.find("#") : comma_ind], int(layer_info_line[comma_ind + 1 : ]) return layer_info_line[layer_info_line.find("#") + 1 : comma_ind], \
int(layer_info_line[comma_ind + 1 : ])
def __generate_header(self, table): def __generate_header(self, table):
# <approx type time/energy> <conversion type at very end> # <approx type time/energy> <conversion type at very end>
......
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