From 63cf585b1bfd0a7e27dff85ca18aa8de49bb8627 Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Thu, 1 Apr 2021 05:19:34 -0500
Subject: [PATCH] approxhpvm.py => hpvm-clang renaming worldwide

---
 hpvm/docs/install.rst                               |  8 ++++----
 hpvm/projects/hpvm-tensor-rt/CMakeLists.txt         |  4 ++--
 hpvm/projects/torch2hpvm/torch2hpvm/compile.py      |  2 +-
 hpvm/scripts/hpvm_installer.py                      |  4 ++--
 hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt      |  7 ++-----
 hpvm/test/dnn_benchmarks/keras/Benchmark.py         | 13 ++++++++-----
 hpvm/tools/CMakeLists.txt                           |  2 +-
 .../{py-approxhpvm => hpvm-clang}/CMakeLists.txt    |  3 +++
 hpvm/tools/{py-approxhpvm => hpvm-clang}/main.py.in |  2 +-
 hpvm/tools/{py-approxhpvm => hpvm-clang}/setup.py   |  0
 10 files changed, 24 insertions(+), 21 deletions(-)
 rename hpvm/tools/{py-approxhpvm => hpvm-clang}/CMakeLists.txt (95%)
 rename hpvm/tools/{py-approxhpvm => hpvm-clang}/main.py.in (99%)
 rename hpvm/tools/{py-approxhpvm => hpvm-clang}/setup.py (100%)

diff --git a/hpvm/docs/install.rst b/hpvm/docs/install.rst
index fa4a3f747b..9dd8365ae7 100644
--- a/hpvm/docs/install.rst
+++ b/hpvm/docs/install.rst
@@ -143,14 +143,14 @@ Some common options that can be used with CMake are:
 * ``-DCMAKE_BUILD_TYPE=type`` --- Valid options for type are Debug, Release, RelWithDebInfo, and MinSizeRel. Default is Debug.
 * ``-DLLVM_ENABLE_ASSERTIONS=On`` --- Compile with assertion checks enabled (default is Yes for Debug builds, No for all other build types).
 
-Now, compile the HPVM Compilation Tool ``approxhpvm.py`` using:
+Now, compile the HPVM Compilation Tool ``hpvm-clang`` using:
 
 .. code-block:: shell
 
-   make -j<number of threads> approxhpvm.py
+   make -j<number of threads> hpvm-clang
 
 With all the aforementioned steps, HPVM should be built, installed, tested and ready to use.
-In particular, ``approxhpvm.py`` should be an executable command from your command line.
+In particular, ``hpvm-clang`` should be an executable command from your command line.
 
 Benchmarks and Tests
 --------------------
@@ -159,7 +159,7 @@ We provide a number of general benchmarks, DNN benchmarks, and test cases, writt
 
 ``make`` targets ``check-hpvm-pass``, ``check-hpvm-dnn``, and ``check-hpvm-profiler``
 tests various components of HPVM and are increasingly time-consuming.
-You can run tests similarly as how ``approxhpvm.py`` is compiled: for example,
+You can run tests similarly as how ``hpvm-clang`` is compiled: for example,
 
 .. code-block:: shell
 
diff --git a/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt b/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt
index f6fed2ac29..cbabc8bbe0 100644
--- a/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt
+++ b/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt
@@ -53,7 +53,7 @@ endif()
 
 # -- Manually list the directories (TRT_LINK_DIRS) and libraries (TRT_LINK_LIBS)
 # tensor_runtime links to, because CMake doesn't help us do this.
-# This is needed by both approxhpvm.py and the RPATH setting step (below).
+# This is needed by both hpvm-clang and the RPATH setting step (below).
 # First, take a guess at the paths to the libraries that are used here.
 # (CMake, why do you make this so difficult?)
 foreach(interface_lib ${LINK_LIBS})
@@ -120,7 +120,7 @@ function(add_tensor_runtime target_name)
     target_link_options(${target_name} PRIVATE "-Wl,-rpath,${libdir}")
   endforeach()
   # Also slap TRT_LINK_DIRS and TRT_LINK_LIBS on this target
