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

Implemented functionality to run binaries and started table generation

parent 5febbf3a
No related branches found
No related tags found
No related merge requests found
import collections
import glob
import os
import subprocess
import shutil
class TableGenerator:
def __init__(self, dir_name, iters, profiler_binary_name):
self.__dir_name = dir_name
self.__network_name = dir_name
self.__iters = iters
self.__profiler_binary_name = profiler_binary_name
def __is_binary(self, file_path):
# Binary name must start with the network name as per our naming standards
return os.path.isfile(file_path) and os.access(file_path, os.X_OK) and \
file_path.find(self.__network_name) != -1
def run_binaries_in_input_dir(self):
if not os.path.isdir(self.__dir_name):
print("ERROR: Directory %s not found" % self.__dir_name)
exit(1)
self.__results_dir_name = "%s_results" % self.__dir_name
try:
os.mkdir(self.__results_dir_name)
except OSError:
if os.path.isdir(self.__results_dir_name):
print("Directory already exists. Clearing directory.")
for old_file in glob.glob(os.path.join(self.__results_dir_name, "*")):
os.remove(old_file)
else:
print("ERROR: Directory doesn't exist but failed to create dir")
for binary_name in os.listdir(self.__dir_name):
binary_path = os.path.join(self.__dir_name, binary_name)
if not self.__is_binary(binary_path):
continue
if not os.path.isfile(binary_path):
print("ERROR: Binary %s not found" % binary_path)
exit(1)
output_file = os.path.join(self.__results_dir_name, binary_name + ".txt")
# No stdout/stderr piping needed for now
subprocess.Popen([profiler_binary_name, binary_path, str(self.__iters), \
output_file]).communicate()
def __get_approximation_type(self, results_filename):
approx_type_start_ind = results_file.find(self.__network_name) \
+ len(self.__network_name) + 1 # + 1 to account for _ delimiter
approx_type_end_ind = results_file.find(".txt")
return results_filename[approx_type_start_ind : approx_type_end_ind]
def generate_table(self):
# Copy ops file to results directory to use as empty table
table_filename = os.path.join(self.__results_dir_name, \
"%s_tensors.txt" % self.__network_name)
# TODO un hard code this
soc_operations_file_name = os.path.join("/home/nvidia/soc_simulator", \
"%s_cifar10" % self.__network_name)
shutil.copyfile(soc_operations_file_name, table_filename)
# Local table --> avoid setting any global variables in case this class is
# reused multiple times
table = defaultdict(defaultdict(str))
for results_file_name in os.listdir(self.__results_dir_name):
# Ignore if not a results file
if not results_file_name.startswith(self.__network_name):
continue
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")
for line in results_file:
print(line)
results_file.close()
# For each output file --> parse and get the storage files
# For each line --> store the time and energy
# <operation name> <type of approx> <time> <energy>
# Need to map to soc_operations file
# final file should be in the format of the soc_operations file
binary_dir_name = "/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_pldi/mobilenet"
num_iters = 1
profiler_binary_name = "/home/nvidia/awesome_profiler/pp"
table_gen = TableGenerator(binary_dir_name, num_iters, profiler_binary_name)
table_gen.run_binaries_in_input_dir()
table_gen.generate_tables()
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