From e40760d5af575109cc7d102bbcd9895df43db153 Mon Sep 17 00:00:00 2001 From: Elizabeth <hashim.sharif91@gmail.com> Date: Wed, 9 Oct 2019 01:26:38 -0500 Subject: [PATCH] Fixed popen bug when running promise timing model --- llvm/projects/soc_simulator/src/driver.py | 76 ++++++++++------------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/llvm/projects/soc_simulator/src/driver.py b/llvm/projects/soc_simulator/src/driver.py index b56f60ac68..50f80ba15d 100644 --- a/llvm/projects/soc_simulator/src/driver.py +++ b/llvm/projects/soc_simulator/src/driver.py @@ -35,21 +35,21 @@ def parse_tensor_layer_file(layer_filename): tensor_layer["Name"] = layer_name if is_conv(layer_name): - tensor_layer["N"] = layer_data[1] - tensor_layer["Cin"] = layer_data[2] - tensor_layer["H"] = layer_data[3] - tensor_layer["W"] = layer_data[4] - tensor_layer["Cout"] = layer_data[5] - tensor_layer["Kh"] = layer_data[6] - tensor_layer["Kw"] = layer_data[7] - tensor_layer["Sh"] = layer_data[8] - tensor_layer["Sw"] = layer_data[9] + tensor_layer["N"] = int(layer_data[1]) + tensor_layer["Cin"] = int(layer_data[2]) + tensor_layer["H"] = int(layer_data[3]) + tensor_layer["W"] = int(layer_data[4]) + tensor_layer["Cout"] = int(layer_data[5]) + tensor_layer["Kh"] = int(layer_data[6]) + tensor_layer["Kw"] = int(layer_data[7]) + tensor_layer["Sh"] = int(layer_data[8]) + tensor_layer["Sw"] = int(layer_data[9]) elif is_fc(layer_name): - tensor_layer["RA"] = layer_data[1] - tensor_layer["CA"] = layer_data[2] - tensor_layer["RB"] = layer_data[3] - tensor_layer["CB"] = layer_data[4] + tensor_layer["RA"] = int(layer_data[1]) + tensor_layer["CA"] = int(layer_data[2]) + tensor_layer["RB"] = int(layer_data[3]) + tensor_layer["CB"] = int(layer_data[4]) elif not is_nml(layer_name): # TODO should we store data for NMLs? print("ERROR: Invalid layer name %s" % layer_name) @@ -113,7 +113,7 @@ class ApproxTypes: def is_promise(config_layer): # TODO overhead in call to split? - return config_layer.split(' ')[0] < fp16_swing + return int(config_layer.split(' ')[0]) < fp16_swing # NOTE smart_dma is always true def quantize(curr_layer, prev_layer, h2f_f2h_operation_ind, layer_data): @@ -167,17 +167,20 @@ def run_promise_simulation(swing, layer_data): exit(1) # Run promise simulator - # TODO need to print time and energy so we can pipe it - # get output --> total time and energy - ptm_process = subprocess.Popen(["./ptm", str(rows_a), str(cols_a), str(rows_b), \ - str(cols_b), str(patch_factor), str(swing)]) - output, _ = ptm_process.communicate() - total_time_energy = output.strip().split(' ') + # TODO need to print time and energy in the ptm runner so we can pipe it + output = subprocess.Popen(["./ptm", str(rows_a), str(cols_a), str(rows_b), \ + str(cols_b), str(patch_factor), str(swing)], \ + stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()[0] + total_time_energy = output.strip().split(',') - assert(len(total_time_energy) == 2) - return total_time_energy[0], total_time_energy[1] + assert(len(total_time_energy) == 2) + return total_time_energy[0], total_time_energy[1] +# Default dict of default dicts +# [Time/Energy][number corresponding to order the layer config was read in] = time/energy +aggregate_results = defaultdict(lambda: defaultdict(float)) + def run_simulations(config_filename, results_filename): config_file = open(config_filename, "r") results_file = open(results_filename, "w") @@ -186,41 +189,27 @@ def run_simulations(config_filename, results_filename): # layers are separated by commas # tensor ops are separated by spaces - for config in config_file: + for config_ind, config in enumerate(config_file): config_layers = config.strip().split(',') prev_layer = ApproxTypes.FP32 curr_layer = None - + for layer_ind, config_layer in enumerate(config_layers): # level layer_data = tensor_layers[layer_ind] # layer - if is_promise(config_layer): + print("IS PROMISE") print("Running layer %s on PROMISE" % layer_data["Name"]) curr_layer = ApproxTypes.PROMISE quant_time, quant_energy = quantize(curr_layer, prev_layer, 0, layer_data) # Compute + time, energy = run_promise_simulation(config_layer, layer_data) + aggregate_results["Time"][config_ind] = time + aggregate_results["Energy"][config_ind] = energy else: + print("Not promise") pass - # for each config file line --> parse the comma separated voltage swing levels - # recall: each line = a configuration that works - # for each level - # if promise --> promise runs an entire layer - # quantize, no patching and unpatching - # run on promise - # output the total time and energy - # else - # for each sublevel (separated by spaces) - # quantize - # run - # keep track of total time and energy --> update as needed - # output the total time and energy - -# quantization: we always have smart dma -# need to search stuff up -# $layer = a map of elements -# stores the layer name, then if __name__ == "__main__": ''' @@ -230,3 +219,4 @@ if __name__ == "__main__": ''' parse_tensor_layer_file("/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_mobilenet/mobilenet_layers.txt") parse_tensor_table("/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_pldi/mobilenet_results/mobilenet_tensors.txt") + run_simulations("/home/nvidia/Gitlab/hpvm/llvm/projects/soc_simulator/pipeline_GEMO/pipeline_GEMO_promise_confs1.txt", "blah") -- GitLab