Skip to content

Commit 8b14fc2

Browse files
authored
Proper implementation for VulkanBackend::is_available()
Differential Revision: D112475113 Pull Request resolved: #21004
1 parent 5ed466e commit 8b14fc2

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

backends/vulkan/cmake/ShaderLibrary.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ if(NOT EXECUTORCH_ROOT)
2525
endif()
2626

2727
# find_program already searches the PATH environment variable and appends the
28-
# platform executable suffix (.exe on Windows). Add the Vulkan SDK bin dir as a
29-
# hint so glslc is found on Windows even when only VULKAN_SDK is set.
28+
# platform executable suffix (.exe on Windows). Prefer the Vulkan SDK bin dir so
29+
# an explicitly configured SDK takes precedence, including on Windows where the
30+
# installer may not add it to PATH.
3031
find_program(GLSLC_PATH glslc HINTS $ENV{VULKAN_SDK}/bin $ENV{VULKAN_SDK}/Bin)
3132

3233
if(NOT GLSLC_PATH AND EXECUTORCH_BUILD_VULKAN)

backends/vulkan/runtime/VulkanBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <executorch/backends/vulkan/runtime/VulkanDelegateHeader.h>
1111
#include <executorch/backends/vulkan/serialization/schema_generated.h>
1212

13+
#include <executorch/backends/vulkan/runtime/api/Context.h>
1314
#include <executorch/backends/vulkan/runtime/graph/ComputeGraph.h>
1415

1516
#include <executorch/backends/vulkan/runtime/graph/ops/OperatorRegistry.h>
@@ -614,8 +615,7 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface {
614615
~VulkanBackend() override = default;
615616

616617
bool is_available() const override {
617-
// TODO(ssjia): replace with an actual Vulkan runtime availability check
618-
return true;
618+
return vkapi::set_and_get_external_adapter() != nullptr || api::available();
619619
}
620620

621621
ET_NODISCARD Error compileModel(

backends/vulkan/runtime/vk_api/Runtime.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cstdlib>
1414
#include <cstring>
1515
#include <iostream>
16+
#include <mutex>
1617
#include <sstream>
1718

1819
namespace vkcompute {
@@ -474,13 +475,18 @@ Adapter* set_and_get_external_adapter(
474475
const VkInstance instance,
475476
const VkPhysicalDevice physical_device,
476477
const VkDevice logical_device) {
477-
static const std::unique_ptr<Adapter> p_external_adapter =
478-
init_external_adapter(
479-
instance,
480-
physical_device,
481-
logical_device,
482-
1,
483-
set_and_get_pipeline_cache_data_path(""));
478+
static std::mutex external_adapter_mutex;
479+
static std::unique_ptr<Adapter> p_external_adapter;
480+
481+
const std::lock_guard<std::mutex> lock(external_adapter_mutex);
482+
if (!p_external_adapter) {
483+
p_external_adapter = init_external_adapter(
484+
instance,
485+
physical_device,
486+
logical_device,
487+
1,
488+
set_and_get_pipeline_cache_data_path(""));
489+
}
484490

485491
return p_external_adapter.get();
486492
}

install_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ def is_vulkan_available() -> bool:
6565
Windows, the desktop GPU platforms the backend supports (macOS would require
6666
MoltenVK).
6767
68-
glslc is looked up on PATH and, failing that, under $VULKAN_SDK/{bin,Bin} to
69-
match the find_program() HINTS the build uses (see pybind.cmake and
70-
ShaderLibrary.cmake): the Windows Vulkan SDK sets VULKAN_SDK but does not add
71-
its bin directory to PATH, so a PATH-only probe would miss it there.
68+
glslc is accepted from PATH or under $VULKAN_SDK/{bin,Bin}. The Windows
69+
Vulkan SDK sets VULKAN_SDK but does not add its bin directory to PATH, so a
70+
PATH-only probe would miss it there.
7271
7372
Returns:
7473
True if glslc is available on a supported platform, False otherwise.

0 commit comments

Comments
 (0)