Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os, sys
commit_id = 'e1d8efd8e5469cf865a9db60007a70e3f0cb8778'
dst_path = "cost_model/maestro"
maestro_dir = "../maestro"
maestro_dir = "../qmaestro"
working_path = os.getcwd()
dst_path = os.path.join(working_path, dst_path)
maestro = os.path.join(maestro_dir, "maestro")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import numpy as np
mapping_cstr = {}
mapping_cstr["L3"] = {"R":"R",
"S":"S",
}
mapping_cstr["L2"] = {"R":"R",
"S":"S",
}
Expand Down
28 changes: 14 additions & 14 deletions data/model/vgg16.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
K,C,Y,X,R,S,T
64,3,224,224,3,3,1
64,64,224,224,3,3,1
128,64,112,112,3,3,1
128,128,112,112,3,3,1
256,128,56,56,3,3,1
256,256,56,56,3,3,1
256,256,56,56,3,3,1
512,256,28,28,3,3,1
512,512,28,28,3,3,1
512,512,28,28,3,3,1
512,512,14,14,3,3,1
512,512,14,14,3,3,1
512,512,14,14,3,3,1
K,C,Y,X,R,S,T,Precision
64,3,224,224,3,3,1,FP16
64,64,224,224,3,3,1,FP16
128,64,112,112,3,3,1,FP16
128,128,112,112,3,3,1,FP16
256,128,56,56,3,3,1,FP16
256,256,56,56,3,3,1,FP16
256,256,56,56,3,3,1,FP16
512,256,28,28,3,3,1,FP16
512,512,28,28,3,3,1,FP16
512,512,28,28,3,3,1,FP16
512,512,14,14,3,3,1,FP16
512,512,14,14,3,3,1,FP16
512,512,14,14,3,3,1,FP16
61 changes: 61 additions & 0 deletions extract_dataflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import argparse

def extract_sections(file_name, output_folder, output_file_name=None):
# Read the content of the original file
with open(file_name, 'r') as f:
content = f.read()

# Initialize sections
precision_section = ""
dataflow_section = ""

# Find the Precision section, if it exists
precision_start_index = content.find("Precision:")
if precision_start_index != -1:
precision_end_index = content.find("}", precision_start_index) + 1
precision_section = content[precision_start_index:precision_end_index]
precision_section += '\n'

# Find the Dataflow section
dataflow_start_index = content.find("Dataflow {")
if dataflow_start_index != -1:
dataflow_end_index = content.find("}", dataflow_start_index) + 1
dataflow_section = content[dataflow_start_index:dataflow_end_index]
dataflow_section += '\n'

# Indent lines in Dataflow section (excluding the first and last lines)
dataflow_lines = dataflow_section.split('\n')
indented_dataflow_lines = '\n'.join(dataflow_lines[0:1] + ['\t' + line for line in dataflow_lines[1:-1]] + dataflow_lines[-1:])
dataflow_section = indented_dataflow_lines

# Create the output folder if it doesn't exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)

# Determine the output file name
if output_file_name is None:
output_file_name = os.path.basename(file_name)
output_file_path = os.path.join(output_folder, output_file_name)

# Write the modified Precision and Dataflow sections to the new file
with open(output_file_path, 'w') as f:
if precision_section:
f.write(precision_section)
if dataflow_section:
f.write(dataflow_section)

if __name__ == "__main__":
# Create an argument parser
parser = argparse.ArgumentParser(description='Extract Precision and Dataflow from a file and save to a new file.')

# Add the file and output folder arguments
parser.add_argument('--file', type=str, required=True, help='Path of the input file')
parser.add_argument('--out', type=str, required=True, help='Path of the output folder')
parser.add_argument('--outname', type=str, help='Optional name of the output file')

# Parse the command-line arguments
args = parser.parse_args()

# Extract the Precision and Dataflow parts and save them to the output folder
extract_sections(args.file, args.out, args.outname)
49 changes: 49 additions & 0 deletions from_maestro_to_gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import csv
import re
import argparse

def parse_m_file(file_path):
layers = []
with open('../qmaestro/data/model/' + file_path, 'r') as file:
with open('../qmaestro/data/model/' + file_path, 'r') as file:
content = file.read()
layers_type = re.findall(r'Type: (\w+)', content, re.DOTALL)
dimension_matches = re.findall(r'Dimensions \{.*?\}', content, re.DOTALL)

for i, dimensions in enumerate(dimension_matches):
dim_values = re.findall(r'\b\w: \d+', dimensions)
dim_dict = {d.split(': ')[0]: int(d.split(': ')[1]) for d in dim_values}
if layers_type[i] == 'DSCONV':
dim_dict['T'] = 2
else:
dim_dict['T'] = 1
layers.append(dim_dict)
return layers

