Skip to content

Commit

Permalink
update lab3 to new formats
Browse files Browse the repository at this point in the history
  • Loading branch information
asyms committed Nov 18, 2024
1 parent e5c4af6 commit 9d8be99
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 39 deletions.
7 changes: 3 additions & 4 deletions lab3/inputs/hardware/accelerator1.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: accelerator1

multipliers:
input_precision: [8, 8]
multiplier_energy: 1 # pJ
multiplier_area: 1 # unit
operational_array:
unit_energy: 0.04 # pJ
unit_area: 1 # unit
dimensions: [D1, D2]
sizes: [32, 32]

Expand Down
7 changes: 3 additions & 4 deletions lab3/inputs/hardware/accelerator2.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: accelerator2

multipliers:
input_precision: [8, 8]
multiplier_energy: 1 # pJ
multiplier_area: 1 # unit
operational_array:
unit_energy: 0.04 # pJ
unit_area: 1 # unit
dimensions: [D1, D2]
sizes: [32, 32]

Expand Down
7 changes: 3 additions & 4 deletions lab3/inputs/hardware/accelerator3.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: accelerator3

multipliers:
input_precision: [8, 8]
multiplier_energy: 1 # pJ
multiplier_area: 1 # unit
operational_array:
unit_energy: 0.04 # pJ
unit_area: 1 # unit
dimensions: [D1, D2, D3]
sizes: [64, 4, 4]

Expand Down
1 change: 0 additions & 1 deletion lab3/inputs/mapping/accelerator1.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- name: default
core_allocation: [1]
spatial_mapping:
D1:
- C, 32
Expand Down
1 change: 0 additions & 1 deletion lab3/inputs/mapping/accelerator2.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- name: default
core_allocation: [1]
spatial_mapping:
D1:
- OX, 32
Expand Down
1 change: 0 additions & 1 deletion lab3/inputs/mapping/accelerator3.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- name: default
core_allocation: [1]
spatial_mapping:
D1:
- OX, 64
Expand Down
Binary file added lab3/inputs/workload/resnet18_first_layer.onnx
Binary file not shown.
46 changes: 22 additions & 24 deletions lab3/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import os
import sys

sys.path.insert(0, os.getcwd())

from zigzag.api import get_hardware_performance_zigzag
from zigzag.visualization.results.plot_cme import bar_plot_cost_model_evaluations_total

# Path to the workload onnx model
# onnx_model_path = "zigzag/inputs/examples/workload/resnet18.onnx"
onnx_model_path = "lab1/resnet18_first_layer.onnx"
workload = "lab3/inputs/workload/resnet18_first_layer.onnx"
workload_name = "resnet18_first_layer"

# List of accelerators architectures we run our experiment for
hardwares = [
accelerators = [
"lab3/inputs/hardware/accelerator1.yaml",
"lab3/inputs/hardware/accelerator2.yaml",
"lab3/inputs/hardware/accelerator3.yaml",
Expand All @@ -23,24 +17,28 @@
"lab3/inputs/mapping/accelerator3.yaml",
]

cmes = []
for i, (hardware, mapping) in enumerate(zip(hardwares, mappings)):
# Pickle filename to save list of cmes
pickle_filename = f"lab3/outputs/list_of_cmes_{i}.pickle"
temporal_mapping_search_engine = "loma"
optimization_criterion = "latency"
energies = []
latencies = []
for i, (accelerator, mapping) in enumerate(zip(accelerators, mappings)):
# Inputs for api call
hw_name = f"accelerator{i+1}"
experiment_id = f"{hw_name}-{workload_name}"
dump_folder = f"lab3/outputs/{experiment_id}"
pickle_filename = f"lab3/outputs/{experiment_id}_cmes.pickle"
# Call the zigzag api, using a provided accelerator and mapping
energy, latency, results = get_hardware_performance_zigzag(
onnx_model_path,
hardware,
workload,
accelerator,
mapping,
opt="latency",
dump_filename_pattern=f"lab3/outputs/accelerator{i}.json",
temporal_mapping_search_engine=temporal_mapping_search_engine,
opt=optimization_criterion,
dump_folder=dump_folder,
pickle_filename=pickle_filename,
)
cmes.append(results[0][0])
energies.append(energy)
latencies.append(latency)

x_labels = [f"accelerator{i}" for i in range(len(hardwares))]
bar_plot_cost_model_evaluations_total(
cmes,
labels=x_labels,
save_path="lab3/outputs/plot_total.png",
)
for i, (energy, latency) in enumerate(zip(energies, latencies)):
print(f"Accelerator {i+1}: Energy = {energy:.2e}, Latency = {latency:.2e}")

0 comments on commit 9d8be99

Please sign in to comment.