Archived
Merge branch 'pr1-device' into pr2-engine
This commit is contained in:
commit
06172e98de
49 files changed
+2100
-205
No files matched your search
@@ -176,6 +176,12 @@ foreach(t ${RAD_TESTS})
|
||||
target_link_libraries(${n} PRIVATE ${RAD_TEST_CORE} ${CMAKE_DL_LIBS})
|
||||
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/libr4d)
|
||||
target_compile_options(${n} PRIVATE -ffp-contract=off)
|
||||
# relayout_parity_test also holds tools/opshapes.cpp's fallback table to these hooks' byte
|
||||
# totals, so it needs the table's source too.
|
||||
if(n STREQUAL relayout_parity_test)
|
||||
target_sources(${n} PRIVATE ${CMAKE_SOURCE_DIR}/tools/opshapes.cpp)
|
||||
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/tools)
|
||||
endif()
|
||||
elseif(n IN_LIST RAD_TESTS_WHOLE_CORE)
|
||||
add_executable(${n} ${t})
|
||||
target_link_libraries(${n} PRIVATE stdc++ "$<LINK_LIBRARY:WHOLE_ARCHIVE,rad_core>")
|
||||
|
||||
+11
-11
@@ -8629,7 +8629,7 @@ struct ArchCases {
|
||||
qwen35_fp8::step, 3, {}, 0x74fd4495028c1525ull);
|
||||
add("qwen35_fp8 + MTP, two ranks", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(2, 3); return qwen35_fp8::declare(b, q35.meta(), &c); },
|
||||
nullptr, 3, { "ar_rmsnorm_quant_fp8" }, 0x1c28909125c12f52ull);
|
||||
nullptr, 3, { "ar_rmsnorm_quant_fp8" }, 0x7c11e3c8243c955full);
|
||||
add("qwen35_fp8 + DFlash2", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(1, 7); return qwen35_fp8::declare(b, q35df.meta(), &c); },
|
||||
qwen35_fp8::step, 7, {}, 0x5eaef1ee37575caeull);
|
||||
@@ -8638,20 +8638,20 @@ struct ArchCases {
|
||||
qwen35_w8a8::step, 7, {}, 0x5a4f256c6fda0e87ull);
|
||||
add("qwen35_w8a8 + DFlash2, two ranks", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(2, 7); return w8a8_declare(b, q35w8df.meta(), &c); },
|
||||
nullptr, 7, { "ar_rmsnorm_quant_fp8" }, 0xb825b9d264795b8eull);
|
||||
nullptr, 7, { "ar_rmsnorm_quant_fp8" }, 0xdc5540151b0d6684ull);
|
||||
add("qwen35moe_fp8 + MTP", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(1, 3); return qwen35moe_fp8::declare(b, q35moe.meta(), &c); },
|
||||
qwen35moe_fp8::step, 3, {}, 0x1bd3b53543cd06eeull);
|
||||
add("qwen4exp_fp8", [this](RadBuilder* b) {
|
||||
auto c = q4_ctx(0, 1); return qwen4exp_fp8::declare(b, &q4, &c); },
|
||||
qwen4exp_fp8::step, 3, {}, 0xbe74d476c7fd04b8ull);
|
||||
qwen4exp_fp8::step, 3, {}, 0x43048d3448778280ull);
|
||||
add("qwen4exp_fp8, two ranks", [this](RadBuilder* b) {
|
||||
auto c = q4_ctx(0, 2); return qwen4exp_fp8::declare(b, &q4, &c); },
|
||||
nullptr, 3, { "ar_hc_write" }, 0x9d7df7914590d6d8ull);
|
||||
nullptr, 3, { "ar_hc_write" }, 0x43d3be2b6d76e470ull);
|
||||
add("qwen4exp_fp8, four-bit experts", [this](RadBuilder* b) {
|
||||
b->encs = { { "ffn_gate_up_exps", w4 }, { "ffn_down_exps", w4 } };
|
||||
auto c = q4_ctx(0, 1); return qwen4exp_fp8::declare(b, &q4, &c); },
|
||||
qwen4exp_fp8::step, 3, {}, 0xb308d06b168a61f1ull);
|
||||
qwen4exp_fp8::step, 3, {}, 0x08d082fcbef37889ull);
|
||||
add("llama_fp8 + DSpark", [this](RadBuilder* b) {
|
||||
auto c = dspark_ctx(0, 1); return llama_fp8::declare(b, lla.meta(), &c); },
|
||||
llama_fp8::step, 7, {}, 0xdcf36a1d31aba73cull);
|
||||
@@ -9333,13 +9333,13 @@ TEST(a_4096_budget_without_a_span_is_the_pinned_graph_and_steps) {
|
||||
uint64_t graph, steps;
|
||||
};
|
||||
const Case cases[] = {
|
||||
{ "qwen4exp_fp8", 1, 0, 0x14b9cab0bea2591full, 0x26a9e2c23cf85696ull },
|
||||
{ "qwen4exp_fp8", 2, 0, 0xc9bcbf1b538b597full, 0x889c6b36c014609full },
|
||||
{ "qwen4exp_fp8", 2, 1, 0x8b2f1786a4ac12b8ull, 0x959ef6b7c6f57d8bull },
|
||||
{ "qwen4exp_fp8", 4, 0, 0x1e97a26b759d29dfull, 0xfbe74f2b9d7020bfull },
|
||||
{ "qwen4exp_fp8", 4, 3, 0x6669aa0573931943ull, 0x36df57cac613c6cfull },
|
||||
{ "qwen4exp_fp8", 1, 0, 0x23ec76c443e2cb6full, 0x26a9e2c23cf85696ull },
|
||||
{ "qwen4exp_fp8", 2, 0, 0x88290524cfd7714full, 0x889c6b36c014609full },
|
||||
{ "qwen4exp_fp8", 2, 1, 0xa4268bda72739be8ull, 0x959ef6b7c6f57d8bull },
|
||||
{ "qwen4exp_fp8", 4, 0, 0xaa5abead708b106full, 0xfbe74f2b9d7020bfull },
|
||||
{ "qwen4exp_fp8", 4, 3, 0x9ffc4cf1b074a153ull, 0x36df57cac613c6cfull },
|
||||
{ "qwen35_fp8", 1, 0, 0xcfc82ca915ec549dull, 0x4d6fca823d1e97efull },
|
||||
{ "qwen35_fp8", 2, 1, 0x5085b8c443c59f7cull, 0xb297654cef04bf08ull },
|
||||
{ "qwen35_fp8", 2, 1, 0xcaf28466af9e917dull, 0x0bcf5833fce11a86ull },
|
||||
{ "qwen35moe_fp8", 1, 0, 0x7fa7b015e1bc8873ull, 0x3fcf71676e558d79ull },
|
||||
{ "qwen35moe_fp8", 2, 0, 0xf60c9508dd197370ull, 0x05e0778848bf416cull },
|
||||
};
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
* see. Where the kernel has an inverse, it must give the planes back exactly.
|
||||
*
|
||||
* libr4d needs a HIP toolchain to build but its layouts do not, so their host sources are compiled
|
||||
* into this test (tests/CMakeLists.txt). The n-gram table's hook is libavx's, from the plugin.
|
||||
* into this test (tests/CMakeLists.txt). The n-gram table's hook is libavx's, from the plugin. One
|
||||
* test here therefore reaches back into tools/opshapes.cpp: the fallback table sizes the packed
|
||||
* weights these hooks own, and only this file can hold both sides of that claim.
|
||||
*/
|
||||
#include "quant_fixture.h"
|
||||
#include "r4d_plugin.h"
|
||||
#include "opshapes.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
@@ -346,6 +349,87 @@ TEST(mxfp4_codes_exponents_and_the_row_reference) {
|
||||
0xc35d26b146836d77ull);
|
||||
}
|
||||
|
||||
/* tools/opshapes.cpp sizes a packed weight from the kernel's stored form, because no schema states
|
||||
* an extent and libref declines every grid with a zero point (ref_planes.h joins scale and zero
|
||||
* into one operand a description cannot state). A stale entry is not a failed check: rad-tune
|
||||
* allocates what the table says and hands the kernel the short buffer, which is a read past the
|
||||
* allocation on the card, not a refusal. So the table's byte total and the hook's `bytes` must
|
||||
* agree. The table's shapes are the tool's own view -- mxfp4's exponents are [K/32][N] there and
|
||||
* [N][K/32] in the store -- so the totals, not the shapes, are the contract. */
|
||||
TEST(the_tool_table_sizes_packed_weights_as_the_kernel_stores_them) {
|
||||
NEED_LIBQUANT();
|
||||
const int64_t N = 128, K = 512, M = 8;
|
||||
auto check = [&](const char* dtype, int64_t group, const Hooks& hk,
|
||||
const std::vector<const char*>& bscale_roles, Opts qo) {
|
||||
const std::vector<float> w = weight(N, K, 21, 1, group);
|
||||
const Quantised q = quantise(quantizer("rtn"), qo, "output.weight", N, K, w);
|
||||
if (q.status != RAD_OK) {
|
||||
CHECK_EQ(q.status, RAD_OK);
|
||||
return;
|
||||
}
|
||||
Opts kp;
|
||||
kp.i("N", N).i("K", K);
|
||||
rad::Geometry g;
|
||||
g.set_i("M", M); g.set_i("N", N); g.set_i("K", K); g.set_i("group", group);
|
||||
g.set_s("dtype", dtype);
|
||||
std::vector<rad::OpdShape> tab;
|
||||
if (rad::rad_operand_shapes("gemm_nt_q", g, 7, M, &tab) != RAD_OK) {
|
||||
std::fprintf(stderr, " %s: the table refuses the geometry\n", dtype);
|
||||
CHECK(false);
|
||||
return;
|
||||
}
|
||||
CHECK_EQ((int)tab.size(), 7);
|
||||
struct P { int operand; size_t opd; std::vector<const char*> roles; };
|
||||
const std::vector<P> ops = { { B, 2, { "codes" } }, { BSCALE, 3, bscale_roles } };
|
||||
for (const P& o : ops) {
|
||||
const Selection s = select(q, N, K, o.roles);
|
||||
RadLayout L{};
|
||||
CHECK_EQ(hk.layout(kp.data(), kp.n(), o.operand, &q.enc, s.sel.data(), s.t.data(),
|
||||
(int)s.t.size(), &L), RAD_OK);
|
||||
const rad::OpdShape& t = tab[o.opd];
|
||||
const int64_t got = t.absent ? 0 : rad_dtype_bytes(t.dtype, rad::rad_numel(t.shape));
|
||||
if (got != (int64_t)L.bytes)
|
||||
std::fprintf(stderr, " %s operand %d: the table sizes %lld byte(s), the kernel "
|
||||
"stores %lld\n", dtype, o.operand, (long long)got,
|
||||
(long long)L.bytes);
|
||||
CHECK_EQ(got, (int64_t)L.bytes);
|
||||
}
|
||||
};
|
||||
{
|
||||
Opts qo;
|
||||
qo.s("codes", "u2").s("zero", "u8").i("group", 128).s("scale", "f16");
|
||||
check("w2a8", 128, nW2, { "scale", "zero" }, qo);
|
||||
}
|
||||
{
|
||||
Opts qo;
|
||||
qo.s("codes", "fp4_e2m1").i("group", 32).s("scale", "e8m0");
|
||||
check("mxfp4a8", 32, nMx, { "scale" }, qo);
|
||||
}
|
||||
/* The guards are the kernel's own: K a whole number of 128-column blocks
|
||||
* (r4d_layout.cpp refuses a weight whose K is not), N a whole number of 16-row tiles (the
|
||||
* row's constraint), and the group the stored form has. A geometry the kernel would refuse has
|
||||
* to be refused here too, or rad-tune would size buffers for a launch that never happens. */
|
||||
auto refuses = [&](int64_t n, int64_t k, int64_t group) {
|
||||
rad::Geometry g;
|
||||
g.set_i("M", M); g.set_i("N", n); g.set_i("K", k); g.set_i("group", group);
|
||||
g.set_s("dtype", "w2a8");
|
||||
std::vector<rad::OpdShape> tab;
|
||||
CHECK_EQ(rad::rad_operand_shapes("gemm_nt_q", g, 7, M, &tab), RAD_E_UNSUPPORTED);
|
||||
};
|
||||
refuses(128, 500, 128); /* K leaves a partial block */
|
||||
refuses(120, 512, 128); /* N leaves a partial tile */
|
||||
refuses(128, 512, 64); /* a group the stored form does not have */
|
||||
/* The shape the DFlash2 draft head tunes at on a two-rank serve, which the kernel takes. */
|
||||
{
|
||||
rad::Geometry g;
|
||||
g.set_i("M", M); g.set_i("N", 124160); g.set_i("K", 2560); g.set_i("group", 128);
|
||||
g.set_s("dtype", "w2a8");
|
||||
std::vector<rad::OpdShape> tab;
|
||||
CHECK_EQ(rad::rad_operand_shapes("gemm_nt_q", g, 7, M, &tab), RAD_OK);
|
||||
CHECK_EQ((int)tab.size(), 7);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(moe_int4_experts_plain_and_rotated_both_classes) {
|
||||
NEED_LIBQUANT();
|
||||
const int64_t N = 64, K = 256, N1 = 48, K1 = 128;
|
||||
|
||||
@@ -996,6 +996,26 @@ TEST(an_op_outside_the_window_on_lane_0_joins_the_second_lane_first) {
|
||||
}));
|
||||
}
|
||||
|
||||
/* An op that names no buffer -- a weight read into the cache (prefetch_beside) -- touches nothing the
|
||||
* window keeps live, so on lane 1 it runs outside the window too (a drafter's reads beside its
|
||||
* all-reduces come after the trunk's window). */
|
||||
TEST(an_op_naming_no_buffer_runs_on_the_second_lane_outside_its_window) {
|
||||
Fixture f;
|
||||
f.P.scratch_regions = 2;
|
||||
rad_weight w = f.add_weight("blk.0.w", RAD_BF16, 8, 4, g_weight_bytes);
|
||||
rad_op a0 = f.add_op("gemm_nt", "M", { 8192 }, { k_scr_seen0 }, { "s0" }, nullptr, {});
|
||||
rad_op a1 = f.add_op("gemm_nt", "M", { 8192 }, { k_scr_seen1 }, { "s1" }, nullptr, { w });
|
||||
f.P.lane1_w0 = f.P.lane1_w1 = (int32_t)a0;
|
||||
CHECK_OK(f.start());
|
||||
|
||||
CHECK_OK(f.step(4, 0, [&](Ctx& c) {
|
||||
RadOperand opd[1] = { RAD_W(w) };
|
||||
CHECK_OK(c.set_lane(1));
|
||||
CHECK_OK(c.issue(a1, opd, 1, RAD_N_BATCH));
|
||||
CHECK_OK(c.set_lane(0));
|
||||
}));
|
||||
}
|
||||
|
||||
/* Operands are positional (spec §2.3), so a miscount is silent numerical garbage at the kernel,
|
||||
* not a diagnosable failure. The runtime checks the given arity against the schema. */
|
||||
TEST(operand_arity_is_checked_against_the_schema) {
|
||||
|
||||
@@ -5733,8 +5733,8 @@ uint64_t scripted_steps(int64_t max_tok, int64_t interval, int64_t busy, int* n_
|
||||
TEST(without_a_span_the_scheduler_plans_and_stages_the_pinned_steps) {
|
||||
struct Case { int64_t max_tok, interval, busy; uint64_t want; };
|
||||
const Case cases[] = {
|
||||
{ 256, 256, -1, 0x17b8231a20db9d46ull }, { 512, 256, -1, 0xe155e72b6a4cc94full }, { 1024, 256, -1, 0x54ba52dac3f4f61cull },
|
||||
{ 1024, 256, 0, 0x54ba52dac3f4f61cull }, { 1024, 256, 128, 0x3d9cbbf533e3c4b5ull }, { 2048, 512, -1, 0x400205b7b9afcf12ull },
|
||||
{ 256, 256, -1, 0x9b2fe92b1919355cull }, { 512, 256, -1, 0xdae73489249b5339ull }, { 1024, 256, -1, 0x44975a352e78619aull },
|
||||
{ 1024, 256, 0, 0x44975a352e78619aull }, { 1024, 256, 128, 0x3c0b9b1a1f864e4aull }, { 2048, 512, -1, 0xd6c184d0563159eeull },
|
||||
};
|
||||
for (const Case& c : cases) {
|
||||
int n = 0;
|
||||
|
||||
Reference in new issue
Block a user