diff --git a/backends/vulkan/cmake/ShaderLibrary.cmake b/backends/vulkan/cmake/ShaderLibrary.cmake index 0fb99757b0c..d7e55cd3592 100644 --- a/backends/vulkan/cmake/ShaderLibrary.cmake +++ b/backends/vulkan/cmake/ShaderLibrary.cmake @@ -25,8 +25,9 @@ if(NOT EXECUTORCH_ROOT) endif() # find_program already searches the PATH environment variable and appends the -# platform executable suffix (.exe on Windows). Add the Vulkan SDK bin dir as a -# hint so glslc is found on Windows even when only VULKAN_SDK is set. +# platform executable suffix (.exe on Windows). Prefer the Vulkan SDK bin dir so +# an explicitly configured SDK takes precedence, including on Windows where the +# installer may not add it to PATH. find_program(GLSLC_PATH glslc HINTS $ENV{VULKAN_SDK}/bin $ENV{VULKAN_SDK}/Bin) if(NOT GLSLC_PATH AND EXECUTORCH_BUILD_VULKAN) diff --git a/backends/vulkan/runtime/VulkanBackend.cpp b/backends/vulkan/runtime/VulkanBackend.cpp index 716d5aa5bd1..ff62d4f258c 100644 --- a/backends/vulkan/runtime/VulkanBackend.cpp +++ b/backends/vulkan/runtime/VulkanBackend.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -614,8 +615,7 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface { ~VulkanBackend() override = default; bool is_available() const override { - // TODO(ssjia): replace with an actual Vulkan runtime availability check - return true; + return vkapi::set_and_get_external_adapter() != nullptr || api::available(); } ET_NODISCARD Error compileModel( diff --git a/backends/vulkan/runtime/vk_api/Runtime.cpp b/backends/vulkan/runtime/vk_api/Runtime.cpp index d7e101d0865..abf51744a95 100644 --- a/backends/vulkan/runtime/vk_api/Runtime.cpp +++ b/backends/vulkan/runtime/vk_api/Runtime.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace vkcompute { @@ -474,13 +475,18 @@ Adapter* set_and_get_external_adapter( const VkInstance instance, const VkPhysicalDevice physical_device, const VkDevice logical_device) { - static const std::unique_ptr p_external_adapter = - init_external_adapter( - instance, - physical_device, - logical_device, - 1, - set_and_get_pipeline_cache_data_path("")); + static std::mutex external_adapter_mutex; + static std::unique_ptr p_external_adapter; + + const std::lock_guard lock(external_adapter_mutex); + if (!p_external_adapter) { + p_external_adapter = init_external_adapter( + instance, + physical_device, + logical_device, + 1, + set_and_get_pipeline_cache_data_path("")); + } return p_external_adapter.get(); } diff --git a/install_utils.py b/install_utils.py index 72cfa5f2faf..ee4a91aa661 100644 --- a/install_utils.py +++ b/install_utils.py @@ -65,10 +65,9 @@ def is_vulkan_available() -> bool: 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. + glslc is accepted from PATH or under $VULKAN_SDK/{bin,Bin}. 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.