Skip to content

Commit 53ead32

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 dacdf0d commit 53ead32

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

lib/API/Device.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "Config.h"
1515

1616
#include "llvm/Support/Error.h"
17+
#include "llvm/Support/raw_ostream.h"
1718

18-
#include <cstdlib>
1919
#include <memory>
2020

2121
using namespace offloadtest;
@@ -27,21 +27,31 @@ Device::~Device() {}
2727
llvm::Expected<llvm::SmallVector<std::unique_ptr<Device>>>
2828
offloadtest::initializeDevices(const DeviceConfig Config) {
2929
llvm::SmallVector<std::unique_ptr<Device>> Devices;
30+
llvm::Error Err = llvm::Error::success();
3031

3132
#ifdef OFFLOADTEST_ENABLE_D3D12
32-
if (auto Err = initializeDX12Devices(Config, Devices))
33-
return Err;
33+
if (auto E = initializeDX12Devices(Config, Devices))
34+
Err = llvm::joinErrors(std::move(Err), std::move(E));
3435
#endif
3536

3637
#ifdef OFFLOADTEST_ENABLE_VULKAN
37-
if (auto Err = initializeVulkanDevices(Config, Devices))
38-
return Err;
38+
if (auto E = initializeVulkanDevices(Config, Devices))
39+
Err = llvm::joinErrors(std::move(Err), std::move(E));
3940
#endif
4041

4142
#ifdef OFFLOADTEST_ENABLE_METAL
42-
if (auto Err = initializeMetalDevices(Config, Devices))
43-
return Err;
43+
if (auto E = initializeMetalDevices(Config, Devices))
44+
Err = llvm::joinErrors(std::move(Err), std::move(E));
4445
#endif
4546

47+
if (Devices.empty()) {
48+
if (Err)
49+
return std::move(Err);
50+
return llvm::createStringError(std::errc::no_such_device,
51+
"No GPU devices found.");
52+
}
53+
// Log errors from backends that failed while others succeeded.
54+
if (Err)
55+
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs());
4656
return Devices;
4757
}

test/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def setDeviceFeatures(config, device, compiler):
241241
target_device = None
242242
# Find the right device to configure against
243243
pattern = re.compile(GPUName, re.IGNORECASE)
244-
for device in devices["Devices"]:
244+
for device in devices.get("Devices", []):
245245
is_warp = "Microsoft Basic Render Driver" in device["Description"]
246246
is_gpu_name_match = bool(pattern.search(device["Description"]))
247247
if device["API"] == "DirectX" and config.offloadtest_enable_d3d12:

0 commit comments

Comments
 (0)