Load module from file. Parameters ---------- path : str The path to the module 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 .t
(path)
| 422 | |
| 423 | |
| 424 | def load_module(path): |
| 425 | """Load module from file. |
| 426 | |
| 427 | Parameters |
| 428 | ---------- |
| 429 | path : str |
| 430 | The path to the module file. |
| 431 | |
| 432 | Returns |
| 433 | ------- |
| 434 | module : runtime.Module |
| 435 | The loaded module |
| 436 | |
| 437 | Note |
| 438 | ---- |
| 439 | This function will automatically call |
| 440 | cc.create_shared if the path is in format .o or .tar |
| 441 | """ |
| 442 | if os.path.isfile(path): |
| 443 | path = os.path.realpath(path) |
| 444 | else: |
| 445 | raise ValueError(f"cannot find file {path}") |
| 446 | |
| 447 | # High level handling for .o and .tar file. |
| 448 | # We support this to be consistent with RPC module load. |
| 449 | if path.endswith(".o"): |
| 450 | # Extra dependencies during runtime. |
| 451 | from tvm.support import cc as _cc |
| 452 | |
| 453 | _cc.create_shared(path + ".so", path) |
| 454 | path += ".so" |
| 455 | elif path.endswith(".tar"): |
| 456 | # Extra dependencies during runtime. |
| 457 | from tvm.support import cc as _cc |
| 458 | from tvm.support import tar as _tar |
| 459 | from tvm.support import utils as _utils |
| 460 | |
| 461 | tar_temp = _utils.tempdir(custom_path=path.replace(".tar", "")) |
| 462 | _tar.untar(path, tar_temp.temp_dir) |
| 463 | files = [tar_temp.relpath(x) for x in tar_temp.listdir()] |
| 464 | _cc.create_shared(path + ".so", files) |
| 465 | path += ".so" |
| 466 | # Redirect to the load API |
| 467 | return _load_module(path) |
| 468 | |
| 469 | |
| 470 | def load_static_library(path, func_names): |