diff --git a/docs/source/backends-overview.md b/docs/source/backends-overview.md index ad3d3b507c1..87939aa4f23 100644 --- a/docs/source/backends-overview.md +++ b/docs/source/backends-overview.md @@ -24,7 +24,7 @@ Backends are the bridge between your exported model and the hardware it runs on. | [CUDA](backends/cuda/cuda-overview.md) | Linux/Windows | GPU | NVIDIA GPU acceleration | | [Core ML](backends/coreml/coreml-overview.md) | iOS, macOS | NPU/GPU/CPU | Apple devices, high performance | | [Metal Performance Shaders](backends/mps/mps-overview.md) | iOS, macOS | GPU | Apple GPU acceleration | -| [Vulkan](backends/vulkan/vulkan-overview.md) | Android | GPU | Android GPU acceleration | +| [Vulkan](backends/vulkan/vulkan-overview.md) | Android, Linux, Windows | GPU | Android devices (mature); Desktops (experimental) | | [Qualcomm](backends-qualcomm) | Android | NPU | Qualcomm SoCs | | [MediaTek](backends-mediatek) | Android | NPU | MediaTek SoCs | | [Arm Ethos-U](backends/arm-ethos-u/arm-ethos-u-overview.md) | Embedded | NPU | Arm MCUs | diff --git a/docs/source/backends/vulkan/vulkan-overview.md b/docs/source/backends/vulkan/vulkan-overview.md index ede7d330e4b..176db5c6be7 100644 --- a/docs/source/backends/vulkan/vulkan-overview.md +++ b/docs/source/backends/vulkan/vulkan-overview.md @@ -3,7 +3,8 @@ The ExecuTorch Vulkan (ET-VK) backend enables ExecuTorch models to execute on GPUs via the cross-platform [Vulkan API](https://www.vulkan.org/). Although the Vulkan API support is almost ubiquitous among modern GPUs, the ExecuTorch Vulkan -backend is currently developed with a specific focus for **Android GPUs**. +backend is developed with a focus on **Android GPUs**, and support for desktop +platforms is experimental. ## Features diff --git a/install_utils.py b/install_utils.py index 9ffaf8c33ff..9b2a83ffddf 100644 --- a/install_utils.py +++ b/install_utils.py @@ -6,6 +6,7 @@ # LICENSE file in the root directory of this source tree. import functools +import os import platform import re import subprocess @@ -56,6 +57,44 @@ def is_cuda_available() -> bool: return False +def is_vulkan_available() -> bool: + """ + Check if the Vulkan shader compiler (glslc) is available on the system. + + glslc is the only build-time dependency for the Vulkan backend; the Vulkan + loader itself is dlopen()ed at runtime via volk. Restricted to Linux and + Windows, the desktop GPU platforms the backend supports (macOS would require + MoltenVK). + + glslc is looked up on PATH and, failing that, under $VULKAN_SDK/{bin,Bin} to + match the find_program() HINTS the build uses (see pybind.cmake and + ShaderLibrary.cmake): the Windows Vulkan SDK sets VULKAN_SDK but does not add + its bin directory to PATH, so a PATH-only probe would miss it there. + + Returns: + True if glslc is available on a supported platform, False otherwise. + """ + if sys.platform not in ("linux", "win32"): + return False + candidates = ["glslc"] + vulkan_sdk = os.environ.get("VULKAN_SDK") + if vulkan_sdk: + glslc_name = "glslc.exe" if sys.platform == "win32" else "glslc" + candidates += [ + os.path.join(vulkan_sdk, "bin", glslc_name), + os.path.join(vulkan_sdk, "Bin", glslc_name), + ] + for glslc in candidates: + try: + subprocess.run( + [glslc, "--version"], capture_output=True, text=True, check=True + ) + return True + except Exception: + continue + return False + + @functools.lru_cache(maxsize=1) def _get_cuda_version(): """ diff --git a/setup.py b/setup.py index 838e204cafc..719fb90012e 100644 --- a/setup.py +++ b/setup.py @@ -889,6 +889,27 @@ def run(self): # noqa C901 ): cmake_configuration_args += ["-DEXECUTORCH_BUILD_CUDA=ON"] + # Auto-enable the Vulkan backend when its only build-time dependency, + # the glslc shader compiler, is available (mirrors the CUDA detection + # above). Unlike CUDA, the backend also needs third-party submodules + # that are not in the default checkout set, so gate on their presence + # too: an incidental glslc must not turn a working source build into a + # hard CMake failure. An explicit -DEXECUTORCH_BUILD_VULKAN=ON still + # flows through and surfaces the backend's own missing-submodule error. + vulkan_third_party = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "backends/vulkan/third-party/volk/volk.c", + ) + if ( + not minimal_build + and os.path.exists(vulkan_third_party) + and install_utils.is_vulkan_available() + and install_utils.is_cmake_option_on( + cmake_configuration_args, "EXECUTORCH_BUILD_VULKAN", default=True + ) + ): + cmake_configuration_args += ["-DEXECUTORCH_BUILD_VULKAN=ON"] + # Check if QNN SDK is available (via QNN_SDK_ROOT env var), and if so, # enable building the Qualcomm backend by default. qnn_sdk_root = os.environ.get("QNN_SDK_ROOT", "").strip()