Archived
libxe2: the m2xfp4 verify GEMM in ESIMD -- gate_up 403 -> 256 us at M=8
A thread owns 16 columns as [word][lane] registers, so a decoded weight pair is one SIMD32 fp16 multiply instead of SIMT's ~10 instructions; the step's activation blocks load with the code lines, so no DPAS waits on its own A load. rad-kbench against libref 50/50; greedy output identical. XE2_M2_SIMT=1 keeps the SIMT kernel. 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
5010e1d083
commit
fc1f2bba59
2 files changed
+179
-2
No files matched your search
+18
-2
@@ -316,6 +316,16 @@ int launch_dpas_raw(sycl::queue& q, const half* at, const uint8_t* codes0, const
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/* xe2_gemv_m2_esimd.cpp: launch_dpas_raw's arithmetic in ESIMD, the activation as [c / 16][m][c % 16] */
|
||||
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);
|
||||
|
||||
namespace {
|
||||
|
||||
int m2_dpas(sycl::queue& q, const RadTensor* A, const RadTensor* AS, const uint8_t* codes0,
|
||||
const uint8_t* meta0, const uint8_t* expe0, int64_t brs, const RadTensor* Y, int64_t M,
|
||||
int64_t N, int64_t K, int64_t acols, int64_t scols, int64_t ars, int64_t srs, int64_t yrs,
|
||||
@@ -328,6 +338,9 @@ int m2_dpas(sycl::queue& q, const RadTensor* A, const RadTensor* AS, const uint8
|
||||
const int64_t ntile = (N + 127) / 128, ldp = ntile * 128;
|
||||
constexpr int64_t kFill = 160;
|
||||
const int splits = (int)std::min<int64_t>(std::max<int64_t>(1, (kFill + ntile - 1) / ntile), std::max<int64_t>(1, kg / kKs));
|
||||
/* the ESIMD form of the register kernel unless XE2_M2_SIMT=1; it stores f32 and bf16 itself */
|
||||
static const bool simt = std::getenv("XE2_M2_SIMT") != nullptr;
|
||||
const bool es = raw && !simt && (splits > 1 || Y->dtype == RAD_F32 || Y->dtype == RAD_BF16);
|
||||
const int64_t abytes = (mpad * acols * 2 + 255) / 256 * 256, rbytes = (mpad * 4 + 255) / 256 * 256;
|
||||
float* ws = workspace(q, (size_t)((abytes + rbytes + N * 4) / 4 + 64));
|
||||
float* pbuf = workspace(q, (size_t)(splits * mpad * ldp), 2);
|
||||
@@ -354,7 +367,7 @@ int m2_dpas(sycl::queue& q, const RadTensor* A, const RadTensor* AS, const uint8
|
||||
const float f = 1.0f / R;
|
||||
for (int64_t c = ch * cspan + t; c < sycl::min(acols, (ch + 1) * cspan); c += 256) {
|
||||
const int64_t p = c & 7, src = (c & ~(int64_t)7) + (p >> 1) + 4 * (p & 1);
|
||||
a16[raw ? c * mpad + m : m * acols + c] =
|
||||
a16[es ? ((c >> 4) * mpad + m) * 16 + (c & 15) : raw ? c * mpad + m : m * acols + c] =
|
||||
m < M ? (half)(e4m3(ab[m * ars + src]) * rad_load_f32(sab, sadt, m * srs + src / 128) * f)
|
||||
: (half)0.0f;
|
||||
}
|
||||
@@ -376,7 +389,10 @@ int m2_dpas(sycl::queue& q, const RadTensor* A, const RadTensor* AS, const uint8
|
||||
if (rc < 0) return rc;
|
||||
char* yb = (char*)Y->data;
|
||||
const uint32_t ydt = Y->dtype;
|
||||
if (raw)
|
||||
if (es)
|
||||
rc = m2_esimd(q, mt, a16, codes0, meta0, expe0, emax, brs, pbuf, N, K, e1, e2, mpad, splits, rr, yb, ydt,
|
||||
yrs, ycs, (int)M, ldp);
|
||||
else if (raw)
|
||||
rc = mt == 1 ? launch_dpas_raw<1, 1>(q, a16, codes0, meta0, expe0, brs, pbuf, N, K, e1, e2, mpad, splits,
|
||||
rr, yb, ydt, yrs, ycs, (int)M)
|
||||
: launch_dpas_raw<2, 1>(q, a16, codes0, meta0, expe0, brs, pbuf, N, K, e1, e2, mpad, splits,
|
||||
|
||||
Reference in new issue
Block a user