Archived
libxe2: the verify GEMM's e_max in the prepass launch -- down 156 -> 142 us at M=8
The per-column largest exponent was a kernel of its own for split-K shapes (7.8 us a launch, 260 a round) and an in-kernel scan otherwise; extra work-groups of the activation prepass now form it and the ESIMD kernel gathers it. rad-kbench against libref 50/50; greedy output identical. 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
ef6c6e13fa
commit
36b8941096
2 files changed
+25
-27
No files matched your search
+23
-16
@@ -351,13 +351,33 @@ int m2_dpas(sycl::queue& q, const RadTensor* A, const RadTensor* AS, const uint8
|
||||
const uint8_t* ab = (const uint8_t*)A->data;
|
||||
const char* sab = (const char*)AS->data;
|
||||
const uint32_t sadt = AS->dtype;
|
||||
/* the activation prepass: a work-group a (row, 2048 columns), each forming the row's factor */
|
||||
/* the activation prepass: a work-group a (row, 2048 columns), each forming the row's factor;
|
||||
* in the same launch, when a kernel below reads it, each column's largest exponent (further
|
||||
* work-groups, 256 columns each) -- a launch of its own cost more than its work */
|
||||
const int64_t chunks = raw ? (acols + 2047) / 2048 : 1;
|
||||
const int64_t cspan = raw ? 2048 : acols;
|
||||
const bool want_emax = es || !(raw && splits == 1);
|
||||
const int64_t agroups = mpad * chunks, egroups = want_emax ? (N + 255) / 256 : 0;
|
||||
int rc = submit([&] {
|
||||
q.parallel_for(sycl::nd_range<1>{(size_t)(mpad * chunks) * 256, 256}, [=](sycl::nd_item<1> it) {
|
||||
const int64_t m = (int64_t)it.get_group(0) / chunks, ch = (int64_t)it.get_group(0) % chunks;
|
||||
q.parallel_for(sycl::nd_range<1>{(size_t)(agroups + egroups) * 256, 256}, [=](sycl::nd_item<1> it) {
|
||||
const int64_t gi = (int64_t)it.get_group(0);
|
||||
const int64_t t = (int64_t)it.get_local_id(0);
|
||||
if (gi >= agroups) { /* uniform over the work-group */
|
||||
const int64_t n = (gi - agroups) * 256 + t;
|
||||
if (n >= N) return;
|
||||
const uint8_t* er = expe0 + n * brs;
|
||||
int32_t mx = 0;
|
||||
int64_t g = 0;
|
||||
if ((kb & 15) == 0 && ((uintptr_t)er & 15) == 0)
|
||||
for (; g < kb; g += 16) {
|
||||
const sycl::vec<uint8_t, 16> ev = *(const sycl::vec<uint8_t, 16>*)(er + g);
|
||||
for (int u = 0; u < 16; ++u) mx = sycl::max(mx, (int32_t)ev[u]);
|
||||
}
|
||||
for (; g < kb; ++g) mx = sycl::max(mx, (int32_t)er[g]);
|
||||
emax[n] = mx;
|
||||
return;
|
||||
}
|
||||
const int64_t m = gi / chunks, ch = gi % chunks;
|
||||
float mx = 0.0f;
|
||||
if (m < M)
|
||||
for (int64_t c = t; c < scols; c += 256) mx = sycl::fmax(mx, rad_load_f32(sab, sadt, m * srs + c));
|
||||
@@ -372,19 +392,6 @@ int m2_dpas(sycl::queue& q, const RadTensor* A, const RadTensor* AS, const uint8
|
||||
: (half)0.0f;
|
||||
}
|
||||
});
|
||||
if (raw && splits == 1) return; /* the register form reads e_max itself */
|
||||
q.parallel_for(sycl::range<1>((size_t)N), [=](sycl::id<1> i) {
|
||||
const uint8_t* er = expe0 + (int64_t)i[0] * brs;
|
||||
int32_t mx = 0;
|
||||
int64_t g = 0;
|
||||
if ((kb & 15) == 0 && ((uintptr_t)er & 15) == 0)
|
||||
for (; g < kb; g += 16) {
|
||||
const sycl::vec<uint8_t, 16> ev = *(const sycl::vec<uint8_t, 16>*)(er + g);
|
||||
for (int u = 0; u < 16; ++u) mx = sycl::max(mx, (int32_t)ev[u]);
|
||||
}
|
||||
for (; g < kb; ++g) mx = sycl::max(mx, (int32_t)er[g]);
|
||||
emax[i[0]] = mx;
|
||||
});
|
||||
});
|
||||
if (rc < 0) return rc;
|
||||
char* yb = (char*)Y->data;
|
||||
|
||||
@@ -55,17 +55,8 @@ int launch(sycl::queue& q, const half* ae, const uint8_t* codes0, const uint8_t*
|
||||
const simd<uint32_t, 16> coff = (col - (uint32_t)n0) * (uint32_t)(K / 2);
|
||||
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: read here when this thread has the whole K, else the
|
||||
* caller's emax pass */
|
||||
simd<int32_t, 16> mx = 0;
|
||||
if (splits == 1) {
|
||||
for (int64_t g = 0; g < kg; g += 4) {
|
||||
const simd<uint32_t, 16> e = gather<uint32_t, 16>((const uint32_t*)(expe0 + g), eoff);
|
||||
_Pragma("unroll") for (int b = 0; b < 4; ++b) mx = max(mx, simd<int32_t, 16>((e >> (8 * b)) & 0xFF));
|
||||
}
|
||||
} else {
|
||||
mx = gather<int32_t, 16>(emax, col * 4u);
|
||||
}
|
||||
/* the column's largest exponent, from the caller's prepass */
|
||||
const simd<int32_t, 16> mx = gather<int32_t, 16>(emax, col * 4u);
|
||||
simd<float, 128> c[MT];
|
||||
_Pragma("unroll") for (int i = 0; i < MT; ++i) c[i] = 0.0f;
|
||||
for (int64_t g0 = g0s; g0 < g1s; g0 += kKs) {
|
||||
|
||||
Reference in new issue
Block a user