Skip to content

Commit ded3172

Browse files
committed
Arm backend: Fix finding library paths
Change-Id: I4fcbbfe125a30e919e899e8add1ff4c8ed140ea5 Signed-off-by: Adrian Lundell <[email protected]>
1 parent a95beb3 commit ded3172

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

backends/arm/test/conftest.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
import glob
67
import logging
78
import os
9+
import platform
810
import random
911
import shutil
10-
import subprocess
1112
import sys
1213
from typing import Any
1314

@@ -173,31 +174,34 @@ def get_option(option: str) -> Any | None:
173174
return None
174175

175176

176-
def _load_lib(lib_name_pattern: str, build_folder: str):
177+
def _load_lib(lib_name_pattern: str):
177178
"""
178179
Find and load a library by name in build_folder.
179180
"""
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:
189184
import torch
190185

191186
torch.ops.load_library(library_paths[0])
192187
else:
193188
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?"
195190
)
196191

197192

198193
def _load_libquantized_ops_aot_lib():
199194
"""
200195
Find and load the libquantized_ops_aot_lib shared library.
201196
"""
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

Comments
 (0)