tests/r4d_emu: the tiled LoRA rows -- matrix, real shapes, batch invariance, codes

The shared lora_cases matrix now runs the tiled rows beside the scalar ones,
handing a row the scratch its hook asks for. test_lora adds: the real shapes
(K 2048 / 5120 / 6144 / 17408, R 16 / 48 / 64 / 192, N 256 .. 12288, odd M,
S 1..4, bf16 / E4M3 / E5M2 / i8, aligned and unaligned rows), each a shrink
-> expand pair held to the f64 bound and to libref's bytes; a row alone vs
the same row inside M = 7 / 16 / 17 / 37 / 300 of random slots and base
rows, bit for bit, through aligned and unaligned buffers; a base-only M 2048
launch touching nothing; and every fp8 / i8 code widened exactly through a
one-hot pool. The emulator shim gains the fence, atomic and allocation calls
the split's arrival counters use.
This commit is contained in:
baKon committed 2026-10-16 20:52:09 -05:00
1 parent ec1e830c43
commit 487a9f4399
3 files changed
+514 -9

No files matched your search

+21
View File
@@ -23,6 +23,10 @@
* half an ulp of y's dtype relative (2^-8 bf16, 2^-11 f16, 0 f32).
* * An implementation marked `ref_bytes` must also produce, for expand, exactly the bytes of the
* first implementation in the list -- the claim libr4d's expand makes about libref's order.
*
* A shrink row with a scratch hook (libr4d's WMMA row keeps its K split's partials there) is handed
* the scratch the hook asks for, filled with a non-zero pattern, as the core would hand it a slice of
* its arena.
*/
#pragma once
@@ -39,13 +43,28 @@
namespace lora_cases {
typedef int (*LaunchFn)(const RadArgs*, RadStream);
typedef int64_t (*ScratchFn)(const RadArgs*);
struct Impl {
const char* name;
LaunchFn shrink, expand;
bool ref_bytes; /* expand must match the first implementation bit for bit */
ScratchFn shrink_scratch; /* the row's scratch hook, or null: none */
};
/* The scratch a launch is handed, sized by the row's own hook from the call's parameters -- what
* the core does at declare with the band's M. Host memory: every implementation here runs on the
* host. */
static inline void with_scratch(RadArgs& a, ScratchFn fn, std::vector<uint8_t>& keep) {
a.scratch = nullptr;
a.scratch_bytes = 0;
const int64_t need = fn ? fn(&a) : 0;
if (need <= 0) return;
keep.assign((size_t)need, 0xA5); /* not zeros: a split must write its partials */
a.scratch = keep.data();
a.scratch_bytes = need;
}
struct Tally {
int cases = 0, fails = 0;
double worst_shrink = 0, worst_expand = 0; /* the largest |err| / tolerance seen */
@@ -173,6 +192,8 @@ static inline void shrink_case(Tally& T, const std::vector<Impl>& impls, std::mt
for (auto& x : tv) std::memcpy(&x, &kSentinel, 4);
t[4] = mk(tv.data(), RAD_F32, {M, R}, {R, 1});
++T.cases;
std::vector<uint8_t> scr;
with_scratch(a, im.shrink_scratch, scr);
const int rc = im.shrink(&a, nullptr);
if (rc != RAD_OK) {
fail(T, im, "shrink returned an error", M, R, K, adt, rc, -1);