From 86b146256a495efb1d10d5c1c99c62dff4c867e5 Mon Sep 17 00:00:00 2001 From: Yifan Zhao <yifanz16@illinois.edu> Date: Tue, 6 Apr 2021 01:54:49 -0500 Subject: [PATCH] Added hpvm-tensor-rt unit tests --- .gitlab-ci.yml | 1 + hpvm/projects/hpvm-tensor-rt/CMakeLists.txt | 4 +++ hpvm/test/CMakeLists.txt | 1 + hpvm/test/README.rst | 6 ++++ hpvm/test/hpvm-tensor-rt/CMakeLists.txt | 11 +++++++ hpvm/test/hpvm-tensor-rt/lit.cfg.py | 35 +++++++++++++++++++++ hpvm/test/hpvm-tensor-rt/perforation.test | 1 + hpvm/test/hpvm-tensor-rt/sampling.test | 1 + 8 files changed, 60 insertions(+) create mode 100644 hpvm/test/hpvm-tensor-rt/CMakeLists.txt create mode 100644 hpvm/test/hpvm-tensor-rt/lit.cfg.py create mode 100644 hpvm/test/hpvm-tensor-rt/perforation.test create mode 100644 hpvm/test/hpvm-tensor-rt/sampling.test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4fd589046b..b626521245 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,6 +25,7 @@ build-and-test: - ./install.sh -j32 -t "X86" DCMAKE_BUILD_TYPE=Release - cd build - make -j32 check-hpvm-pass + - make -j32 check-hpvm-tensor-rt - make -j32 check-hpvm-dnn - make -j32 check-hpvm-keras-acc - make -j32 check-hpvm-torch-acc diff --git a/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt b/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt index be42ebec07..c448ce9c37 100644 --- a/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt +++ b/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt @@ -140,6 +140,10 @@ add_tensor_runtime(tensor_runtime_online -DONLINE_PROFILING=true -DFP16_tuning=f add_dependencies(tensor_runtime_online tensor_runtime) # Adding rule for the debugging source +# Don't put these binaries into the global bin/ (which is the LLVM default) +# Put it in our current dir. +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_executable(sampling_tests tests/sampling_tests.cc) target_link_libraries(sampling_tests tensor_runtime_online) diff --git a/hpvm/test/CMakeLists.txt b/hpvm/test/CMakeLists.txt index c0409b2101..8b4185294f 100644 --- a/hpvm/test/CMakeLists.txt +++ b/hpvm/test/CMakeLists.txt @@ -6,6 +6,7 @@ set(CLANG_C ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/clang) set(CLANG_CXX ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/clang++) add_subdirectory(hpvm_pass) # Passes test suite +add_subdirectory(hpvm-tensor-rt) # Unit tests of tensor_runtime add_subdirectory(benchmarks) # HPVM benchmarks (no DNN) add_subdirectory(dnn_benchmarks/hpvm-c) # HPVM-C DNN accuracy test suite add_subdirectory(dnn_benchmarks/keras) # Keras frontend test suite diff --git a/hpvm/test/README.rst b/hpvm/test/README.rst index 54cb323527..efd37dccf1 100644 --- a/hpvm/test/README.rst +++ b/hpvm/test/README.rst @@ -8,6 +8,10 @@ The ``hpvm/test`` directory holds all tests and benchmarks in HPVM and is organi * ``hpvm_pass/``: unit and regression tests for HPVM Passes, written in LLVM-bitcode. +* ``hpvm-tensor-rt/``: unit tests for the HPVM `tensor_runtime`. + This folder just contains the test fixtures and the test files to run. + The actual test cases live under ``${project_root}/hpvm/projects/hpvm-tensor-rt/tests/``. + * ``benchmarks/``: includes a few applications written in HPVM-C, a template, and directions for compiling and running these benchmarks. * ``benchmarks/parboil``: Selected benchmarks from the `Parboil <http://impact.crhc.illinois.edu/parboil/parboil.aspx>`_ benchmark suite. @@ -54,6 +58,8 @@ The following targets runs these tests respectively: * ``make -j check-hpvm-pass`` runs tests in ``hpvm_pass``: ``hpvm_pass/**/*.ll``. These are regression and unit tests for HPVM passes. +* ``make -j check-hpvm-tensor-rt`` checks the approximation implementations of `tensor_runtime`. + * ``make -j check-hpvm-dnn`` runs all 20 DNN benchmarks under ``dnn_benchmarks/hpvm-c`` (10 DNNs x 2 versions) and validates their accuracy. diff --git a/hpvm/test/hpvm-tensor-rt/CMakeLists.txt b/hpvm/test/hpvm-tensor-rt/CMakeLists.txt new file mode 100644 index 0000000000..9c1314d9eb --- /dev/null +++ b/hpvm/test/hpvm-tensor-rt/CMakeLists.txt @@ -0,0 +1,11 @@ +configure_lit_site_cfg( + ../lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py +) + +add_lit_testsuite(check-hpvm-tensor-rt "Running unit tests of HPVM Tensor Runtime" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS sampling_tests perforation_tests # These are from under projects/hpvm-tensor-rt +) diff --git a/hpvm/test/hpvm-tensor-rt/lit.cfg.py b/hpvm/test/hpvm-tensor-rt/lit.cfg.py new file mode 100644 index 0000000000..861281e56d --- /dev/null +++ b/hpvm/test/hpvm-tensor-rt/lit.cfg.py @@ -0,0 +1,35 @@ +# -*- Python -*- + +# Configuration file for the 'lit' test runner. + +import os + +import lit.formats +from lit.llvm import llvm_config + +# name: The name of this test suite. +config.name = "HPVM-Tensor-Runtime" + +# testFormat: The test format to use to interpret tests. +config.test_format = lit.formats.ShTest(False) + +# suffixes: A list of file extensions to treat as test files. This is overriden +# by individual lit.local.cfg files in the test subdirectories. +config.suffixes = [".test"] + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.dirname(__file__) + +# test_exec_root: The root path where tests should be run. +# This is set to the current directory under build dir (think CMAKE_CURRENT_BINARY_DIR) +current_source_dir = os.path.dirname(os.path.relpath(__file__, config.llvm_src_root)) +current_binary_dir = os.path.join(config.llvm_obj_root, current_source_dir) +config.test_exec_root = current_binary_dir + +# Tweak the PATH to include the tools dir. +# We'll include the PATH to where the hpvm-tensor-rt test cases are built. +# TODO: "tools/hpvm/..." is a bit of hardcoding. Not too bad. +# Still, think about how to improve this. +proj_trt_dir = os.path.join(config.llvm_obj_root, "tools/hpvm/projects/hpvm-tensor-rt") +print(proj_trt_dir) +llvm_config.with_environment("PATH", proj_trt_dir, append_path=True) diff --git a/hpvm/test/hpvm-tensor-rt/perforation.test b/hpvm/test/hpvm-tensor-rt/perforation.test new file mode 100644 index 0000000000..c585dd8f64 --- /dev/null +++ b/hpvm/test/hpvm-tensor-rt/perforation.test @@ -0,0 +1 @@ +RUN: sampling_tests diff --git a/hpvm/test/hpvm-tensor-rt/sampling.test b/hpvm/test/hpvm-tensor-rt/sampling.test new file mode 100644 index 0000000000..ef56cfabce --- /dev/null +++ b/hpvm/test/hpvm-tensor-rt/sampling.test @@ -0,0 +1 @@ +RUN: perforation_tests -- GitLab