Skip to content

Commit

Permalink
update lab2 to new formats
Browse files Browse the repository at this point in the history
  • Loading branch information
asyms committed Nov 18, 2024
1 parent 168ffb5 commit e5c4af6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 94 deletions.
49 changes: 49 additions & 0 deletions lab2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import logging
import os

from zigzag.api import get_hardware_performance_zigzag
from zigzag.visualization.results.plot_cme import (
bar_plot_cost_model_evaluations_breakdown,
)
from zigzag.visualization.results.print_mapping import print_mapping


# Initialize the logger
logging_level = logging.INFO
logging_format = "%(asctime)s - %(name)s.%(funcName)s +%(lineno)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging_level, format=logging_format)

# Define the experiment id and pickle name
hw_name = "tpu_like"
workload_name = "resnet18_first_layer"
experiment_id = f"{hw_name}-{workload_name}"
pickle_name = f"{experiment_id}-saved_list_of_cmes"

# Define main input paths
accelerator = "zigzag/inputs/hardware/tpu_like.yaml"
workload = "lab2/resnet18_first_layer.onnx"
mapping = "lab2/mapping.yaml"
assert os.path.exists(mapping), "Copy mapping.yaml from lab1 and modify it for lab2."

# Define other inputs of api call
temporal_mapping_search_engine = "loma"
optimization_criterion = "latency"
dump_folder = f"lab2/outputs/{experiment_id}"
pickle_filename = f"lab2/outputs/{pickle_name}.pickle"

# Get the hardware performance through api call
energy, latency, results = get_hardware_performance_zigzag(
accelerator=accelerator,
workload=workload,
mapping=mapping,
temporal_mapping_search_engine=temporal_mapping_search_engine,
opt=optimization_criterion,
dump_folder=dump_folder,
pickle_filename=pickle_filename,
)

# Save a bar plot of the cost model evaluations breakdown
cmes = [result[0] for result in results[0][1]]
save_path = "lab2/outputs/breakdown.png"
bar_plot_cost_model_evaluations_breakdown(cmes, save_path=save_path)
print_mapping(cmes[0])
18 changes: 8 additions & 10 deletions lab2/solutions/mapping.yaml → lab2/mapping.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
- name: /conv1/Conv
core_allocation: [1]
# spatial_mapping:
# D1:
# - K, 32
# D2:
# - C, 32
- name: Conv1 # Name of the first conv layer in the onnx model
spatial_mapping:
D1:
- C, 32
D2:
- K, 32
memory_operand_links:
O: O
W: I2
I: I1

# Default entry in case layer name and operator type are not available
- name: default
core_allocation: [1]
spatial_mapping:
D1:
- K, 32
D2:
- C, 32
D2:
- K, 32
memory_operand_links:
O: O
W: I2
Expand Down
84 changes: 0 additions & 84 deletions lab2/solutions/main.py

This file was deleted.

0 comments on commit e5c4af6

Please sign in to comment.