|
6 | 6 |
|
7 | 7 | # pyre-strict |
8 | 8 |
|
| 9 | + |
9 | 10 | """API for loading and executing ExecuTorch PTE files using the C++ runtime. |
10 | 11 |
|
11 | 12 | .. warning:: |
|
29 | 30 | # the pybindings shared library extension. This will load libtorch.so and |
30 | 31 | # related libs, ensuring that the pybindings lib can resolve those runtime |
31 | 32 | # dependencies. |
| 33 | + |
32 | 34 | import torch as _torch |
33 | 35 |
|
34 | 36 | logger = logging.getLogger(__name__) |
35 | 37 |
|
36 | 38 | # Auto-discover the OpenVINO C library path from the pip-installed openvino |
37 | 39 | # package so the C++ backend's dlopen/LoadLibrary call works without the user |
38 | 40 | # having to set LD_LIBRARY_PATH or OPENVINO_LIB_PATH manually. |
| 41 | + |
39 | 42 | if not os.environ.get("OPENVINO_LIB_PATH"): |
40 | 43 | try: |
41 | 44 | import glob |
|
64 | 67 | del _ov_libs, _ov_libs_dir, _lib_pattern, _ov_dir, spec |
65 | 68 | except Exception as e: |
66 | 69 | logger.debug("OpenVINO auto-discovery failed: %s", e) |
67 | | - |
68 | 70 | # Update the DLL search path on Windows. This is the recommended way to handle native |
69 | 71 | # extensions. |
| 72 | + |
70 | 73 | if sys.platform == "win32": |
71 | 74 | try: |
72 | 75 | # The extension DLL should be in the same directory as this file. |
| 76 | + |
73 | 77 | pybindings_dir = os.path.dirname(os.path.abspath(__file__)) |
74 | 78 | os.add_dll_directory(pybindings_dir) |
75 | 79 | except Exception as e: |
76 | 80 | logger.error( |
77 | 81 | "Failed to add the pybinding extension DLL to the search path. The extension may not work.", |
78 | 82 | e, |
79 | 83 | ) |
80 | | - |
81 | 84 | # Let users import everything from the C++ _portable_lib extension as if this |
82 | 85 | # python file defined them. Although we could import these dynamically, it |
83 | 86 | # wouldn't preserve the static type annotations. |
84 | 87 | # |
85 | 88 | # Note that all of these are experimental, and subject to change without notice. |
| 89 | + |
86 | 90 | from executorch.extension.pybindings._portable_lib import ( # noqa: F401 |
87 | 91 | # Disable "imported but unused" (F401) checks. |
88 | 92 | _create_profile_block, # noqa: F401 |
|
109 | 113 |
|
110 | 114 | # Clean up so that `dir(portable_lib)` is the same as `dir(_portable_lib)` |
111 | 115 | # (apart from some __dunder__ names). |
| 116 | + |
112 | 117 | del _torch |
113 | 118 | del _exir_warnings |
114 | 119 | del _warnings |
0 commit comments