def write_csv(layers, precision, output_file):
with open('./data/model/'+ output_file, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["K", "C", "Y", "X", "R", "S", "T", "Precision"])
for layer in layers:
t_value = 2 if layer.get('Type') == 'DSCONV' else 1
writer.writerow([
layer.get('K', 0),
layer.get('C', 0),
layer.get('Y', 0),
layer.get('X', 0),
layer.get('R', 0),
layer.get('S', 0),
layer.get('T', 0),
precision
])


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Parse a .m file and generate a CSV.')
parser.add_argument('input_file', type=str, help='Path to the input .m file')
parser.add_argument('precision', type=str, help='Precision value for the CSV')
parser.add_argument('output_file', type=str, help='Path to the output CSV file')
args = parser.parse_args()

layers = parse_m_file(args.input_file)
write_csv(layers, args.precision, args.output_file)
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

12 changes: 12 additions & 0 deletions run_digamma.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cd ./src/GAMMA


python main.py --num_pe -1 --area_budget 0.2 --pe_limit 200 --model vgg16 --outdir outdir_digamma

cd ../../






2 changes: 1 addition & 1 deletion run_gamma.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd ./src/GAMMA
python main.py --fitness1 latency --fitness2 power --num_pe 168 --l1_size 512 --l2_size 108000 --NocBW 81920000 --epochs 10 \
--model vgg16 --singlelayer 1
--model vgg16 --num_layer 13 #--singlelayer 1
cd ../../


Expand Down
10 changes: 10 additions & 0 deletions run_gamma_map_cstr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cd ./src/GAMMA
python main.py --mapping_cstr dla_map --fitness1 latency --fitness2 power --num_pe 168 --l1_size 512 --l2_size 108000 --NocBW 81920000 --epochs 10 \
--model vgg16 --outdir outdir_map
cd ../../






24 changes: 24 additions & 0 deletions script/avg_exec_time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
cd ..
# Number of executions
num_executions=10
total_execution_time_ns=0

for ((i=1; i<=$num_executions; i++)); do

start_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

./run_gamma.sh

end_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

elapsed_time_ms=$((end_time - start_time))

total_execution_time_ms=$((total_execution_time_ms + elapsed_time_ms))
done


average_execution_time_ms=$((total_execution_time_ms / num_executions))

# Display the total execution time in nanoseconds
echo "Gamma -> Avg Execution Time: $average_execution_time_ms ms" >> "output.txt"
24 changes: 24 additions & 0 deletions script/avg_exec_time_digamma.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
cd ..
# Number of executions
num_executions=10
total_execution_time_ns=0

for ((i=1; i<=$num_executions; i++)); do

start_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

./run_digamma.sh

end_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

elapsed_time_ms=$((end_time - start_time))

total_execution_time_ms=$((total_execution_time_ms + elapsed_time_ms))
done


average_execution_time_ms=$((total_execution_time_ms / num_executions))

# Display the total execution time in nanoseconds
echo "DiGamma -> Avg Execution Time: $average_execution_time_ms ms" >> "output.txt"
24 changes: 24 additions & 0 deletions script/avg_exec_time_map_cstr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
cd ..
# Number of executions
num_executions=10
total_execution_time_ns=0

for ((i=1; i<=$num_executions; i++)); do

start_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

./run_gamma_map_cstr.sh

end_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

elapsed_time_ms=$((end_time - start_time))

total_execution_time_ms=$((total_execution_time_ms + elapsed_time_ms))
done


average_execution_time_ms=$((total_execution_time_ms / num_executions))

# Display the total execution time in nanoseconds
echo "Map Cstr -> Avg Execution Time: $average_execution_time_ms ms" >> "output.txt"
24 changes: 24 additions & 0 deletions script/avg_exec_time_with_hwconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
cd ..
# Number of executions
num_executions=10
total_execution_time_ns=0

for ((i=1; i<=$num_executions; i++)); do

start_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

./run_gamma_with_hwconfig.sh

end_time=$(perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)')

elapsed_time_ms=$((end_time - start_time))

total_execution_time_ms=$((total_execution_time_ms + elapsed_time_ms))
done


average_execution_time_ms=$((total_execution_time_ms / num_executions))

# Display the total execution time in nanoseconds
echo "Av Execution Time: $average_execution_time_ms ms"
12 changes: 12 additions & 0 deletions script/delete_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
folder_path="$HOME/Desktop/Tesi/gamma/src/GAMMA"

# Navigate to the folder
cd "$folder_path" || exit

# Delete .csv files
find . -type f -name "*.csv" -delete

# Delete .m files
find . -type f -name "*.m" -delete

echo "Deletion complete for .csv and .m files in $folder_path"
3 changes: 3 additions & 0 deletions script/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./avg_exec_time.sh
./avg_exec_time_map_cstr.sh
./avg_exec_time_digamma.sh
12 changes: 12 additions & 0 deletions script/run_digamma.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cd ./src/GAMMA


python main.py --num_pe -1 --area_budget 0.2 --pe_limit 200 --model vgg16 --outdir outdir_digamma

cd ../../






10 changes: 10 additions & 0 deletions script/run_gamma_map_cstr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cd ./src/GAMMA
python main.py --mapping_cstr dla_map --fitness1 latency --fitness2 power --num_pe 168 --l1_size 512 --l2_size 108000 --NocBW 81920000 --epochs 10 \
--model vgg16 --outdir outdir_map
cd ../../






Loading