def download_linked_module(file_name): """Load module from remote side.""" # c++ compiler/linker cc = os.environ.get("CXX", "g++") # pylint: disable=import-outside-toplevel path = temp.relpath(file_name) if path.endswith(".o"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc _cc.create_shared(path + ".so", path, cc=cc) path += ".so" elif path.endswith(".tar"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc, tar as _tar tar_temp = utils.tempdir(custom_path=path.replace(".tar", "")) _tar.untar(path, tar_temp.temp_dir) files = [tar_temp.relpath(x) for x in tar_temp.listdir()] _cc.create_shared(path + ".so", files, cc=cc) path += ".so" elif path.endswith(".dylib") or path.endswith(".so"): pass else: raise RuntimeError("Do not know how to link %s" % file_name) logger.info("Send linked module %s to client", path) return bytearray(open(path, "rb").read())
def load_module(path, fmt=""): """Load module from file. Parameters ---------- path : str The path to the module file. fmt : str, optional The format of the file, if not specified it will be inferred from suffix of the file. Returns ------- module : runtime.Module The loaded module Note ---- This function will automatically call cc.create_shared if the path is in format .o or .tar """ if os.stat(path).st_size == 0: logging.info( "The lib generated by the NNVM compiler does not contain optimized " "functions for any operators. This usually happens when an external " "accelerator, e.g. TensorRT, is employed along with TVM to compile " "the model, and all the operators in the model are supported by the " "external accelerator at runtime. Therefore, the NNVM compiler skipped " "optimizing them at the compile time. The TVM runtime " "will create an empty Module as a dummy module.") return _ffi_api.CreateEmptyModule() # High level handling for .o and .tar file. # We support this to be consistent with RPC module load. if path.endswith(".o"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc _cc.create_shared(path + ".so", path) path += ".so" elif path.endswith(".tar"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc, util as _util, tar as _tar tar_temp = _util.tempdir(custom_path=path.replace('.tar', '')) _tar.untar(path, tar_temp.temp_dir) files = [tar_temp.relpath(x) for x in tar_temp.listdir()] _cc.create_shared(path + ".so", files) path += ".so" # TODO(weberlo): we should probably use a more distinctive suffix for uTVM object files elif path.endswith(".obj"): fmt = "micro_dev" # Redirect to the load API return _ffi_api.ModuleLoadFromFile(path, fmt)
def load_module(path, fmt=""): """Load module from file. Parameters ---------- path : str The path to the module file. fmt : str, optional The format of the file, if not specified it will be inferred from suffix of the file. Returns ------- module : runtime.Module The loaded module Note ---- This function will automatically call cc.create_shared if the path is in format .o or .tar """ if os.path.isfile(path): path = os.path.realpath(path) else: raise ValueError("cannot find file %s" % path) # c++ compiler/linker cc = os.environ.get("CXX", "g++") # High level handling for .o and .tar file. # We support this to be consistent with RPC module load. if path.endswith(".o"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc _cc.create_shared(path + ".so", path, cc=cc) path += ".so" elif path.endswith(".tar"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc, utils as _utils, tar as _tar tar_temp = _utils.tempdir(custom_path=path.replace(".tar", "")) _tar.untar(path, tar_temp.temp_dir) files = [tar_temp.relpath(x) for x in tar_temp.listdir()] _cc.create_shared(path + ".so", files, cc=cc) path += ".so" # TODO(weberlo): we should probably use a more distinctive suffix for microTVM object files elif path.endswith(".obj"): fmt = "micro_dev" # Redirect to the load API return _ffi_api.ModuleLoadFromFile(path, fmt)
def load_module(path, fmt=""): """Load module from file. Parameters ---------- path : str The path to the module file. fmt : str, optional The format of the file, if not specified it will be inferred from suffix of the file. Returns ------- module : runtime.Module The loaded module Note ---- This function will automatically call cc.create_shared if the path is in format .o or .tar """ # High level handling for .o and .tar file. # We support this to be consistent with RPC module load. if path.endswith(".o"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc _cc.create_shared(path + ".so", path) path += ".so" elif path.endswith(".tar"): # Extra dependencies during runtime. from tvm.contrib import cc as _cc, util as _util, tar as _tar tar_temp = _util.tempdir(custom_path=path.replace('.tar', '')) _tar.untar(path, tar_temp.temp_dir) files = [tar_temp.relpath(x) for x in tar_temp.listdir()] _cc.create_shared(path + ".so", files) path += ".so" # TODO(weberlo): we should probably use a more distinctive suffix for uTVM object files elif path.endswith(".obj"): fmt = "micro_dev" # Redirect to the load API return _ffi_api.ModuleLoadFromFile(path, fmt)