Skip to content

Commit e10e98e

Browse files
committed
debug
1 parent 1745f91 commit e10e98e

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

.ci/scripts/test_wheel_package_qnn.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cat > "$REPO_ROOT/script.py" << 'EOF'
1717
import argparse
1818
1919
import torch
20+
from executorch.backends.qualcomm import install_qnn_sdk
2021
from executorch.backends.qualcomm.quantizer.quantizer import QnnQuantizer
2122
from executorch.backends.qualcomm.utils.utils import (
2223
generate_htp_compiler_spec,
@@ -30,6 +31,7 @@ from executorch.extension.export_util.utils import save_pte_program
3031
from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e, prepare_qat_pt2e
3132
3233
def main() -> None:
34+
install_qnn_sdk()
3335
parser = argparse.ArgumentParser()
3436
parser.add_argument("-f", "--output_folder", type=str, default="", help="The folder to store the exported program")
3537
parser.add_argument("--soc", type=str, default="SM8650", help="Specify the SoC model.")

backends/qualcomm/__init__.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,4 @@
22
import os
33
import pathlib
44

5-
from .scripts.download_qnn_sdk import (
6-
_download_qnn_sdk,
7-
_get_libcxx_dir,
8-
_load_libcxx_libs,
9-
_stage_libcxx,
10-
)
11-
12-
# Path to executorch/backends/qualcomm/
13-
PKG_ROOT = pathlib.Path(__file__).parent.parent / "qualcomm"
14-
15-
print(
16-
"EXECUTORCH_BUILDING_WHEEL: ", os.environ.get("EXECUTORCH_BUILDING_WHEEL", "False")
17-
)
18-
if not os.environ.get("EXECUTORCH_BUILDING_WHEEL"):
19-
# --- Qualcomm SDK handling ---
20-
qnn_root = os.environ.get("QNN_SDK_ROOT")
21-
if qnn_root:
22-
QNN_SDK_DIR = pathlib.Path(qnn_root)
23-
else:
24-
QNN_SDK_DIR = PKG_ROOT / "sdk" / "qnn"
25-
if not QNN_SDK_DIR.exists():
26-
print("Qualcomm SDK not found. Downloading...")
27-
_download_qnn_sdk()
28-
29-
os.environ["QNN_SDK_ROOT"] = str(QNN_SDK_DIR)
30-
31-
# Load QNN library
32-
qnn_lib = QNN_SDK_DIR / "lib" / "x86_64-linux-clang" / "libQnnHtp.so"
33-
try:
34-
ctypes.CDLL(str(qnn_lib), mode=ctypes.RTLD_GLOBAL)
35-
print(f"Loaded QNN library from {qnn_lib}")
36-
except OSError as e:
37-
print(f"[ERROR] Failed to load QNN library at {qnn_lib}: {e}")
38-
raise
39-
40-
# --- libc++ handling ---
41-
# Path to executorch/backends/
42-
# _libcxx_dir = _get_libcxx_dir(PKG_ROOT)
43-
44-
# Stage (download if missing) and load
45-
try:
46-
_stage_libcxx(_libcxx_dir)
47-
_load_libcxx_libs(_libcxx_dir)
48-
except Exception as e:
49-
print(f"[libcxx] Warning: failed to stage/load libc++: {e}")
5+
from .scripts.download_qnn_sdk import install_qnn_sdk

backends/qualcomm/scripts/download_qnn_sdk.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,45 @@ def _load_libcxx_libs(lib_path):
264264
print(f"Loaded {sofile.name}")
265265
except OSError as e:
266266
print(f"[WARN] Failed to load {sofile.name}: {e}")
267+
268+
269+
def install_qnn_sdk(force_download: bool = True) -> bool:
270+
"""
271+
Initialize Qualcomm backend:
272+
- Ensure SDK is available (env or packaged/downloaded copy)
273+
- Load QNN libraries
274+
- Stage and load libc++
275+
276+
Returns:
277+
bool: True if QNN was successfully loaded, False otherwise.
278+
"""
279+
280+
# --- Qualcomm SDK handling ---
281+
qnn_sdk_dir = PKG_ROOT / "sdk" / "qnn"
282+
print(f"[INIT] qnn_sdk_dir: {qnn_sdk_dir}")
283+
if not qnn_sdk_dir.exists():
284+
print("[INIT] Qualcomm SDK not found. Downloading...")
285+
_download_qnn_sdk()
286+
287+
os.environ["QNN_SDK_ROOT"] = str(qnn_sdk_dir)
288+
289+
# Load QNN library
290+
qnn_lib = qnn_sdk_dir / "lib" / "x86_64-linux-clang" / "libQnnHtp.so"
291+
print(f"[INIT] qnn_lib: {qnn_lib}")
292+
try:
293+
ctypes.CDLL(str(qnn_lib), mode=ctypes.RTLD_GLOBAL)
294+
print(f"[INIT] Loaded QNN library from {qnn_lib}")
295+
except OSError as e:
296+
print(f"[ERROR] Failed to load QNN library at {qnn_lib}: {e}")
297+
return False
298+
299+
# --- libc++ handling ---
300+
try:
301+
libcxx_dir = _get_libcxx_dir(PKG_ROOT / "sdk")
302+
_stage_libcxx(libcxx_dir)
303+
_load_libcxx_libs(libcxx_dir)
304+
print(f"[INIT] Loaded libc++ from {libcxx_dir}")
305+
except Exception as e:
306+
print(f"[libcxx] Warning: failed to stage/load libc++: {e}")
307+
308+
return True

0 commit comments

Comments
 (0)