|
57 | 57 | import site |
58 | 58 | import subprocess |
59 | 59 | import sys |
60 | | -import sysconfig |
61 | | -import tempfile |
62 | 60 |
|
63 | 61 | from distutils import log # type: ignore[import-not-found] |
64 | 62 | from distutils.sysconfig import get_python_lib # type: ignore[import-not-found] |
@@ -463,84 +461,6 @@ def run(self): |
463 | 461 | if self._ran_build: |
464 | 462 | return |
465 | 463 |
|
466 | | - try: |
467 | | - # Following code is for building the Qualcomm backend. |
468 | | - from backends.qualcomm.scripts.download_qnn_sdk import ( |
469 | | - _download_qnn_sdk, |
470 | | - is_linux_x86, |
471 | | - ) |
472 | | - |
473 | | - if is_linux_x86(): |
474 | | - os.environ["EXECUTORCH_BUILDING_WHEEL"] = "1" |
475 | | - |
476 | | - with tempfile.TemporaryDirectory() as tmpdir: |
477 | | - tmp_path = Path(tmpdir) |
478 | | - sdk_path = _download_qnn_sdk(dst_folder=tmp_path) |
479 | | - |
480 | | - if not sdk_path: |
481 | | - raise RuntimeError( |
482 | | - "Qualcomm SDK not found, cannot build backend" |
483 | | - ) |
484 | | - |
485 | | - # Determine paths |
486 | | - prj_root = Path(__file__).parent.resolve() |
487 | | - build_sh = prj_root / "backends/qualcomm/scripts/build.sh" |
488 | | - build_root = prj_root / "build-x86" |
489 | | - |
490 | | - if not build_sh.exists(): |
491 | | - raise FileNotFoundError(f"{build_sh} not found") |
492 | | - |
493 | | - # Run build.sh with SDK path exported |
494 | | - env = dict(**os.environ) |
495 | | - env["QNN_SDK_ROOT"] = str(sdk_path) |
496 | | - subprocess.check_call( |
497 | | - [ |
498 | | - str(build_sh), |
499 | | - "--skip_linux_android", |
500 | | - "--skip_linux_embedded", |
501 | | - ], |
502 | | - env=env, |
503 | | - ) |
504 | | - |
505 | | - # Copy the main .so into the wheel package |
506 | | - so_src = ( |
507 | | - build_root / "backends/qualcomm/libqnn_executorch_backend.so" |
508 | | - ) |
509 | | - so_dst = Path( |
510 | | - self.get_ext_fullpath( |
511 | | - "executorch.backends.qualcomm.qnn_backend" |
512 | | - ) |
513 | | - ) |
514 | | - self.mkpath(str(so_dst.parent)) # ensure destination exists |
515 | | - self.copy_file(str(so_src), str(so_dst)) |
516 | | - logging.info(f"Copied Qualcomm backend: {so_src} -> {so_dst}") |
517 | | - |
518 | | - # Copy Python adaptor .so files |
519 | | - ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") |
520 | | - |
521 | | - so_files = [ |
522 | | - ( |
523 | | - "executorch.backends.qualcomm.python.PyQnnManagerAdaptor", |
524 | | - prj_root |
525 | | - / f"backends/qualcomm/python/PyQnnManagerAdaptor{ext_suffix}", |
526 | | - ), |
527 | | - ( |
528 | | - "executorch.backends.qualcomm.python.PyQnnWrapperAdaptor", |
529 | | - prj_root |
530 | | - / f"backends/qualcomm/python/PyQnnWrapperAdaptor{ext_suffix}", |
531 | | - ), |
532 | | - ] |
533 | | - |
534 | | - for module_name, so_src in so_files: |
535 | | - so_dst = Path(self.get_ext_fullpath(module_name)) |
536 | | - self.mkpath(str(so_dst.parent)) |
537 | | - self.copy_file(str(so_src), str(so_dst)) |
538 | | - logging.info(f"Copied Qualcomm backend: {so_src} -> {so_dst}") |
539 | | - |
540 | | - except ImportError: |
541 | | - logging.error("Fail to build Qualcomm backend") |
542 | | - logging.exception("Import error") |
543 | | - |
544 | 464 | if self.editable_mode: |
545 | 465 | self._ran_build = True |
546 | 466 | self.run_command("build") |
@@ -837,6 +757,11 @@ def run(self): # noqa C901 |
837 | 757 | cmake_build_args += ["--target", "custom_ops_aot_lib"] |
838 | 758 | cmake_build_args += ["--target", "quantized_ops_aot_lib"] |
839 | 759 |
|
| 760 | + if cmake_cache.is_enabled("EXECUTORCH_BUILD_QNN"): |
| 761 | + cmake_build_args += ["--target", "qnn_executorch_backend"] |
| 762 | + cmake_build_args += ["--target", "PyQnnManagerAdaptor"] |
| 763 | + cmake_build_args += ["--target", "PyQnnWrapperAdaptor"] |
| 764 | + |
840 | 765 | # Set PYTHONPATH to the location of the pip package. |
841 | 766 | os.environ["PYTHONPATH"] = ( |
842 | 767 | site.getsitepackages()[0] + ";" + os.environ.get("PYTHONPATH", "") |
@@ -924,5 +849,24 @@ def run(self): # noqa C901 |
924 | 849 | dst="executorch/data/lib/", |
925 | 850 | dependent_cmake_flags=[], |
926 | 851 | ), |
| 852 | + BuiltFile( |
| 853 | + src_dir="%CMAKE_CACHE_DIR%/backends/qualcomm/%BUILD_TYPE%/", |
| 854 | + src_name="qnn_executorch_backend", |
| 855 | + dst="executorch/backends/qualcomm/", |
| 856 | + is_dynamic_lib=True, |
| 857 | + dependent_cmake_flags=["EXECUTORCH_BUILD_QNN"], |
| 858 | + ), |
| 859 | + BuiltExtension( |
| 860 | + src_dir="%CMAKE_CACHE_DIR%/backends/qualcomm/%BUILD_TYPE%/", |
| 861 | + src="PyQnnManagerAdaptor.*", |
| 862 | + modpath="executorch.backends.qualcomm.python.PyQnnManagerAdaptor", |
| 863 | + dependent_cmake_flags=["EXECUTORCH_BUILD_QNN"], |
| 864 | + ), |
| 865 | + BuiltExtension( |
| 866 | + src_dir="%CMAKE_CACHE_DIR%/backends/qualcomm/%BUILD_TYPE%/", |
| 867 | + src="PyQnnWrapperAdaptor.*", |
| 868 | + modpath="executorch.backends.qualcomm.python.PyQnnWrapperAdaptor", |
| 869 | + dependent_cmake_flags=["EXECUTORCH_BUILD_QNN"], |
| 870 | + ), |
927 | 871 | ], |
928 | 872 | ) |
0 commit comments