This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/plugin/spechub/exports.cpp
T
Code000andClaude Opus 5.5 d0fd4aa1bb spec: --draft-verify token|block|traversal for the coupled MTP chain
--draft-coupling verifies each row of the chain on its own. Two lossless
sequence-level verifiers accept more drafts from the same chain: Block
Verification (arXiv 2403.10444) decides the whole chain at once, Traversal
Verification (arXiv 2505.12398) walks a path from its last draft back to its
first. --draft-verify token (default) is the engine as it was; block switches
the coupling on; traversal needs it and is refused otherwise.

Block: the sampler marks the consecutive bound rows of a request with the
block's length (RadMtpCoupleState::blk) and mtp_couple_verify decides the block
on the workgroup of its round-1 row, every FP64 sum a fixed lane tree so the
result is the host reference's bit for bit. The wide-plane serial helper is a
kernel of its own, which leaves couple_verify without scratch.

Traversal: a new op mtp_trav_verify takes the step's topology (parent row, draft
token per row) and decides a request on one workgroup, 0 bytes of scratch: the
target's law as integer masses of a fixed-point exponential, the walk in FP64.
Its header and kernel also handle nodes with several children (Gumbel-top-k and
RheoSampling siblings); the serial head here drafts one, so that part has no
producer yet and is covered by the tests only.

RadMtpCoupleState grows from 152 to 168 bytes (nkids, scheme, blk), so
RAD_ABI_VERSION is 41.

Exactness: mtp_block_test enumerates the draft tree of a toy model and runs
chi-square over the real verify code; mtp_rrs_test runs chi-square and an
exhaustive enumeration of the walk (worst |joint - P| 7e-14) with negative
controls that fail; spechub_device_test compares the device rows with the host
rows. Measured on Qwen3.8-Flash-Next IQR-V4 (TP2, MTP chain 3, coupling) on our
branch: about +1% tok/s with traversal, +4.6% at T 1.0 top_k 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 21:49:45 +01:00

95 lines
3.8 KiB
C++

/* plugin/spechub/exports.cpp -- the plugin's export block.
*
* The whole kernel-plugin set (schema count/at, kernel count/at, ABI version, info) and nothing else.
* The rows themselves, their schemas and their argument readers are in spechub.cpp; the launches are
* spechub.hip (device) and ref_spechub.cpp (host).
*
* Reference status is per row: the library carries device rows and their host oracle, so
* `rad_kernel_reference` marks the device rows 0 and the host rows 1, and `rad_plugin_reference`
* stays 0. Marking the whole library would make the reference gate refuse the device rows. On a
* machine with no card only the reference rows exist, and the gate refuses the coupling there.
*
* The ops are declared only under --draft-coupling on; the plugin never reads the flag.
*/
#include "spechub.h"
#include "rad_abi_layout.h"
#ifdef RAD_SPECHUB_WITH_DEVICE
#include "../../libr4d/r4d_emit.h" /* only for the three globals it declares */
/* r4d_emit.h's dispatch recorder, defined here because plugins load RTLD_LOCAL and cannot
* resolve libr4d's copy. Nothing in this plugin sets the log, so the recorder stays inert. */
const void** r4d_dispatch_log = nullptr;
int r4d_dispatch_cap = 0;
int r4d_dispatch_n = 0;
#endif
namespace {
const RadPluginInfo kInfo = {
RAD_PLUGIN_KERNEL, "spechub", "0.1.0",
"Maximal coupling of speculative drafts: Q draws (MTP, DFlash2), coupled verify", "gfx1201",
};
} /* namespace */
extern "C" uint32_t rad_plugin_abi_version(void) { return RAD_ABI_VERSION; }
RAD_PLUGIN_ABI_LAYOUT_EXPORT
extern "C" const RadPluginInfo* rad_plugin_info(void) { return &kInfo; }
/* Mixed library: 0, and the per-row answer below does the classifying. */
extern "C" int rad_plugin_reference(void) { return 0; }
/* Row layout is [device 0..2, ref 0..2] with a card, [ref 0..2] without; row/op index 2 is
* dflash_couple_propose. The device rows are the production kernels; the host rows are the oracle
* rad-kbench checks them against and the only thing a card-less machine can run. */
extern "C" int rad_kernel_reference(int i) {
#ifdef RAD_SPECHUB_WITH_DEVICE
return (i >= 0 && i < RAD_SPECHUB_N_OPS) ? 0 : 1;
#else
(void)i;
return 1;
#endif
}
extern "C" int rad_kernel_schema_count(void) { return rad_spechub_schema_count(); }
extern "C" const RadOpSchema* rad_kernel_schema_at(int i) { return rad_spechub_schema_at(i); }
/* The device rows and the host references beside them, in that order. A card-less machine loads the
* same library and resolves only the reference rows. */
extern "C" int rad_kernel_count(void) {
#ifdef RAD_SPECHUB_WITH_DEVICE
return 2 * RAD_SPECHUB_N_OPS;
#else
return RAD_SPECHUB_N_OPS;
#endif
}
namespace {
RadKernelInfo ref_row(int op, RadLaunchFn launch, const char* name) {
RadKernelInfo x = rad_spechub_row(op, launch);
x.name = name;
x.domain = RAD_DOMAIN_HOST;
x.priority = 0;
return x;
}
} /* namespace */
extern "C" const RadKernelInfo* rad_kernel_at(int i) {
#ifdef RAD_SPECHUB_WITH_DEVICE
static const RadKernelInfo dev[RAD_SPECHUB_N_OPS] = {
rad_spechub_row(0, rad_mine_mtp_couple_propose_launch),
rad_spechub_row(1, rad_mine_mtp_couple_verify_launch),
rad_spechub_row(2, rad_mine_dflash_couple_launch),
rad_spechub_row(3, rad_mine_mtp_trav_verify_launch),
};
if (i >= 0 && i < RAD_SPECHUB_N_OPS) return &dev[i];
i -= RAD_SPECHUB_N_OPS;
#endif
static const RadKernelInfo ref[RAD_SPECHUB_N_OPS] = {
ref_row(0, rad_ref_mtp_couple_propose, "ref_mtp_couple_propose"),
ref_row(1, rad_ref_mtp_couple_verify, "ref_mtp_couple_verify"),
ref_row(2, rad_ref_dflash_couple, "ref_dflash_couple_propose"),
ref_row(3, rad_ref_mtp_trav_verify, "ref_mtp_trav_verify"),
};
if (i < 0 || i >= RAD_SPECHUB_N_OPS) return nullptr;
return &ref[i];
}