-  # so that approxhpvm.py can read them. (we'll create our own properties.)
+  # so that hpvm-clang can read them. (we'll create our own properties.)
   set_target_properties(
     ${target_name} PROPERTIES
     TRT_LINK_DIRS "${TRT_LINK_DIRS}"
diff --git a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py
index 922b6795ad..172448a60d 100644
--- a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py
+++ b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py
@@ -172,7 +172,7 @@ class ModelExporter:
         from subprocess import run
 
         args = [
-            "approxhpvm.py",
+            "hpvm-clang",
             str(self.codefile),
             str(output_binary),
             *self.compile_args,
diff --git a/hpvm/scripts/hpvm_installer.py b/hpvm/scripts/hpvm_installer.py
index 6e3418b74b..cce8b3f079 100755
--- a/hpvm/scripts/hpvm_installer.py
+++ b/hpvm/scripts/hpvm_installer.py
@@ -30,7 +30,7 @@ LINKS = [
     "test",
     "tools",
 ]
-MAKE_TARGETS = ["approxhpvm.py"]
+MAKE_TARGETS = ["hpvm-clang"]
 MAKE_TEST_TARGETS = ["check-hpvm-dnn", "check-hpvm-pass"]
 
 # Relative to project root which is __file__.parent.parent
@@ -345,7 +345,7 @@ HPVM not installed.
 To complete installation, follow these instructions:
 - Create and navigate to a folder "./build" 
 - Run "cmake ../llvm [options]". Find potential options in README.md.
-- Run "make -j<number of threads> approxhpvm.py" and then "make install"
+- Run "make -j<number of threads> hpvm-clang" and then "make install"
 For more details refer to README.md.
 """
         )
diff --git a/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt b/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt
index d429bca23c..d9cdafa7bc 100644
--- a/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt
+++ b/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt
@@ -1,6 +1,3 @@
-# First get approxhpvm.py which we then use to compile benchmarks.
-get_filename_component(APPROXHPVM_PY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py REALPATH)
-
 # Each source file contains a @MODEL_PARAMS_DIR@ waiting to be filled in.
 set(MODEL_PARAMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../model_params/")
 set(test_compile_targets "")
@@ -12,8 +9,8 @@ function(compile_hpvm_c target_name src_filepath codegen_target)
   # the name of output file and custom target to clash.
   add_custom_command(
     OUTPUT ${output_bin_path}
-    DEPENDS ${generated_file_path} approxhpvm.py
-    COMMAND ${APPROXHPVM_PY}
+    DEPENDS ${generated_file_path} hpvm-clang
+    COMMAND hpvm-clang
       ${generated_file_path} ${output_bin_path}
       -t ${codegen_target} -I ${CMAKE_CURRENT_SOURCE_DIR}/include ${ARGN}
   )
diff --git a/hpvm/test/dnn_benchmarks/keras/Benchmark.py b/hpvm/test/dnn_benchmarks/keras/Benchmark.py
index c225ff9766..f3d8e9e6b2 100644
--- a/hpvm/test/dnn_benchmarks/keras/Benchmark.py
+++ b/hpvm/test/dnn_benchmarks/keras/Benchmark.py
@@ -52,20 +52,23 @@ class Benchmark:
         
         try:
             subprocess.run([
-                "approxhpvm.py", 
+                "hpvm-clang", 
                 "-h"
             ], check=True, stdout=FNULL)
             
         except:
-            print ("\n\n ERROR: Could not find approxhpvm.py (HPVM compile script)!! \n\n")
-            print ("To Compile, Must set PATH to include approxhpvm.py script. Do the following: ")
-            print ("**** export PATH=${PATH_TO_YOUR_HPVM_INSTALLATION}/build/bin/:$PATH *****")
+            print("""
+
+ERROR: Could not find hpvm-clang (HPVM compile script)!!
+
+hpvm-clang is installed to the python environment used when compiling HPVM.
+Please try rerunning 'make -j hpvm-clang'.""")
             sys.exit(1)
 
 
         try:
             subprocess.run([
-                "approxhpvm.py", src_file, target_binary,
+                "hpvm-clang", src_file, target_binary,
                 "-t", "tensor", "--conf-file", approx_conf_file
             ], check=True)
         except:
diff --git a/hpvm/tools/CMakeLists.txt b/hpvm/tools/CMakeLists.txt
index 495348404f..4758dde6a3 100644
--- a/hpvm/tools/CMakeLists.txt
+++ b/hpvm/tools/CMakeLists.txt
@@ -1,2 +1,2 @@
 add_llvm_tool_subdirectory(hpvm-config)
-add_llvm_tool_subdirectory(py-approxhpvm)
\ No newline at end of file
+add_llvm_tool_subdirectory(hpvm-clang)
\ No newline at end of file
diff --git a/hpvm/tools/py-approxhpvm/CMakeLists.txt b/hpvm/tools/hpvm-clang/CMakeLists.txt
similarity index 95%
rename from hpvm/tools/py-approxhpvm/CMakeLists.txt
rename to hpvm/tools/hpvm-clang/CMakeLists.txt
index e0640cdf9f..53a98d0b2d 100644
--- a/hpvm/tools/py-approxhpvm/CMakeLists.txt
+++ b/hpvm/tools/hpvm-clang/CMakeLists.txt
@@ -73,3 +73,6 @@ add_custom_target(
     COMMAND python3 -m pip install ./
     DEPENDS ${init_path} setup.py
 )
+# hpvm-clang is the name of the compiler binary (see setup.py)
+# We provide this alias for convenience
+add_custom_target(hpvm-clang DEPENDS hpvmpy)
diff --git a/hpvm/tools/py-approxhpvm/main.py.in b/hpvm/tools/hpvm-clang/main.py.in
similarity index 99%
rename from hpvm/tools/py-approxhpvm/main.py.in
rename to hpvm/tools/hpvm-clang/main.py.in
index 4062d047a4..5fa256d26b 100644
--- a/hpvm/tools/py-approxhpvm/main.py.in
+++ b/hpvm/tools/hpvm-clang/main.py.in
@@ -153,7 +153,7 @@ def _run_opt(
 
 
 def parse_args():
-    parser = argparse.ArgumentParser("approxhpvm")
+    parser = argparse.ArgumentParser("hpvm-clang")
     parser.add_argument("input_file", type=Path, help="HPVM-C code to compile")
     parser.add_argument("output_file", type=Path, help="Path to generate binary to")
     parser.add_argument(
diff --git a/hpvm/tools/py-approxhpvm/setup.py b/hpvm/tools/hpvm-clang/setup.py
similarity index 100%
rename from hpvm/tools/py-approxhpvm/setup.py
rename to hpvm/tools/hpvm-clang/setup.py
-- 
GitLab