Archived
libxe2: m2xfp4 codes stored tiled at load -- the verify GEMM's step one block load, gate_up 240 -> 222 us
Where N % 16 == 0 and K % 128 == 0 the layout hook asks for "xe2.m2.tiled16": a 16-column tile's 128-column step is 1 KiB, dword w of its columns side by side, the ESIMD kernel's [word][lane] registers as they lie (four block loads in place of four d32x4 gathers). M = 1 goes to the same kernel when tiled. Every m2 reader in libxe2 (exact, SIMT GEMV, jm and SIMT DPAS forms, prefill decode) reads the tiled form; unrelayout inverts it for the oracle. rad-kbench against libref: 70 checked, 70 passed (worst rel_l2 1.2e-3). M = 8: gate_up 240 -> 222, down 140 -> 119, N=1024 50 -> 25 us. Greedy output identical (8 prompts x 64 tokens); 512-token decode 31.8 -> 33.3 tok/s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
1 parent
2a764d2d38
commit
68d510b1f4
4 files changed
+107
-37
No files matched your search
@@ -10,7 +10,8 @@
|
||||
*
|
||||
* Layout: a thread 16 output columns, lane = column, as the SIMT kernel's sub-group. Its codes are
|
||||
* read 16 bytes a lane at a time (LSC d32x4 gathers, [dword][lane] in registers), so a word of 8
|
||||
* nibbles is one register across the 16 columns. The activation is ae[(c / 16) * mpad + m][c % 16]
|
||||
* nibbles is one register across the 16 columns -- or, stored tiled (xe2_ops.h, m2_tiled), a step's
|
||||
* 1 KiB already in that order, four block loads. The activation is ae[(c / 16) * mpad + m][c % 16]
|
||||
* (c the permuted column of xe2_gemv_m2.cpp's prepass, m the row): a DPAS A operand of 8 rows by 16
|
||||
* k is one 256-byte block load. Results: y directly (f32 / bf16) when the whole K is one thread's,
|
||||
* else partial sums into pbuf for the caller's reduction, exactly as launch_dpas_raw does. */
|
||||
@@ -28,7 +29,7 @@ using half = sycl::half;
|
||||
|
||||
constexpr int kKs = 4; /* 32-groups a step: 64 bytes of a column's codes */
|
||||
|
||||
template <int MT>
|
||||
template <int MT, bool TL>
|
||||
int launch(sycl::queue& q, const half* ae, const uint8_t* codes0, const uint8_t* meta0,
|
||||
const uint8_t* expe0, const int32_t* emax, int64_t brs, float* pbuf, int64_t N, int64_t K,
|
||||
int64_t e1, int64_t e2, int64_t mpad, int splits, const float* rr, char* yb, uint32_t ydt,
|
||||
@@ -53,6 +54,7 @@ int launch(sycl::queue& q, const half* ae, const uint8_t* codes0, const uint8_t*
|
||||
col.merge(simd<uint32_t, 16>((uint32_t)(N - 1)), col > (uint32_t)(N - 1));
|
||||
const uint8_t* cbase = codes0 + n0 * (K / 2);
|
||||
const simd<uint32_t, 16> coff = (col - (uint32_t)n0) * (uint32_t)(K / 2);
|
||||
const uint32_t* tbase = (const uint32_t*)codes0 + tile * (kg / 4) * 256; /* TL: the tile's steps */
|
||||
const simd<uint32_t, 16> eoff = col * (uint32_t)brs;
|
||||
const simd<uint32_t, 16> moff = col * (uint32_t)kg;
|
||||
/* the column's largest exponent, from the caller's prepass */
|
||||
@@ -62,9 +64,14 @@ int launch(sycl::queue& q, const half* ae, const uint8_t* codes0, const uint8_t*
|
||||
/* a step: kKs groups -- the code lines, the activation blocks, the decode and DPAS */
|
||||
auto step = [&](int64_t g0, simd<uint32_t, 16> e4, simd<uint32_t, 16> m4) SYCL_ESIMD_FUNCTION {
|
||||
simd<uint32_t, 256> line; /* [word 16][lane 16] */
|
||||
_Pragma("unroll") for (int qd = 0; qd < 4; ++qd)
|
||||
line.template select<64, 1>(qd * 64) =
|
||||
gather<uint32_t, 64, 4>((const uint32_t*)(cbase + g0 * 16 + qd * 16), coff);
|
||||
if constexpr (TL) { /* tiled: the step is these 1 KiB as they lie */
|
||||
_Pragma("unroll") for (int qd = 0; qd < 4; ++qd)
|
||||
line.template select<64, 1>(qd * 64) = block_load<uint32_t, 64>(tbase + (g0 / kKs) * 256 + qd * 64);
|
||||
} else {
|
||||
_Pragma("unroll") for (int qd = 0; qd < 4; ++qd)
|
||||
line.template select<64, 1>(qd * 64) =
|
||||
gather<uint32_t, 64, 4>((const uint32_t*)(cbase + g0 * 16 + qd * 16), coff);
|
||||
}
|
||||
/* the step's activation, 8 k-blocks of [mpad rows][16 k], loaded with the codes */
|
||||
simd<half, kKs * 2 * MT * 128> As;
|
||||
_Pragma("unroll") for (int b = 0; b < kKs * 2 * MT; ++b)
|
||||
@@ -154,11 +161,16 @@ int launch(sycl::queue& q, const half* ae, const uint8_t* codes0, const uint8_t*
|
||||
int m2_esimd(sycl::queue& q, int mt, const half* ae, const uint8_t* codes0, const uint8_t* meta0,
|
||||
const uint8_t* expe0, const int32_t* emax, int64_t brs, float* pbuf, int64_t N, int64_t K,
|
||||
int64_t e1, int64_t e2, int64_t mpad, int splits, const float* rr, char* yb, uint32_t ydt,
|
||||
int64_t yrs, int64_t ycs, int mm, int64_t ldp) {
|
||||
return mt == 1 ? launch<1>(q, ae, codes0, meta0, expe0, emax, brs, pbuf, N, K, e1, e2, mpad, splits, rr, yb,
|
||||
ydt, yrs, ycs, mm, ldp)
|
||||
: launch<2>(q, ae, codes0, meta0, expe0, emax, brs, pbuf, N, K, e1, e2, mpad, splits, rr, yb,
|
||||
ydt, yrs, ycs, mm, ldp);
|
||||
int64_t yrs, int64_t ycs, int mm, int64_t ldp, bool tl) {
|
||||
auto go = [&](auto mt_, auto tl_) {
|
||||
return launch<decltype(mt_)::value, decltype(tl_)::value>(q, ae, codes0, meta0, expe0, emax, brs, pbuf, N, K,
|
||||
e1, e2, mpad, splits, rr, yb, ydt, yrs, ycs, mm, ldp);
|
||||
};
|
||||
using T = std::true_type;
|
||||
using F = std::false_type;
|
||||
using M1 = std::integral_constant<int, 1>;
|
||||
using M2 = std::integral_constant<int, 2>;
|
||||
return mt == 1 ? (tl ? go(M1{}, T{}) : go(M1{}, F{})) : (tl ? go(M2{}, T{}) : go(M2{}, F{}));
|
||||
}
|
||||
|
||||
} // namespace xe2
|
||||
Reference in new issue
Block a user