Skip to content

Commit 0fe8047

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. Collect backend initialization errors with joinErrors() and return them together 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 4e8eb85 commit 0fe8047

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

lib/API/Device.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,27 @@ void Device::registerDevice(std::shared_ptr<Device> D) {
5757
}
5858

5959
llvm::Error Device::initialize(const DeviceConfig Config) {
60+
llvm::Error Result = llvm::Error::success();
6061
#ifdef OFFLOADTEST_ENABLE_D3D12
6162
if (auto Err = initializeDXDevices(Config))
62-
return Err;
63+
Result = llvm::joinErrors(std::move(Result), std::move(Err));
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+
Result = llvm::joinErrors(std::move(Result), std::move(Err));
68+
else
69+
// Validation layers have internal state which require a specific
70+
// destruction ordering. Relying on the global dtor call for this is
71+
// unreliable and can cause a null-deref in the validation layers during the
72+
// final vkDestroyInstance. This is a known limitation of the validation
73+
// layers which explicitely requires using atexit.
74+
atexit(Device::cleanupVulkanDevices);
7375
#endif
7476
#ifdef OFFLOADTEST_ENABLE_METAL
7577
if (auto Err = initializeMtlDevices(Config))
76-
return Err;
78+
Result = llvm::joinErrors(std::move(Result), std::move(Err));
7779
#endif
78-
return llvm::Error::success();
80+
return Result;
7981
}
8082

8183
void Device::uninitialize() { DeviceContext::instance().unregisterDevices(); }

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)