From 70ead4a70536ec7af29a99658a9e207b6e16d230 Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Tue, 16 Mar 2021 16:20:15 -0500
Subject: [PATCH] Added example for hpvm binary tuning

---
 README.md                 |  7 +++++++
 examples/tune_hpvm_bin.py | 21 +++++++++++++++++++++
 predtuner/__init__.py     |  1 +
 3 files changed, 29 insertions(+)
 create mode 100644 examples/tune_hpvm_bin.py

diff --git a/README.md b/README.md
index 2ec57bb..21a2378 100644
--- a/README.md
+++ b/README.md
@@ -40,3 +40,10 @@ You can open this in the browser and browse to "Getting Started" section.
   [here](https://drive.google.com/file/d/1Z84z-nsv_nbrr8t9i28UoxSJg-Sd_Ddu/view?usp=sharing).
 
 In either case, there should be a `model_params/` folder at the root of repo after extraction.
+
+## Binary Tuning Support for HPVM
+
+This branch (`hpvm`) contains experimental support for tuning with HPVM binary.
+See `examples/tune_hpvm_bin.py` for an example tuning session using such a binary file.
+
+TODO: attach a frontend-generated binary as an actual example.
diff --git a/examples/tune_hpvm_bin.py b/examples/tune_hpvm_bin.py
new file mode 100644
index 0000000..7fcfed3
--- /dev/null
+++ b/examples/tune_hpvm_bin.py
@@ -0,0 +1,21 @@
+import site
+from pathlib import Path
+
+site.addsitedir(Path(__file__).parent.parent.absolute().as_posix())
+from predtuner import PipedBinaryApp, config_pylogger
+
+# Set up logger to put log file in /tmp
+msg_logger = config_pylogger(output_dir="/tmp", verbose=True)
+
+# TODO: fill in these 2 paths:
+binary_file = ""
+metadata_file = ""
+# Create a "piped binary application"
+app = PipedBinaryApp("TestBinaryApp", binary_file, metadata_file)
+# Start tuning -- see tune_vgg16_cifar10.py for more details on the options
+tuner = app.get_tuner()
+tuner.tune(100, 3.0, 3.0, True, 50, cost_model="cost_linear")
+tuner.dump_configs("configs.json")
+fig = tuner.plot_configs(show_qos_loss=True)
+fig.savefig("configs.png", dpi=300)
+app.dump_hpvm_configs(tuner.best_configs, "hpvm_confs.txt")
diff --git a/predtuner/__init__.py b/predtuner/__init__.py
index c11d18f..babe3e0 100644
--- a/predtuner/__init__.py
+++ b/predtuner/__init__.py
@@ -9,5 +9,6 @@ from .modeledapp import (
     QoSModelP1,
     QoSModelP2,
 )
+from .pipedbin import PipedBinaryApp
 from .torchapp import TorchApp, TorchApproxKnob
 from .torchutil import accuracy
-- 
GitLab