def run(self): self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.tools = buildtools.EllBuildTools(self.ell_root, self.verbose) self.find_files() self.copy_files(self.files, "") self.copy_files(self.includes, "include") self.copy_files(self.tcc, "tcc") out_file = self.tools.compile(self.model_file, self.func_name, self.model_name, self.target, self.output_dir, self.blas, self.fuse_linear_ops, self.profile, self.llvm_format, self.optimize, self.debug) if self.language != "cpp": self.tools.swig(self.output_dir, self.model_file_base, self.language) if not self.no_opt_tool: out_file = self.tools.opt(self.output_dir, out_file, self.optimization_level) if not self.no_llc_tool: out_file = self.tools.llc(self.output_dir, out_file, self.target, self.optimization_level) self.create_cmake_file() if self.language == "python": self.create_module_init_file() if self.target == "host": print("success, now you can build the '" + self.output_dir + "' folder") else: print("success, now copy the '" + self.output_dir + "' folder to your target machine and build it there")
def __init__(self): self.arg_parser = argparse.ArgumentParser( "This script uses ELL to create a demo project for a model (default is d_I160x160x3CMCMCMCMCMCMC1A from the ELL gallery)\n" "on a target device (default is Raspberry Pi 3), pushes it to the given\n" "device's ip address using ssh and scp, then executes the test.\n" "The test also measures the accuracy and performance of evaluating the model.\n") self.ipaddress = None self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.test_dir = os.path.join(self.build_root, "test", "pitest") self.output_dir = None self.target_dir = "/home/pi/pi3" self.model_name = None self.labels_file = None self.ell_model = None self.ell_json = None self.username = "******" self.password = "******" self.target = "pi3" self.machine = None self.cluser = None self.ssh = None self.blas = True self.expression = None self.created_dirs = [] self.profile = False self.test = False if (not os.path.isdir(self.test_dir)): os.makedirs(self.test_dir)
def __init__(self, ipaddress=None, cluster=None, outdir=None, profile=False, model=None, labels=None, target="pi3", target_dir="/home/pi/pi3", username="******", password="******", iterations=1, expected=None, blas=True, test=False, verbose=True, timeout=None): self.ipaddress = ipaddress self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.output_dir = outdir self.target_dir = target_dir self.labels_file = labels self.ell_model = model self.username = username self.password = password self.target = target self.cluster = cluster self.blas = blas self.expected = expected self.profile = profile self.test = test self.verbose = verbose if timeout: self.timeout = int(timeout) else: self.timeout = None self.iterations = iterations # local state. self.model_name = None self.machine = None self.ell_json = None self.created_dirs = [] self.gallery_url = "https://github.com/Microsoft/ELL-models/raw/master/models/ILSVRC2012/" # initialize state from the args if not self.output_dir: self.output_dir = "test" self.test_dir = os.path.abspath(self.output_dir) if os.path.isdir(self.test_dir): rmtree(self.test_dir) os.makedirs(self.test_dir) self.extract_model_info(self.ell_model, self.labels_file) self.output_dir = os.path.join(self.test_dir, self.target, self.model_name) self.resolve_address(self.ipaddress, self.cluster) if not os.path.isdir(self.output_dir): os.makedirs(self.output_dir)
def test_simple_xor_model(self): path = os.path.join(find_ell.find_ell_build(), "tools/importers/CNTK/test/xorModel1.dnn") predictor = cntk_to_ell.predictor_from_cntk_model(path) result = predictor.Predict([0, 0]) self.assertAlmostEqual(result[0], 0, msg='incorrect prediction for [0, 0]') result = predictor.Predict([0, 1]) self.assertAlmostEqual(result[0], 1, msg='incorrect prediction for [0, 1]') result = predictor.Predict([1, 0]) self.assertAlmostEqual(result[0], 1, msg='incorrect prediction for [1, 0]') result = predictor.Predict([1, 1]) self.assertAlmostEqual(result[0], 0, msg='incorrect prediction for [1, 1]') # create a map and save to file ell_map = ell.neural.utilities.ell_map_from_predictor(predictor) ell_map.Save("xor_test.map") # create a map and save to file ell_map = ell.neural.utilities.ell_map_from_predictor( predictor, step_interval_msec=500, lag_threshold_msec=750, function_prefix="XorTest") ell_map.Save("xor_test_steppable.map")
def get_build_tool_locations(): build_root = find_ell.find_ell_build() jsonPath = os.path.join(build_root, ELL_TOOLS_JSON) if not os.path.isfile(jsonPath): raise Exception("Could not find build output: " + jsonPath) with open(jsonPath) as f: return json.loads(f.read())
def get_test_model_repo(self): config_file = os.path.join(find_ell.find_ell_build(), "config.json") if os.path.isfile(config_file): with open(config_file, "r") as f: config = json.load(f) if "test_models_repo" in config: return clone_repo(config["test_models_repo"], get_home_path()) return None else: raise Exception("Missing config.json file: {}".format(config_file))
def run(self): self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.tools = buildtools.EllBuildTools(self.ell_root) self.find_files() self.copy_files(self.files, "") self.copy_files(self.includes, "include") self.start_timer("compile") out_file = self.tools.compile( model_file=self.model_file, func_name=self.func_name, model_name=self.model_name, target=self.target, output_dir=self.output_dir, use_blas=self.blas, fuse_linear_ops=self.fuse_linear_ops, optimize_reorder_data_nodes=self.optimize_reorder, profile=self.profile, llvm_format=self.llvm_format, optimize=self.optimize, debug=self.debug, is_model_file=False, swig=self.swig, header=self.cpp_header, objext="." + self.objext, extra_options=self.compile_args) self.stop_timer("compile") if self.swig: self.start_timer("swig") self.tools.swig(self.output_dir, self.model_file_base, self.language) self.stop_timer("swig") if not self.no_opt_tool: self.start_timer("opt") out_file = self.tools.opt(self.output_dir, out_file, self.optimization_level) self.stop_timer("opt") if not self.no_llc_tool: self.start_timer("llc") out_file = self.tools.llc(self.output_dir, out_file, self.target, self.optimization_level, "." + self.objext) self.stop_timer("llc") self.write_stats() self.create_cmake_file() if self.language == "python": self.create_module_init_file() if self.target == "host": self.logger.info("success, now you can build the '" + self.output_dir + "' folder") else: self.logger.info( "success, now copy the '{}' folder to your target machine and build it there" .format(self.output_dir))
def run(self): self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.tools = buildtools.EllBuildTools(self.ell_root, self.verbose) self.find_files() self.copy_files(self.files, "") self.copy_files(self.includes, "include") self.copy_files(self.tcc, "tcc") self.tools.compile(self.model_file, self.func_name, self.model_name, self.target, self.output_dir, self.blas, self.profile) if self.language != "cpp": self.tools.swig(self.output_dir, self.model_name, self.language) self.tools.opt(self.output_dir, self.model_name) self.tools.llc(self.output_dir, self.model_name, self.target) self.create_cmake_file() if self.target == "host": print("success, now you can build the '" + self.output_dir + "' folder") else: print("success, now copy the '" + self.output_dir + "' folder to your target machine and build it there")
def __init__(self): self.ipaddress = None self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.test_dir = os.path.join(self.build_root, "test", "pitest") self.output_dir = None self.target_dir = "/home/pi/pi3" self.model_name = None self.labels_file = None self.ell_model = None self.ell_json = None self.username = "******" self.password = "******" self.target = "pi3" self.machine = None self.cluster = None self.blas = True self.expression = None self.created_dirs = [] self.profile = False self.test = False if (not os.path.isdir(self.test_dir)): os.makedirs(self.test_dir)
# File: build_gemm_models.py # Authors: Mason Remy # # Requires: Python 3.x # #################################################################################################### import os import sys script_path = os.path.dirname(os.path.realpath(__file__)) sys.path += [os.path.join(script_path, "../../../pythonlibs")] import find_ell ell_build_root = find_ell.find_ell_build() sys.path += [os.path.join(ell_build_root, "interfaces", "python", "package")] import ell import random import argparse import numpy as np type_mapping = { "double": ell.nodes.PortType.real, "float": ell.nodes.PortType.smallReal } def make_matrix(rows, cols, use_fixed_seed, data_type_str): if use_fixed_seed:
def get_ell_build(self): if not self.build_root: import find_ell self.build_root = find_ell.find_ell_build() return self.build_root
def __init__(self, ipaddress=None, cluster=None, outdir=None, profile=False, model=None, labels=None, target="pi3", target_dir="/home/pi/pi3", username="******", password="******", iterations=1, expected=None, blas=True, compile=COMPILE_INCREMENTAL, test=True, verbose=True, timeout=None): self.ipaddress = ipaddress self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.output_dir = outdir self.target_dir = target_dir self.labels_file = labels self.ell_model = model self.username = username self.password = password self.target = target self.cluster = cluster self.blas = blas self.expected = expected self.profile = profile self.compile = compile self.test = test self.verbose = verbose self.logger = logger.get() if timeout: self.timeout = int(timeout) else: self.timeout = None self.iterations = iterations # local state. self.model_name = None self.machine = None self.ell_json = None self.created_dirs = [] self.gallery_url = "https://github.com/Microsoft/ELL-models/raw/master/models/ILSVRC2012/" # initialize state from the args if not self.output_dir: self.output_dir = "test" self.test_dir = os.path.abspath(self.output_dir) if os.path.isdir(self.test_dir): if self.compile == COMPILE_FULL: rmtree(self.test_dir) else: if self.compile == COMPILE_NONE: raise Exception( "Test only usage requires outdir '{}' to exist already". format(self.output_dir)) os.makedirs(self.test_dir) if self.compile: self.extract_model_info(self.ell_model, self.labels_file) self.output_dir = os.path.join(self.test_dir, self.target) if self.test: self.resolve_address(self.ipaddress, self.cluster)
#################################################################################################### import gc import os import sys from shutil import copyfile, rmtree import numpy as np script_path = os.path.dirname(os.path.abspath(__file__)) sys.path += [ os.path.join(script_path, '..', '..', '..', 'tools', 'utilities', 'pythonlibs') ] import find_ell import ell ell_build_dir = find_ell.find_ell_build() sys.path += [os.path.join(ell_build_dir, "tools", "wrap")] import wrap import buildtools def wrap_model(model, target_dir, language): builder = wrap.ModuleBuilder() args = [ model, "--outdir", os.path.join(target_dir, "model"), "--language", language, "--target", "host", "--module_name", "model" ] builder.parse_command_line(args) builder.run()
def __init__(self, ipaddress=None, cluster=None, outdir=None, profile=False, model=None, labels=None, target="pi3", target_dir="/home/pi/test", username="******", password="******", iterations=1, expected=None, blas=True, compile=COMPILE_INCREMENTAL, test=True, timeout=None, apikey=None, skip_ellcode=False, gitrepo=None, wrap_options=None): self.ipaddress = ipaddress self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.output_dir = outdir self.target_dir = target_dir self.labels_file = labels self.ell_model = model self.username = username self.password = password self.target = target self.cluster = cluster self.apikey = apikey self.blas = blas self.expected = expected self.profile = profile self.profile_log = None self.compile = compile self.test = test self.prediction_time = None self.skip_ellcode = skip_ellcode self.logger = logger.get() self.rePlatform = "ARMv7.*" if target == "pi0": self.rePlatform = "ARMv6.*" if timeout: self.timeout = int(timeout) else: self.timeout = None self.iterations = iterations # local state. self.model_name = None self.machine = None self.ell_json = None self.created_dirs = [] self.gallery_url = "https://github.com/Microsoft/ELL-models/raw/master/" if gitrepo: self.gallery_url = download_helper.clone_repo( gitrepo, download_helper.get_home_path()) if wrap_options and type(wrap_options) is not list: raise Exception("'wrap_options' should be a list") self.wrap_options = wrap_options # initialize state from the args if not self.output_dir: self.output_dir = "test" self.test_dir = os.path.abspath(self.output_dir) if os.path.isdir(self.test_dir): if self.compile == COMPILE_FULL: rmtree(self.test_dir) os.makedirs(self.test_dir) else: if self.compile == COMPILE_NONE: raise Exception( "Test only usage requires outdir '{}' to exist already". format(self.output_dir)) os.makedirs(self.test_dir) if self.compile: self.extract_model_info(self.ell_model, self.labels_file) self.output_dir = os.path.join(self.test_dir, self.target) if self.test and self.target != "host": self.resolve_address(self.ipaddress, self.cluster)
def run(self): self.build_root = find_ell.find_ell_build() self.ell_root = os.path.dirname(self.build_root) self.tools = buildtools.EllBuildTools(self.ell_root) self.find_files() self.copy_files(self.files, "") self.copy_files(self.includes, "include") self.start_timer("compile") out_file = self.tools.compile( model_file=self.model_file, func_name=self.func_name, model_name=self.model_name, target=self.target, skip_ellcode=self.skip_ellcode, output_dir=self.output_dir, use_blas=self.blas, fuse_linear_ops=self.fuse_linear_ops, optimize_reorder_data_nodes=self.optimize_reorder, profile=self.profile, llvm_format=self.llvm_format, optimize=self.optimize, parallelize=self.parallelize, vectorize=self.vectorize, debug=self.debug, is_model_file=False, swig=self.swig, header=self.cpp_header, objext="." + self.objext, global_value_alignment=self.global_value_alignment, extra_options=self.compile_args) self.stop_timer("compile") if self.swig: self.start_timer("swig") args = [] if self.target in ["pi3", "pi0", "orangepi0"]: args += ["-DSWIGWORDSIZE32", "-DLINUX"] elif self.target in ["pi3_64", "aarch64"]: args += ["-DSWIGWORDSIZE64", "-DLINUX"] elif self.target == "host": from sys import maxsize if sys.platform.startswith('win32'): args += ["-DWIN32"] # SWIG expects 32-bit, regardless of bitness for Windows # (because INT_MAX == LONG_MAX on Windows) args += ["-DSWIGWORDSIZE32"] else: if sys.platform.startswith('linux'): args += ["-DLINUX"] if maxsize > 2**32: args += ["-DSWIGWORDSIZE64"] else: args += ["-DSWIGWORDSIZE32"] elif sys.platform.startswith('darwin'): args += ["-DAPPLE"] else: pass # raise exception? else: pass # raise exception? self.tools.swig(self.output_dir, self.model_file_base, self.language, args) self.stop_timer("swig") if not self.no_opt_tool: self.start_timer("opt") out_file = self.tools.opt(self.output_dir, out_file, self.optimization_level) self.stop_timer("opt") if not self.no_llc_tool: self.start_timer("llc") out_file = self.tools.llc(self.output_dir, out_file, self.target, self.optimization_level, "." + self.objext) self.stop_timer("llc") self.write_stats() self.create_cmake_file() if self.language == "python": self.create_module_init_file() if self.target == "host": self.logger.info("success, now you can build the '" + self.output_dir + "' folder") else: self.logger.info("success, now copy the '{}' folder to your target machine and build it there".format( self.output_dir))