From 956d298591c961e48bd43e7cbe756b5f2cf9a551 Mon Sep 17 00:00:00 2001 From: agent Date: Mon, 9 Nov 2026 21:09:05 -0400 Subject: [PATCH] cli: name the backend that registered no device in the "invalid device" error (engine#1766, ask 2) Stacked on #272, which makes a failed `hrx_gpu_initialize` log through `hrx_check()` (ask 1). This is ask 2: the message the user actually meets. A backend whose runtime failed still registers itself and then contributes no device, so its name resolves to nothing and the argument looks invalid: error while handling argument "--device": invalid device: HRX0 (before) error while handling argument "--device": invalid device: HRX0 hrx registered no device - its runtime did not initialise; the log line above this names why (after) Only the registry API is used (`ggml_backend_reg_dev_count`, `ggml_backend_reg_name`), so `common/` still knows nothing about HRX. Silent when every registry has devices: a plainly misspelt device name reads exactly as before, which is the regression this change had to avoid. Refs engine#1766. --- common/arg.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/common/arg.cpp b/common/arg.cpp index 6135ff9c84a7..e1ee136d373d 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -1052,7 +1052,21 @@ static std::vector parse_device_list(const std::string & val for (const auto & device : dev_names) { auto * dev = ggml_backend_dev_by_name(device.c_str()); if (!dev || ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_CPU) { - throw std::invalid_argument(string_format("invalid device: %s", device.c_str())); + // engine#1766: a backend whose runtime failed to initialise registers itself and then contributes no + // devices, so its name resolves to nothing and the argument looks invalid. Name the registries that + // contributed none -- the backend has already logged why (for HRX: "the HRX runtime did not + // initialise"), and without this line the user only sees a message about the argument. + std::string empty_registries; + for (size_t i = 0; i < ggml_backend_reg_count(); ++i) { + ggml_backend_reg_t reg = ggml_backend_reg_get(i); + if (reg != nullptr && ggml_backend_reg_dev_count(reg) == 0) { + empty_registries += string_format( + "\n %s registered no device - if its runtime failed to initialise, the log line above this names why", + ggml_backend_reg_name(reg)); + } + } + throw std::invalid_argument(string_format("invalid device: %s%s", device.c_str(), + empty_registries.c_str())); } devices.push_back(dev); }