| 689 | self.build_base = "pip-out" |
| 690 | |
| 691 | def run(self): # noqa C901 |
| 692 | self.dump_options() |
| 693 | cmake_build_type = get_build_type(self.debug) |
| 694 | # get_python_lib() typically returns the path to site-packages, where |
| 695 | # all pip packages in the environment are installed. |
| 696 | cmake_prefix_path = os.environ.get("CMAKE_PREFIX_PATH", get_python_lib()) |
| 697 | # Put the cmake cache under the temp directory, like |
| 698 | # "pip-out/temp.<plat>/cmake-out". |
| 699 | pip_build_dir = os.path.join( |
| 700 | os.path.dirname(os.path.abspath(__file__)), self.build_temp |
| 701 | ) |
| 702 | cmake_cache_dir = os.path.join(pip_build_dir, "cmake-out") |
| 703 | self.mkpath(cmake_cache_dir) |
| 704 | |
| 705 | cmake_configuration_args = [ |
| 706 | f"-DPYTHON_EXECUTABLE={sys.executable}", |
| 707 | # Let cmake calls like `find_package(Torch)` find cmake config files |
| 708 | # like `TorchConfig.cmake` that are provided by pip packages. |
| 709 | f"-DCMAKE_PREFIX_PATH={cmake_prefix_path}", |
| 710 | f"-DCMAKE_BUILD_TYPE={cmake_build_type}", |
| 711 | ] |
| 712 | |
| 713 | # Use ClangCL on Windows. |
| 714 | if _is_windows(): |
| 715 | cmake_configuration_args += ["-T ClangCL"] |
| 716 | |
| 717 | # Allow adding extra cmake args through the environment. Used by some |
| 718 | # tests and demos to expand the set of targets included in the pip |
| 719 | # package. |
| 720 | cmake_configuration_args += [ |
| 721 | item for item in re.split(r"\s+", os.environ.get("CMAKE_ARGS", "")) if item |
| 722 | ] |
| 723 | |
| 724 | # Check if CUDA is available, and if so, enable building the CUDA |
| 725 | # backend by default. |
| 726 | if install_utils.is_cuda_available() and install_utils.is_cmake_option_on( |
| 727 | cmake_configuration_args, "EXECUTORCH_BUILD_CUDA", default=True |
| 728 | ): |
| 729 | cmake_configuration_args += ["-DEXECUTORCH_BUILD_CUDA=ON"] |
| 730 | |
| 731 | # Check if QNN SDK is available (via QNN_SDK_ROOT env var), and if so, |
| 732 | # enable building the Qualcomm backend by default. |
| 733 | qnn_sdk_root = os.environ.get("QNN_SDK_ROOT", "").strip() |
| 734 | if qnn_sdk_root and install_utils.is_cmake_option_on( |
| 735 | cmake_configuration_args, "EXECUTORCH_BUILD_QNN", default=True |
| 736 | ): |
| 737 | cmake_configuration_args += [ |
| 738 | "-DEXECUTORCH_BUILD_QNN=ON", |
| 739 | f"-DQNN_SDK_ROOT={qnn_sdk_root}", |
| 740 | ] |
| 741 | |
| 742 | # Enable OpenVINO backend on Linux. The backend uses dlopen at |
| 743 | # runtime so it has no build-time SDK dependency. |
| 744 | if sys.platform == "linux" and install_utils.is_cmake_option_on( |
| 745 | cmake_configuration_args, |
| 746 | "EXECUTORCH_BUILD_OPENVINO", |
| 747 | default=True, |
| 748 | ): |