Skip to content

Commit 68112e4

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 e2679fa commit 68112e4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/API/Device.cpp

Lines changed: 14 additions & 4 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 Result = llvm::Error::success();
3031

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

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

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

47+
if (Devices.empty()) {
48+
if (Result)
49+
return std::move(Result);
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 (Result)
55+
llvm::logAllUnhandledErrors(std::move(Result), 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)