Archived
sycl: Phase 0 of the Intel backend -- the B65's limits and XMX types, the host baseline
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
This commit is contained in:
1 parent
9eaf10da6e
commit
c25f610fda
4 files changed
+439
No files matched your search
@@ -0,0 +1,111 @@
|
||||
// Phase 0 device probe: limits, aspects, sub-groups, joint_matrix combinations, and a
|
||||
// numerical check of which XMX element types actually execute on the device.
|
||||
#include <sycl/sycl.hpp>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace syclex = sycl::ext::oneapi::experimental;
|
||||
namespace jm = sycl::ext::oneapi::experimental::matrix;
|
||||
|
||||
static const char *mt(jm::matrix_type t) {
|
||||
switch (t) {
|
||||
case jm::matrix_type::bf16: return "bf16";
|
||||
case jm::matrix_type::fp16: return "fp16";
|
||||
case jm::matrix_type::tf32: return "tf32";
|
||||
case jm::matrix_type::fp32: return "fp32";
|
||||
case jm::matrix_type::fp64: return "fp64";
|
||||
case jm::matrix_type::sint8: return "s8";
|
||||
case jm::matrix_type::uint8: return "u8";
|
||||
case jm::matrix_type::sint32: return "s32";
|
||||
case jm::matrix_type::uint32: return "u32";
|
||||
default: return "other";
|
||||
}
|
||||
}
|
||||
|
||||
// One sub-group computes C[M x N] = A[M x K] * B[K x N] with joint_matrix, compared with a host loop.
|
||||
template <typename Ta, typename Tc, size_t M, size_t N, size_t K>
|
||||
static double jm_test(sycl::queue &q, const char *name) {
|
||||
std::vector<Ta> a(M * K), b(K * N);
|
||||
std::vector<Tc> c(M * N, 0);
|
||||
std::vector<double> ref(M * N, 0);
|
||||
for (size_t i = 0; i < M * K; i++) a[i] = Ta(float(int(i * 7 % 11) - 5) * 0.25f);
|
||||
for (size_t i = 0; i < K * N; i++) b[i] = Ta(float(int(i * 5 % 13) - 6) * 0.5f);
|
||||
for (size_t m = 0; m < M; m++)
|
||||
for (size_t n = 0; n < N; n++)
|
||||
for (size_t k = 0; k < K; k++) ref[m * N + n] += double(float(a[m * K + k])) * double(float(b[k * N + n]));
|
||||
Ta *da = sycl::malloc_device<Ta>(M * K, q), *db = sycl::malloc_device<Ta>(K * N, q);
|
||||
Tc *dc = sycl::malloc_device<Tc>(M * N, q);
|
||||
q.memcpy(da, a.data(), sizeof(Ta) * M * K);
|
||||
q.memcpy(db, b.data(), sizeof(Ta) * K * N);
|
||||
q.memset(dc, 0, sizeof(Tc) * M * N).wait();
|
||||
try {
|
||||
q.parallel_for(sycl::nd_range<1>{16, 16}, [=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(16)]] {
|
||||
auto sg = it.get_sub_group();
|
||||
jm::joint_matrix<sycl::sub_group, Ta, jm::use::a, M, K, jm::layout::row_major> ma;
|
||||
jm::joint_matrix<sycl::sub_group, Ta, jm::use::b, K, N, jm::layout::row_major> mb;
|
||||
jm::joint_matrix<sycl::sub_group, Tc, jm::use::accumulator, M, N> mc;
|
||||
jm::joint_matrix_fill(sg, mc, Tc(0));
|
||||
auto pa = sycl::address_space_cast<sycl::access::address_space::global_space, sycl::access::decorated::no>(da);
|
||||
auto pb = sycl::address_space_cast<sycl::access::address_space::global_space, sycl::access::decorated::no>(db);
|
||||
auto pc = sycl::address_space_cast<sycl::access::address_space::global_space, sycl::access::decorated::no>(dc);
|
||||
jm::joint_matrix_load(sg, ma, pa, K);
|
||||
jm::joint_matrix_load(sg, mb, pb, N);
|
||||
jm::joint_matrix_mad(sg, mc, ma, mb, mc);
|
||||
jm::joint_matrix_store(sg, mc, pc, N, jm::layout::row_major);
|
||||
}).wait_and_throw();
|
||||
} catch (sycl::exception &e) {
|
||||
printf(" jm %-28s FAILED: %s\n", name, e.what());
|
||||
return -1;
|
||||
}
|
||||
q.memcpy(c.data(), dc, sizeof(Tc) * M * N).wait();
|
||||
double maxerr = 0;
|
||||
for (size_t i = 0; i < M * N; i++) maxerr = std::fmax(maxerr, std::fabs(double(c[i]) - ref[i]));
|
||||
printf(" jm %-28s M%zu N%zu K%zu max|err|=%g\n", name, M, N, K, maxerr);
|
||||
sycl::free(da, q); sycl::free(db, q); sycl::free(dc, q);
|
||||
return maxerr;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};
|
||||
auto d = q.get_device();
|
||||
printf("device: %s\n", d.get_info<sycl::info::device::name>().c_str());
|
||||
printf("backend: %s driver: %s\n",
|
||||
d.get_backend() == sycl::backend::ext_oneapi_level_zero ? "level_zero" : "other",
|
||||
d.get_info<sycl::info::device::driver_version>().c_str());
|
||||
printf("max_compute_units: %u\n", d.get_info<sycl::info::device::max_compute_units>());
|
||||
printf("max_work_group_size: %zu\n", d.get_info<sycl::info::device::max_work_group_size>());
|
||||
printf("sub_group_sizes:");
|
||||
for (auto s : d.get_info<sycl::info::device::sub_group_sizes>()) printf(" %zu", s);
|
||||
printf("\nlocal_mem_size: %llu\n", (unsigned long long)d.get_info<sycl::info::device::local_mem_size>());
|
||||
printf("global_mem_size: %llu (%.2f GiB)\n", (unsigned long long)d.get_info<sycl::info::device::global_mem_size>(),
|
||||
d.get_info<sycl::info::device::global_mem_size>() / 1073741824.0);
|
||||
printf("max_mem_alloc_size: %llu (%.2f GiB)\n", (unsigned long long)d.get_info<sycl::info::device::max_mem_alloc_size>(),
|
||||
d.get_info<sycl::info::device::max_mem_alloc_size>() / 1073741824.0);
|
||||
printf("max_clock_frequency: %u MHz\n", d.get_info<sycl::info::device::max_clock_frequency>());
|
||||
printf("global_mem_cache_size: %llu\n", (unsigned long long)d.get_info<sycl::info::device::global_mem_cache_size>());
|
||||
printf("aspects: fp16=%d fp64=%d usm_device=%d usm_host=%d usm_shared=%d usm_system=%d atomic64=%d intel_matrix=%d\n",
|
||||
d.has(sycl::aspect::fp16), d.has(sycl::aspect::fp64), d.has(sycl::aspect::usm_device_allocations),
|
||||
d.has(sycl::aspect::usm_host_allocations), d.has(sycl::aspect::usm_shared_allocations),
|
||||
d.has(sycl::aspect::usm_system_allocations), d.has(sycl::aspect::atomic64),
|
||||
d.has(sycl::aspect::ext_intel_matrix));
|
||||
try {
|
||||
auto arch = d.get_info<syclex::info::device::architecture>();
|
||||
printf("architecture enum: %d (bmg_g31=%d)\n", int(arch), int(syclex::architecture::intel_gpu_bmg_g31));
|
||||
} catch (...) { printf("architecture: query failed\n"); }
|
||||
|
||||
printf("matrix_combinations:\n");
|
||||
try {
|
||||
auto combos = d.get_info<syclex::info::device::matrix_combinations>();
|
||||
for (auto &c : combos)
|
||||
printf(" A=%s B=%s C=%s D=%s M=%zu N=%zu K=%zu (max M %zu N %zu K %zu)\n", mt(c.atype), mt(c.btype),
|
||||
mt(c.ctype), mt(c.dtype), c.msize, c.nsize, c.ksize, c.max_msize, c.max_nsize, c.max_ksize);
|
||||
if (combos.empty()) printf(" (none)\n");
|
||||
} catch (sycl::exception &e) { printf(" query failed: %s\n", e.what()); }
|
||||
|
||||
printf("joint_matrix execution checks:\n");
|
||||
jm_test<sycl::ext::oneapi::bfloat16, float, 8, 16, 16>(q, "bf16 x bf16 -> f32");
|
||||
jm_test<sycl::half, float, 8, 16, 16>(q, "fp16 x fp16 -> f32");
|
||||
jm_test<int8_t, int32_t, 8, 16, 32>(q, "s8 x s8 -> s32");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// 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;
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
# probe.sh -- Phase 0 device checks for the Intel (SYCL / Level Zero) backend; see docs/SYCL_PROGRESS.md.
|
||||
# devprobe: limits, aspects, sub-group sizes, joint_matrix combinations and three joint_matrix runs
|
||||
# dpas_fp8: whether XMX executes E4M3 / E5M2 DPAS, against bf16 and s8 DPAS controls in the same harness
|
||||
# Usage: scripts/sycl/probe.sh [OUTDIR] (needs oneAPI; sources setvars.sh if icpx is not on PATH)
|
||||
set -e
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
out=${1:-${TMPDIR:-/tmp}/rad-sycl-probe}
|
||||
mkdir -p "$out"
|
||||
command -v icpx >/dev/null || . /opt/intel/oneapi/setvars.sh >/dev/null
|
||||
icpx -fsycl -O2 "$here/devprobe.cpp" -o "$out/devprobe"
|
||||
icpx -fsycl -O2 -fsycl-targets=spir64_gen -Xs "-device bmg-g31" "$here/dpas_fp8.cpp" -o "$out/dpas_fp8"
|
||||
"$out/devprobe"
|
||||
"$out/dpas_fp8"
|
||||
Reference in new issue
Block a user