From c1dd30aaa75d7553b8d908deacfed0f5a33689c0 Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Fri, 26 Mar 2021 14:15:06 -0500
Subject: [PATCH] Added documentation for predtuner and hpvm-profiler

---
 hpvm/docs/components/hpvm-profiler.rst        |  6 +++
 hpvm/docs/components/index.rst                |  2 +
 hpvm/docs/components/predtuner.rst            |  1 +
 .../hpvm-profiler/hpvm_profiler/__init__.py   | 39 ++++++++-----------
 hpvm/projects/predtuner                       |  2 +-
 hpvm/projects/torch2hpvm/README.rst           |  2 -
 6 files changed, 26 insertions(+), 26 deletions(-)
 create mode 100644 hpvm/docs/components/hpvm-profiler.rst
 create mode 120000 hpvm/docs/components/predtuner.rst

diff --git a/hpvm/docs/components/hpvm-profiler.rst b/hpvm/docs/components/hpvm-profiler.rst
new file mode 100644
index 0000000000..8a0e6603d3
--- /dev/null
+++ b/hpvm/docs/components/hpvm-profiler.rst
@@ -0,0 +1,6 @@
+HPVM Profiler API
+======================
+
+.. autofunction:: hpvm_profiler.profile_configs
+
+.. autofunction:: hpvm_profiler.plot_hpvm_configs
diff --git a/hpvm/docs/components/index.rst b/hpvm/docs/components/index.rst
index 774c1ef1cd..e71b13a8bb 100644
--- a/hpvm/docs/components/index.rst
+++ b/hpvm/docs/components/index.rst
@@ -28,3 +28,5 @@ which explains their role, usage, and other details.
    keras-frontend
    keras-benchmarks
    torch2hpvm
+   predtuner
+   hpvm-profiler
diff --git a/hpvm/docs/components/predtuner.rst b/hpvm/docs/components/predtuner.rst
new file mode 120000
index 0000000000..cdda0ab7b3
--- /dev/null
+++ b/hpvm/docs/components/predtuner.rst
@@ -0,0 +1 @@
+../../projects/predtuner/README.rst
\ No newline at end of file
diff --git a/hpvm/projects/hpvm-profiler/hpvm_profiler/__init__.py b/hpvm/projects/hpvm-profiler/hpvm_profiler/__init__.py
index 88f74c9194..14d0f491b8 100644
--- a/hpvm/projects/hpvm-profiler/hpvm_profiler/__init__.py
+++ b/hpvm/projects/hpvm-profiler/hpvm_profiler/__init__.py
@@ -1,7 +1,9 @@
+from dataclasses import dataclass
 from pathlib import Path
-from subprocess import CalledProcessError, PIPE
+from subprocess import PIPE, CalledProcessError
 from typing import Iterable, List, Tuple, Union
-from dataclasses import dataclass
+
+import matplotlib.pyplot as plt
 from tqdm import trange
 
 PathLike = Union[Path, str]
@@ -14,25 +16,20 @@ def profile_configs(
     output_config_path: PathLike,
     profile_filename: str = "profile_info.txt",
     qos_filename: str = "final_accuracy",
-):
+) -> None:
     """
     Profile an HPVM configuration file with an HPVM binary.
     The configuration file must have the baseline as the first configuration.
 
-    binary_path: Union[Path, str]
-        Path to binary to be executed in profiling.
-    config_path: Union[Path, str]
-        Path to config file (HPVM configuration format)
+    binary_path: Path to binary to be executed in profiling.
+    config_path: Path to config file (HPVM configuration format)
         with configs to enumerate for profiling.
-    output_config_path: Union[Path, str]
-        Path where the output configs are written.
+    output_config_path: Path where the output configs are written.
         The output config file has the same configs as the input `config_path` file,
         but the performance and energy readings are updated.
-    profile_filename: str
-        Name of profile file generated by the binary (in current directory).
+    profile_filename: Name of profile file generated by the binary (in current directory).
         This defaults to "profile_info.txt" and should not be changed for HPVM binaries.
-    qos_filename: str
-        Name of QoS file generated by the binary (in current directory).
+    qos_filename: Name of QoS file generated by the binary (in current directory).
         It contains a single float number as the QoS of this run.
         This defaults to "final_accuracy" and should not be changed for HPVM binaries.
     """
@@ -76,26 +73,21 @@ def plot_hpvm_configs(
     save_to: PathLike = None,
     show_qos_loss: bool = True,
     **fig_kwargs,
-):
+) -> plt.Figure:
     """
     Plot the QoS-speedup information in an HPVM configuration file.
     It is recommended to profile the config file first (using `profile_configs`)
     to obtain real speedup numbers.
     This function creates a `matplotlib.pyplot.Figure`, plots on it, and returns it.
 
-    config_path: Union[Path, str]
-        Path to the config file (HPVM configuration format).
-    save_to: Union[Path, str]
-        File to save figure into. Default is None: don't save figure (just return it).
-    show_qos_loss: bool
-        Show the loss of QoS on x axis of the figure. Defaults to True.
+    config_path: Path to the config file (HPVM configuration format).
+    save_to: File to save figure into. Default is None: don't save figure (just return it).
+    show_qos_loss: Show the loss of QoS on x axis of the figure. Defaults to True.
         If False, will use (absolute) QoS instead of QoS loss.
-    fig_kwargs:
-        Arguments to pass to `plt.subplots`.
+    fig_kwargs: Arguments to pass to `plt.subplots`.
     """
 
     import numpy as np
-    import matplotlib.pyplot as plt
 
     _, configs = read_hpvm_configs(config_path)
     get_qos = lambda c: c.qos_loss if show_qos_loss else c.qos
@@ -109,6 +101,7 @@ def plot_hpvm_configs(
         fig.savefig(save_to, dpi=300)
     return fig
 
+
 @dataclass
 class Config:
     conf_name: str
diff --git a/hpvm/projects/predtuner b/hpvm/projects/predtuner
index 2fbd6f876c..aa28a41ca1 160000
--- a/hpvm/projects/predtuner
+++ b/hpvm/projects/predtuner
@@ -1 +1 @@
-Subproject commit 2fbd6f876c34bfdbcbddc71cd73646e71bde5748
+Subproject commit aa28a41ca12b15af31e1d15b687367e27cde3878
diff --git a/hpvm/projects/torch2hpvm/README.rst b/hpvm/projects/torch2hpvm/README.rst
index e36e832045..928aa2e19f 100644
--- a/hpvm/projects/torch2hpvm/README.rst
+++ b/hpvm/projects/torch2hpvm/README.rst
@@ -1,10 +1,8 @@
-
 PyTorch Frontend for HPVM
 =========================
 
 ``torch2hpvm`` is a PyTorch frontend for HPVM. It provides a set of API that
 
-
 * Generates a PyTorch ``module`` into HPVM-C code;
 * Exports a PyTorch dataset to ApproxHPVM dataset format;
 * Compiles the generated code into binary by invoking HPVM automatically.
-- 
GitLab