Server environment function return temp dir
(load_library, work_path=None)
| 63 | |
| 64 | |
| 65 | def _server_env(load_library, work_path=None): |
| 66 | """Server environment function return temp dir""" |
| 67 | if work_path: |
| 68 | temp = work_path |
| 69 | else: |
| 70 | temp = utils.tempdir() |
| 71 | |
| 72 | # pylint: disable=unused-variable |
| 73 | @tvm_ffi.register_global_func("tvm.rpc.server.workpath", override=True) |
| 74 | def get_workpath(path): |
| 75 | return temp.relpath(path) |
| 76 | |
| 77 | @tvm_ffi.register_global_func("tvm.rpc.server.load_module", override=True) |
| 78 | def load_module(file_name): |
| 79 | """Load module from remote side.""" |
| 80 | path = temp.relpath(file_name) |
| 81 | m = _load_module(path) |
| 82 | logger.info("load_module %s", path) |
| 83 | return m |
| 84 | |
| 85 | @tvm_ffi.register_global_func("tvm.rpc.server.download_linked_module", override=True) |
| 86 | def download_linked_module(file_name): |
| 87 | """Load module from remote side.""" |
| 88 | # pylint: disable=import-outside-toplevel |
| 89 | path = temp.relpath(file_name) |
| 90 | |
| 91 | if path.endswith(".o"): |
| 92 | # Extra dependencies during runtime. |
| 93 | from tvm.support import cc as _cc |
| 94 | |
| 95 | _cc.create_shared(path + ".so", path) |
| 96 | path += ".so" |
| 97 | elif path.endswith(".tar"): |
| 98 | # Extra dependencies during runtime. |
| 99 | from tvm.support import cc as _cc |
| 100 | from tvm.support import tar as _tar |
| 101 | |
| 102 | tar_temp = utils.tempdir(custom_path=path.replace(".tar", "")) |
| 103 | _tar.untar(path, tar_temp.temp_dir) |
| 104 | files = [tar_temp.relpath(x) for x in tar_temp.listdir()] |
| 105 | _cc.create_shared(path + ".so", files) |
| 106 | path += ".so" |
| 107 | elif path.endswith(".dylib") or path.endswith(".so"): |
| 108 | pass |
| 109 | else: |
| 110 | raise RuntimeError(f"Do not know how to link {file_name}") |
| 111 | logger.info("Send linked module %s to client", path) |
| 112 | return bytearray(open(path, "rb").read()) |
| 113 | |
| 114 | libs = [] |
| 115 | load_library = load_library.split(":") if load_library else [] |
| 116 | for file_name in load_library: |
| 117 | # Resolve the literal library file name against the current working |
| 118 | # directory, preserving the exact filename the caller requested. |
| 119 | resolved = tvm_ffi.libinfo._resolve_and_validate( |
| 120 | [Path.cwd() / file_name], cond=lambda p: p.is_file() |
| 121 | ) |
| 122 | if resolved is None: |
no test coverage detected
searching dependent graphs…