kbench: a kernel that lays out a weight table's experts is handed them laid out

A weight table reached every kernel as the tensor its planes decode to. libr4d's 4-bit grouped GEMMs
read each expert through their layout hooks (the w4 codes as R4D_DT_MOEW4, the E4M3 scales of
w4nl64a8h), so moe_gemm_w4a8 refused every case with "dtype this kernel does not serve", which
counts as a failure. Each expert is now laid out from its planes (the container's or
kf_draw_table's) and the entries are stacked one laid expert apart, while the oracle still reads
the decoded table. The container pass and the replay both do it, and a table counts as laid out
where the replay decides whether to compare exactly.

kfixture: kf_table_entry, kf_draw_entry_planes (kf_draw_table's per-expert draw, the same bytes)
and kf_lay_table. fixture_test: a table's experts are each laid out by the kernel.
This commit is contained in:
keptn42 committed 2026-11-04 22:08:06 +01:00
1 parent e0c3f971dc
commit 394b8cd290
5 files changed
+206 -15

No files matched your search

+22
View File
@@ -23,6 +23,7 @@
#include "rad_core.h"
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
@@ -189,6 +190,27 @@ uint64_t kf_weight_seed(const KfOperand& d, size_t k);
* refusal with `why`. */
int kf_draw_table(const KfOperand& d, size_t k, std::vector<uint8_t>* out, std::string* why);
/* One entry of a weight table: the table's encoding and selection over its shape without the
* leading expert dimension, as a weight operand. */
KfOperand kf_table_entry(const KfOperand& d);
/* Entry e's planes as kf_draw_table draws them. */
void kf_draw_entry_planes(const KfOperand& d, size_t k, int64_t e,
std::vector<std::vector<uint8_t>>* out);
/* Entry e's selected planes, from the fixture's draw or a container. RAD_OK, or the refusal. */
using KfEntryPlanes = std::function<int(int64_t e, std::vector<std::vector<uint8_t>>* out)>;
/* The bytes kernel `info` reads for the weight table `operand`: every entry laid out from its
* planes as kf_lay_weight lays out a weight, stacked one laid entry apart, which is how a kernel
* reads a table it is handed whole rather than through the engine's pointers. `lay` is the first
* entry's. Returns kf_lay_weight's answer for the entries: RAD_E_UNSUPPORTED when the kernel reads
* them as decoded (kf_draw_table's bytes); RAD_E_SHAPE when the entries lay out to different
* sizes, or to a size the declared entry does not stride by. */
int kf_lay_table(const RadKernelInfo* info, const RadParam* p, int n_p, int operand,
const KfOperand& d, const KfEntryPlanes& planes, RadLayout* lay,
std::vector<uint8_t>* out);
/* ================================================================== drawing an input
*
* One implementation for recorder and reader, which must produce byte-identical inputs. An index