Archived
scripts/sycl/probe.sh builds and runs two probes on the Arc Pro B65 (Level Zero, xe driver): the device's limits and joint_matrix combinations, and an ESIMD DPAS check of E4M3 / E5M2 against bf16 and s8 controls in the same harness. bf16, fp16, s8 and tf32 XMX are exact; fp8 DPAS compiles for bmg-g31 but returns garbage, so fp8 weights are widened to bf16 in-register (exact for E4M3). docs/SYCL_PROGRESS.md is the resume log: device tables, the host baseline (82/88 of -LE 'gpu|oot'; the six failures are FFmpeg-less builds and CPU-time budgets on this VM), BetterBench setup, the model library survey and the open blockers (no MiniCPM5 container in the library, no ROCm here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
129 lines
6.1 KiB
C++
129 lines
6.1 KiB
C++
// Does Xe2 (BMG) XMX execute FP8 DPAS? One ESIMD work-item does C[8x16] = A[8x32] * B[32x16]
|
|
// with A and B as E4M3 (hf8) or E5M2 (bf8) bytes, checked against a host reference. A bf16
|
|
// DPAS of the same values (K=16, two halves) runs first as a control.
|
|
#include <sycl/sycl.hpp>
|
|
#include <sycl/ext/intel/esimd.hpp>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <vector>
|
|
|
|
using namespace sycl::ext::intel::esimd;
|
|
namespace xmx = sycl::ext::intel::esimd::xmx;
|
|
|
|
constexpr int M = 8, N = 16, K = 32;
|
|
|
|
static uint8_t enc(float v, int ebits) { // exact values only
|
|
int mbits = 7 - ebits, bias = (1 << (ebits - 1)) - 1;
|
|
if (v == 0) return 0;
|
|
uint8_t s = v < 0 ? 0x80 : 0;
|
|
float a = std::fabs(v);
|
|
int e = int(std::floor(std::log2(a)));
|
|
int m = int(std::lround((a / std::ldexp(1.f, e) - 1.f) * (1 << mbits)));
|
|
return s | uint8_t((e + bias) << mbits) | uint8_t(m);
|
|
}
|
|
|
|
template <xmx::dpas_argument_type P>
|
|
static void run(sycl::queue &q, const char *name, int ebits) {
|
|
std::vector<float> af(M * K), bf(K * N);
|
|
const float vals[] = {-2, -1.5f, -1, -0.5f, 0, 0.5f, 1, 1.5f, 2};
|
|
for (int i = 0; i < M * K; i++) af[i] = vals[(i * 7 + 3) % 9];
|
|
for (int i = 0; i < K * N; i++) bf[i] = vals[(i * 5 + 1) % 9];
|
|
std::vector<uint8_t> a8(M * K), b8(K * N);
|
|
for (int i = 0; i < M * K; i++) a8[i] = enc(af[i], ebits);
|
|
for (int k = 0; k < K; k++) // VNNI: [K/4][N][4]
|
|
for (int n = 0; n < N; n++) b8[(k / 4) * N * 4 + n * 4 + (k % 4)] = enc(bf[k * N + n], ebits);
|
|
std::vector<double> ref(M * N, 0);
|
|
for (int m = 0; m < M; m++)
|
|
for (int n = 0; n < N; n++)
|
|
for (int k = 0; k < K; k++) ref[m * N + n] += af[m * K + k] * bf[k * N + n];
|
|
|
|
uint8_t *da = sycl::malloc_device<uint8_t>(M * K, q), *db = sycl::malloc_device<uint8_t>(K * N, q);
|
|
float *dc = sycl::malloc_device<float>(M * N, q);
|
|
q.memcpy(da, a8.data(), M * K).wait();
|
|
q.memcpy(db, b8.data(), K * N).wait();
|
|
try {
|
|
q.parallel_for(sycl::range<1>{1}, [=](sycl::id<1>) SYCL_ESIMD_KERNEL {
|
|
simd<uint8_t, M * K> A = block_load<uint8_t, M * K>(da);
|
|
simd<uint8_t, K * N> B = block_load<uint8_t, K * N>(db);
|
|
simd<float, M * N> C = 0;
|
|
C = xmx::dpas<8, M, float, float, uint8_t, uint8_t, P, P>(C, B, A);
|
|
block_store<float, M * N>(dc, C);
|
|
}).wait_and_throw();
|
|
} catch (sycl::exception &e) {
|
|
printf("%-6s DPAS FAILED: %s\n", name, e.what());
|
|
return;
|
|
}
|
|
std::vector<float> c(M * N);
|
|
q.memcpy(c.data(), dc, sizeof(float) * M * N).wait();
|
|
double err = 0;
|
|
for (int i = 0; i < M * N; i++) err = std::fmax(err, std::fabs(c[i] - ref[i]));
|
|
printf("%-6s DPAS M8 N16 K32 -> f32: max|err| = %g (c[0]=%g ref=%g)\n", name, err, c[0], ref[0]);
|
|
sycl::free(da, q); sycl::free(db, q); sycl::free(dc, q);
|
|
}
|
|
|
|
// Controls with the same harness: bf16 (K=16, VNNI pairs) -> f32 and s8 (K=32) -> s32.
|
|
static void ctl_bf16(sycl::queue &q) {
|
|
using bf = sycl::ext::oneapi::bfloat16;
|
|
constexpr int KB = 16;
|
|
const float vals[] = {-2, -1.5f, -1, -0.5f, 0, 0.5f, 1, 1.5f, 2};
|
|
std::vector<bf> a(M * KB), b(KB * N);
|
|
std::vector<double> ref(M * N, 0);
|
|
for (int i = 0; i < M * KB; i++) a[i] = vals[(i * 7 + 3) % 9];
|
|
std::vector<float> bfv(KB * N);
|
|
for (int i = 0; i < KB * N; i++) bfv[i] = vals[(i * 5 + 1) % 9];
|
|
for (int k = 0; k < KB; k++)
|
|
for (int n = 0; n < N; n++) b[(k / 2) * N * 2 + n * 2 + (k % 2)] = bfv[k * N + n];
|
|
for (int m = 0; m < M; m++) for (int n = 0; n < N; n++) for (int k = 0; k < KB; k++)
|
|
ref[m * N + n] += float(a[m * KB + k]) * bfv[k * N + n];
|
|
bf *da = sycl::malloc_device<bf>(M * KB, q), *db = sycl::malloc_device<bf>(KB * N, q);
|
|
float *dc = sycl::malloc_device<float>(M * N, q);
|
|
q.memcpy(da, a.data(), sizeof(bf) * M * KB).wait();
|
|
q.memcpy(db, b.data(), sizeof(bf) * KB * N).wait();
|
|
q.parallel_for(sycl::range<1>{1}, [=](sycl::id<1>) SYCL_ESIMD_KERNEL {
|
|
simd<bf, M * KB> A = block_load<bf, M * KB>(da);
|
|
simd<bf, KB * N> B = block_load<bf, KB * N>(db);
|
|
simd<float, M * N> C = 0;
|
|
C = xmx::dpas<8, M, float, float, bf, bf>(C, B, A);
|
|
block_store<float, M * N>(dc, C);
|
|
}).wait();
|
|
std::vector<float> c(M * N);
|
|
q.memcpy(c.data(), dc, sizeof(float) * M * N).wait();
|
|
double err = 0;
|
|
for (int i = 0; i < M * N; i++) err = std::fmax(err, std::fabs(c[i] - ref[i]));
|
|
printf("bf16 DPAS M8 N16 K16 -> f32: max|err| = %g (c[0]=%g ref=%g)\n", err, c[0], ref[0]);
|
|
}
|
|
static void ctl_s8(sycl::queue &q) {
|
|
std::vector<int8_t> a(M * K), b(K * N);
|
|
std::vector<int> bv(K * N); std::vector<long> ref(M * N, 0);
|
|
for (int i = 0; i < M * K; i++) a[i] = int8_t((i * 7 + 3) % 9 - 4);
|
|
for (int i = 0; i < K * N; i++) bv[i] = (i * 5 + 1) % 9 - 4;
|
|
for (int k = 0; k < K; k++) for (int n = 0; n < N; n++) b[(k / 4) * N * 4 + n * 4 + (k % 4)] = int8_t(bv[k * N + n]);
|
|
for (int m = 0; m < M; m++) for (int n = 0; n < N; n++) for (int k = 0; k < K; k++) ref[m * N + n] += a[m * K + k] * bv[k * N + n];
|
|
int8_t *da = sycl::malloc_device<int8_t>(M * K, q), *db = sycl::malloc_device<int8_t>(K * N, q);
|
|
int *dc = sycl::malloc_device<int>(M * N, q);
|
|
q.memcpy(da, a.data(), M * K).wait();
|
|
q.memcpy(db, b.data(), K * N).wait();
|
|
q.parallel_for(sycl::range<1>{1}, [=](sycl::id<1>) SYCL_ESIMD_KERNEL {
|
|
simd<int8_t, M * K> A = block_load<int8_t, M * K>(da);
|
|
simd<int8_t, K * N> B = block_load<int8_t, K * N>(db);
|
|
simd<int, M * N> C = 0;
|
|
C = xmx::dpas<8, M, int, int, int8_t, int8_t>(C, B, A);
|
|
block_store<int, M * N>(dc, C);
|
|
}).wait();
|
|
std::vector<int> c(M * N);
|
|
q.memcpy(c.data(), dc, sizeof(int) * M * N).wait();
|
|
long err = 0;
|
|
for (int i = 0; i < M * N; i++) err = std::max(err, std::labs(c[i] - ref[i]));
|
|
printf("s8 DPAS M8 N16 K32 -> s32: max|err| = %ld (c[0]=%d ref=%ld)\n", err, c[0], ref[0]);
|
|
}
|
|
|
|
int main() {
|
|
sycl::queue q{sycl::gpu_selector_v};
|
|
printf("device: %s\n", q.get_device().get_info<sycl::info::device::name>().c_str());
|
|
run<xmx::dpas_argument_type::hf8>(q, "e4m3", 4);
|
|
run<xmx::dpas_argument_type::bf8>(q, "e5m2", 5);
|
|
ctl_bf16(q);
|
|
ctl_s8(q);
|
|
return 0;
|
|
}
|