|
3 | 3 | # This source code is licensed under the BSD-style license found in the |
4 | 4 | # LICENSE file in the root directory of this source tree. |
5 | 5 |
|
| 6 | +import glob |
6 | 7 | import logging |
7 | 8 | import os |
| 9 | +import platform |
8 | 10 | import random |
9 | 11 | import shutil |
10 | | -import subprocess |
11 | 12 | import sys |
12 | 13 | from typing import Any |
13 | 14 |
|
@@ -173,31 +174,34 @@ def get_option(option: str) -> Any | None: |
173 | 174 | return None |
174 | 175 |
|
175 | 176 |
|
176 | | -def _load_lib(lib_name_pattern: str, build_folder: str): |
| 177 | +def _load_lib(lib_name_pattern: str): |
177 | 178 | """ |
178 | 179 | Find and load a library by name in build_folder. |
179 | 180 | """ |
180 | | - find_lib_cmd = [ |
181 | | - "find", |
182 | | - build_folder, |
183 | | - "-name", |
184 | | - f"{lib_name_pattern}", |
185 | | - ] |
186 | | - res = subprocess.run(find_lib_cmd, capture_output=True) |
187 | | - if res.returncode == 0: |
188 | | - library_paths = res.stdout.decode().strip().split("\n") |
| 181 | + |
| 182 | + library_paths = glob.glob(lib_name_pattern, recursive=True) |
| 183 | + if len(library_paths) > 0: |
189 | 184 | import torch |
190 | 185 |
|
191 | 186 | torch.ops.load_library(library_paths[0]) |
192 | 187 | else: |
193 | 188 | raise RuntimeError( |
194 | | - f"Did not find any library matching {lib_name_pattern} in {build_folder}. Have you installed executorch properly?" |
| 189 | + f"Did not find any library matching {lib_name_pattern}. Have you installed executorch properly?" |
195 | 190 | ) |
196 | 191 |
|
197 | 192 |
|
198 | 193 | def _load_libquantized_ops_aot_lib(): |
199 | 194 | """ |
200 | 195 | Find and load the libquantized_ops_aot_lib shared library. |
201 | 196 | """ |
202 | | - _load_lib("_portable_lib.cpython-310*", "extension") |
203 | | - _load_lib("libquantized_ops_aot_lib.*", "kernels") |
| 197 | + |
| 198 | + so_ext = { |
| 199 | + "Darwin": "dylib", |
| 200 | + "Linux": "so", |
| 201 | + "Windows": "dll", |
| 202 | + }.get(platform.system(), None) |
| 203 | + |
| 204 | + executorch_path = os.path.join(os.path.dirname(__file__), "..", "..", "..") |
| 205 | + |
| 206 | + _load_lib(f"{executorch_path}/**/_portable_lib.cpython-310*{so_ext}") |
| 207 | + _load_lib(f"{executorch_path}/**/libquantized_ops_aot_lib.{so_ext}") |
0 commit comments