Construct a VirtualMachine wrapper object. Parameters ---------- rt_mod: Union[tvm.runtime.Module, tvm.runtime.Executable] Runtime module exported by the result of build. device : Union[Device, List[Device]] The device to deploy the
(
self,
rt_mod: tvm.runtime.Module | tvm.runtime.Executable,
device: Device | list[Device],
memory_cfg: str | dict[Device, str] | None = None,
)
| 45 | POOLED_ALLOCATOR = 2 |
| 46 | |
| 47 | def __init__( |
| 48 | self, |
| 49 | rt_mod: tvm.runtime.Module | tvm.runtime.Executable, |
| 50 | device: Device | list[Device], |
| 51 | memory_cfg: str | dict[Device, str] | None = None, |
| 52 | ) -> None: |
| 53 | """ |
| 54 | Construct a VirtualMachine wrapper object. |
| 55 | |
| 56 | Parameters |
| 57 | ---------- |
| 58 | rt_mod: Union[tvm.runtime.Module, tvm.runtime.Executable] |
| 59 | Runtime module exported by the result of build. |
| 60 | |
| 61 | device : Union[Device, List[Device]] |
| 62 | The device to deploy the module. |
| 63 | |
| 64 | memory_cfg : Optional[Union[str, Dict[Device, str]]] |
| 65 | Config the type of memory allocator. The allocator type can be ["naive", |
| 66 | "pooled"]. If memory_cfg is None, all devices will use pooled allocator |
| 67 | by default. If memory_cfg is string, all devices will use the specified |
| 68 | allocator type. If memory_cfg is a dict, each device uses the allocator |
| 69 | type specified in the dict, or pooled allocator if not specified in the |
| 70 | dict. |
| 71 | """ |
| 72 | if not isinstance(rt_mod, tvm.runtime.Module): |
| 73 | if isinstance(rt_mod, tvm.runtime.Executable): |
| 74 | rt_mod = rt_mod.jit() |
| 75 | else: |
| 76 | raise ValueError("Expect the rt_mod to be an runtime.Module") |
| 77 | |
| 78 | self.module = rt_mod["vm_load_executable"]() |
| 79 | self._invoke_closure = self.module["invoke_closure"] |
| 80 | self._save_function = self.module["save_function"] |
| 81 | self._set_input = self.module["set_input"] |
| 82 | self._invoke_stateful = self.module["invoke_stateful"] |
| 83 | self._get_output = self.module["get_output"] |
| 84 | self._get_output_arity = self.module["get_output_arity"] |
| 85 | self._get_function_arity = self.module["get_function_arity"] |
| 86 | self._get_function_param_name = self.module["get_function_param_name"] |
| 87 | self._set_instrument = self.module["set_instrument"] |
| 88 | self._setup_device(device, memory_cfg) |
| 89 | |
| 90 | def _setup_device(self, dev: Device, memory_cfg: str | dict[Device, str]) -> None: |
| 91 | """init devices and allocators.""" |
nothing calls this directly
no test coverage detected