diff --git a/npu/private_route.cpp b/npu/private_route.cpp index 2d1b848cf..d774c3d78 100644 --- a/npu/private_route.cpp +++ b/npu/private_route.cpp @@ -107,9 +107,18 @@ std::string private_route_missing(const std::string& model_type) { "-DONEBIT_NPU_PRIVATE= (docs/npu.md, \"Private routes\")"; } +bool private_routes_available() { return !routes().empty() || !commands().empty(); } + void parse_private_option(const std::string& kv, PrivateOptions& opts) { const auto eq = kv.find('='); if (eq == std::string::npos || eq == 0) throw std::runtime_error("--npu-opt takes KEY=VALUE, not '" + kv + "'"); + // A private-route option on a build with no private routes is not a preference, it is a request nothing will read. + // Storing it silently is how a run ended up 10x slower than asked with no log line anywhere (engine#1740, W6): the + // caller asked for one route and got another, and the only evidence was that the numbers were identical. + if (!private_routes_available()) + throw std::runtime_error("--npu-opt " + kv + + " was given, but this build links no private NPU route, so the option would be ignored. " + "Build with -DONEBIT_NPU_PRIVATE= (docs/npu.md, \"Private routes\")"); opts[kv.substr(0, eq)] = kv.substr(eq + 1); } diff --git a/npu/private_route.h b/npu/private_route.h index a062f2b24..7f39e687a 100644 --- a/npu/private_route.h +++ b/npu/private_route.h @@ -104,6 +104,11 @@ std::string private_model_name(const std::string& model_type); // it or it is not a private route's type; otherwise that the route is not in this build. std::string private_route_missing(const std::string& model_type); // "KEY=VALUE" -> opts[KEY] = VALUE; throws without '=' or with an empty key. +// True when this build links a private-route add-on and it registered at least one route or command. `--npu-opt` only +// means anything in that case; without it the option used to be stored and silently ignored, which turns a mistyped or +// add-on-less invocation into a 10x slower route with no signal (engine#1740, W6). +bool private_routes_available(); + void parse_private_option(const std::string& kv, PrivateOptions& opts); // Defined by the add-on; `1bit` calls it once at startup in -DONEBIT_NPU_PRIVATE builds. diff --git a/tests/npu_private_route_test.cpp b/tests/npu_private_route_test.cpp index c4a09e64e..c3675a278 100644 --- a/tests/npu_private_route_test.cpp +++ b/tests/npu_private_route_test.cpp @@ -51,7 +51,24 @@ bool throws(const std::string& kv) { } // namespace +// engine#1740 (W6): with no add-on linked, a private-route option must be REFUSED, not stored. The failure it pins is +// concrete: `--npu-opt dx=` on such a build was accepted, ignored, and served the per-op route instead -- 10x slower +// with no log line, discovered only because two runs produced identical numbers. The arm is ordered before any route is +// registered below, which is exactly the no-add-on state. +void no_addon_refuses_the_option() { + PrivateOptions o; + bool threw = false; + try { + parse_private_option("dx=/tmp/kernels", o); + } catch (const std::runtime_error& e) { + threw = std::string(e.what()).find("links no private NPU route") != std::string::npos; + } + check("no add-on: --npu-opt is refused by name, not stored (engine#1740)", threw && o.empty()); + check("no add-on: private_routes_available() is false", !private_routes_available()); +} + int main() { + no_addon_refuses_the_option(); namespace fs = std::filesystem; const fs::path dir = fs::temp_directory_path() / ("npu_private_route_test." + std::to_string(::getpid())); fs::create_directories(dir);