Skip to content

Commit de099b0

Browse files
MarijnS95claude
andcommitted
api-query: Continue device initialization when a backend fails
Device::initialize() returns early when any backend fails to initialize, preventing subsequent backends from being discovered. For example, a Vulkan initialization failure (e.g. VK_ERROR_INCOMPATIBLE_DRIVER when MoltenVK is not installed) blocks Metal device discovery on macOS. Log backend initialization errors and continue to the next backend instead. Also make lit.cfg.py resilient to an empty device list from api-query. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 84f62d0 commit de099b0

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

lib/API/Device.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,25 @@ void Device::registerDevice(std::shared_ptr<Device> D) {
5959
llvm::Error Device::initialize(const DeviceConfig Config) {
6060
#ifdef OFFLOADTEST_ENABLE_D3D12
6161
if (auto Err = initializeDXDevices(Config))
62-
return Err;
62+
logAllUnhandledErrors(std::move(Err), llvm::errs(),
63+
"DirectX initialization failed: ");
6364
#endif
6465
#ifdef OFFLOADTEST_ENABLE_VULKAN
6566
if (auto Err = initializeVulkanDevices(Config))
66-
return Err;
67-
// Validation layers have internal state which require a specific destruction
68-
// ordering. Relying on the global dtor call for this is unreliable and can
69-
// cause a null-deref in the validation layers during the final
70-
// vkDestroyInstance. This is a known limitation of the validation layers
71-
// which explicitely requires using atexit.
72-
atexit(Device::cleanupVulkanDevices);
67+
logAllUnhandledErrors(std::move(Err), llvm::errs(),
68+
"Vulkan initialization failed: ");
69+
else
70+
// Validation layers have internal state which require a specific
71+
// destruction ordering. Relying on the global dtor call for this is
72+
// unreliable and can cause a null-deref in the validation layers during the
73+
// final vkDestroyInstance. This is a known limitation of the validation
74+
// layers which explicitely requires using atexit.
75+
atexit(Device::cleanupVulkanDevices);
7376
#endif
7477
#ifdef OFFLOADTEST_ENABLE_METAL
7578
if (auto Err = initializeMtlDevices(Config))
76-
return Err;
79+
logAllUnhandledErrors(std::move(Err), llvm::errs(),
80+
"Metal initialization failed: ");
7781
#endif
7882
return llvm::Error::success();
7983
}

test/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def setDeviceFeatures(config, device, compiler):
216216
target_device = None
217217
# Find the right device to configure against
218218
pattern = re.compile(GPUName, re.IGNORECASE)
219-
for device in devices["Devices"]:
219+
for device in devices.get("Devices", []):
220220
is_warp = "Microsoft Basic Render Driver" in device["Description"]
221221
is_gpu_name_match = bool(pattern.search(device["Description"]))
222222
if device["API"] == "DirectX" and config.offloadtest_enable_d3d12:

0 commit comments

Comments
 (0)