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 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 make_project(self, target_dir): build_dir = os.path.join(target_dir, "build") if os.path.isdir(build_dir): rmtree(build_dir) os.makedirs(build_dir) current_path = os.getcwd() os.chdir(build_dir) cmd = buildtools.EllBuildTools(find_ell.get_ell_root()) cmd.cmake_generate("..") make = ["make"] if os.name == 'nt': make = ["cmake", "--build", ".", "--config", "Release"] cmd.run(make, print_output=True) os.chdir(current_path)
def make_project(target_dir): build_dir = os.path.join(target_dir, "build") if os.path.isdir(build_dir): rmtree(build_dir) os.makedirs(build_dir) current_path = os.getcwd() os.chdir(build_dir) cmd = buildtools.EllBuildTools(find_ell.get_ell_root(), verbose=True) cmake = ["cmake", ".."] if os.name == 'nt': cmake = ["cmake", "-G", "Visual Studio 15 2017 Win64", ".."] cmd.run(cmake, print_output=True) make = ["make"] if os.name == 'nt': make = ["cmake", "--build", ".", "--config", "Release"] cmd.run(make, print_output=True) os.chdir(current_path)
def test_cpp(model_path): target_dir = os.path.join(os.path.dirname(model_path), "tutorial_cpp") if os.path.isdir(target_dir): rmtree(target_dir) os.makedirs(target_dir) copyfile(os.path.join(script_path, "tutorialCMakeLists.txt"), os.path.join(target_dir, "CMakeLists.txt")) copyfile(os.path.join(script_path, "tutorial.cpp"), os.path.join(target_dir, "tutorial.cpp")) # invoke "wrap.py" helper to create a compilable C++ project wrap_model(model_path, target_dir, "cpp") # compile the project using cmake. make_project(target_dir) # did it actually build? binary = os.path.join(target_dir, "build") if os.name == 'nt': binary = os.path.join(binary, "release", "tutorial.exe") else: binary = os.path.join(binary, "tutorial") if not os.path.isfile(binary): print("### wrap_test failed, binary 'tutorial' was not produced") return 1 # execute the compiled tutorial.exe binary and check the output cmd = buildtools.EllBuildTools(find_ell.get_ell_root(), verbose=True) output = cmd.run([binary], print_output=True) if not "Prediction=0, 1, 2, 3, 4, 5, 6, 7, 8, 9" in output: print( "### FAILED: wrap_test cpp binary did not print the expected results, got the following:\n{}" .format(output)) return 1 else: print("### PASSED wrap_test: test_cpp") return 0
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 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))