diff --git a/llvm/projects/keras/src/Benchmark.py b/llvm/projects/keras/src/Benchmark.py index c206af332d920f263a77aa12b13bb3aff03b3a9e..fc3b483fbc9b34dc99455ba6e61fcc7eea79f24a 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)