diff --git a/core/plugin/select.cpp b/core/plugin/select.cpp index beb3388d..d7f9eb0a 100644 --- a/core/plugin/select.cpp +++ b/core/plugin/select.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -139,6 +140,13 @@ const KernelRow* Registry::select(std::string_view op, const Geometry& g, int do } } + static const int seldbg = std::getenv("R4D_DIAG") ? 1 : 0; /* kernel-selection trace; R4D_DIAG=1 */ + if (seldbg && std::string(op) == "attn_paged" && domain == RAD_DOMAIN_DEVICE) { + std::fprintf(stderr, "[SELDBG] %s | best=%s\n", t.query.c_str(), best ? best->info->name : "(none)"); + for (const auto& c : t.candidates) + std::fprintf(stderr, " %-28s prio=%-3d ok=%d why=%s\n", c.kernel.c_str(), + c.priority, (int)c.ok, c.why.c_str()); + } if (best) { t.kernel = best->info->name; t.plugin = best->plugin; diff --git a/core/runtime/ctx.cpp b/core/runtime/ctx.cpp index 41e3465e..23eb5813 100644 --- a/core/runtime/ctx.cpp +++ b/core/runtime/ctx.cpp @@ -401,7 +401,10 @@ int Ctx::bind_ops() { /* Execution site. Site is a property of the weights (spec ยง5.1), so an op whose every * weight operand was placed on the host runs its host kernel and everything else runs on * the device. An op with no weights stays on the device; the planner overrides through - * set_op_domain, which is where the "contiguous host runs" objective actually lands. + * set_op_domain, which is where the "contiguous host runs" objective actually lands. A + * weightless op with no device kernel in any band (host-only: rmsnorm_p / gelu_mul / + * logit_softcap / attn_paged) falls back to the band resolution and runs on the host -- + * the device is not a correct answer for a kernel that exists only on the host. * * ON THE HOST BACKEND (no card visible: CPU-only serving) the device domain is the host's * own memory and an op with no device kernel in any band runs its host kernel -- the @@ -431,6 +434,11 @@ int Ctx::bind_ops() { all_host = false; } if (all_host) dom = RAD_DOMAIN_HOST; + } else { + bool any_dev = false; + for (const Band& b : oi.bands) + if (b.dom[RAD_DOMAIN_DEVICE]) { any_dev = true; break; } + if (!any_dev) dom = RAD_DOMAIN_HOST; } op_domain_[i].store((uint8_t)dom, std::memory_order_relaxed);