Skip to content

Commit 1b89c86

Browse files
committed
[Hexagon] Support RPC execution of existing shared lib
This patch modifies the `get_executor_from_factory` for relax to support accepting a string that points to an already exported shared library. This allows us to run models that were already compiled through the RPC executor.
1 parent b654852 commit 1b89c86

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

python/tvm/contrib/hexagon/session.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@ def get_graph_debug_executor(
287287
)
288288

289289
def get_executor_from_factory(
290-
self, module: Union[ExecutorFactoryModule, relax.Executable], hexagon_arch: str = "v68"
290+
self, module: Union[ExecutorFactoryModule, relax.Executable, str], hexagon_arch: str = "v68"
291291
):
292292
"""Create a local GraphModule which consumes a remote libmod.
293293
294294
Parameters
295295
----------
296296
297-
module : Union[ExecutorFactoryModule, relax.Executable]
297+
module : Union[ExecutorFactoryModule, relax.Executable, str]
298298
299299
The module to upload to the remote
300300
session and load.
@@ -305,7 +305,7 @@ def get_executor_from_factory(
305305
return self._aot_executor_from_factory(module)
306306
if isinstance(module, GraphExecutorFactoryModule):
307307
return self._graph_executor_from_factory(module)
308-
if isinstance(module, relax.Executable):
308+
if isinstance(module, (relax.Executable, str)):
309309
return self._relax_vm_executable_executor(module, hexagon_arch=hexagon_arch)
310310

311311
raise TypeError(f"Unsupported executor type: {type(module)}")
@@ -358,15 +358,17 @@ def _graph_executor_from_factory(
358358
"""
359359
return self.get_graph_executor(module.get_graph_json(), module.get_lib())
360360

361-
def _relax_vm_executable_executor(self, vm_exec: relax.Executable, hexagon_arch: str):
361+
def _relax_vm_executable_executor(
362+
self, vm_exec: Union[relax.Executable, str], hexagon_arch: str
363+
):
362364
"""Create a local TVM module which consumes a remote vm executable.
363365
364366
Paramters
365367
---------
366368
367369
vm_exec : relax.Executable
368370
The Relax VM Executable to upload to the remote and load. This will typically be the
369-
output of `relax.build`.
371+
output of `relax.build` or the path to an already built and exported shared library
370372
hexagon_arch : str
371373
The hexagon arch to be used
372374
Returns
@@ -376,14 +378,21 @@ def _relax_vm_executable_executor(self, vm_exec: relax.Executable, hexagon_arch:
376378
"""
377379
assert self._rpc is not None, "Hexagon session must be started using __enter__ prior to use"
378380

379-
temp_dir = utils.tempdir()
380-
path_exec = temp_dir.relpath("exec.so")
381+
if isinstance(vm_exec, relax.Executable):
382+
temp_dir = utils.tempdir()
383+
path_exec = temp_dir.relpath("exec.so")
381384

382-
vm_exec.mod.export_library(
383-
path_exec,
384-
fcompile=hexagon.create_aot_shared,
385-
hexagon_arch=hexagon_arch,
386-
)
385+
vm_exec.mod.export_library(
386+
path_exec,
387+
fcompile=hexagon.create_aot_shared,
388+
hexagon_arch=hexagon_arch,
389+
)
390+
391+
path = self.upload(path_exec, "exec.so")
392+
elif isinstance(vm_exec, str):
393+
path_exec = vm_exec
394+
else:
395+
raise TypeError(f"Unsupported executor type: {type(vm_exec)}")
387396

388397
path = self.upload(path_exec, "exec.so")
389398
return self._rpc.get_function("tvm.hexagon.load_module")(str(path))

0 commit comments

Comments
 (0)