From 6b962ae4117f87636492b1faf4a6fc8d2b73499d Mon Sep 17 00:00:00 2001 From: Hashim Sharif <hsharif3@tyler.cs.illinois.edu> Date: Sun, 23 Aug 2020 01:35:23 -0500 Subject: [PATCH] Adding source compile option (incomplete) to common Benchmark script --- llvm/projects/keras/src/Benchmark.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/llvm/projects/keras/src/Benchmark.py b/llvm/projects/keras/src/Benchmark.py index c206af332d..fc3b483fbc 100644 --- a/llvm/projects/keras/src/Benchmark.py +++ b/llvm/projects/keras/src/Benchmark.py @@ -1,6 +1,8 @@ import sys +import os +import shutil from keras.utils.np_utils import to_categorical from keras.models import load_model from frontend.approxhpvm_translator import translate_to_approxhpvm @@ -8,7 +10,8 @@ from frontend.weight_utils import dumpCalibrationData from frontend.weight_utils import dumpHPVMToKerasModel - +# Every CNN Benchmark must inherit from Benchmark class +# Defines common interfaces and virtual methods to be overridden by child classes class Benchmark: def __init__(self, name, reload_dir, keras_model_file, hpvm_dir, num_classes): @@ -32,14 +35,30 @@ class Benchmark: return + # Compiles frontend generated sources + def compileSource(self, working_dir): + + # set LLVM_SRC_ROOT + os.environ["CFLAGS"] = "" + os.environ["CXXFLAGS"] = "" + + dest_file = working_dir + "CMakeLists.txt" + shutil.copy("cmake_template/CMakeLists.txt", dest_file) + + # Cmake ../ + # make + + def run(self, argv): if len(argv) < 2: - print ("Usage: python ${benchmark.py} [hpvm_reload|keras_reload|train] [frontend]") + print ("Usage: python ${benchmark.py} [hpvm_reload|keras_reload|train] [frontend] [compile]") sys.exit(0) + # Virtual method call implemented by each CNN model = self.buildModel() + # Virtual method call to preprocess test and train data X_train, Y_train, X_test, Y_test = self.data_preprocess() if argv[1] == "hpvm_reload": @@ -60,11 +79,12 @@ class Benchmark: print("ERROR: Must load HPVM model to invoke frontend - use 'hpvm_reload'") sys.exit(1) + # Main call to ApproxHPVM-Keras Frontend working_dir = translate_to_approxhpvm(model, self.hpvm_dir, X_test, Y_test, self.num_classes) print ("*** working_dir = ", working_dir) - - + if len(argv) > 3 and argv[3] == "compile": + self.compileSource(working_dir) -- GitLab