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,186 @@
|
||||
# Intel GPU (SYCL / Level Zero) backend: progress log
|
||||
|
||||
Task brief: `radiance-sycl.md` (repo root, not committed). Porting analysis: `docs/SYCL_PORTING.md`
|
||||
(Phase 1, not written yet). This file is the resume point: a fresh session should be able to continue
|
||||
from it alone.
|
||||
|
||||
## Status
|
||||
|
||||
| phase | state |
|
||||
|---|---|
|
||||
| 0 environment check | done |
|
||||
| 1 codebase study, `SYCL_PORTING.md` | in progress |
|
||||
| 2 design | not started |
|
||||
| 3 correctness-first kernels | not started |
|
||||
| 4 performance | not started |
|
||||
| 5 broaden and finish | not started |
|
||||
|
||||
## Open blockers / questions for the user
|
||||
|
||||
1. **No `.rad` container for any milestone model is in `/mnt/model-library`.**
|
||||
`StillDeadcode/minicpm5-2b-bf16/` holds only `README.md` and `minicpm5-2b-bf16-dspark.recipe`; there
|
||||
is no `minicpm5-2b-bf16.rad`, no `minicpm5-2b-fp8.rad`, and no raw `openbmb/MiniCPM5-2B` /
|
||||
`MiniCPM5-2B-DSpark` checkpoint to convert from. A `find -iname '*.rad'` over the library and
|
||||
`/models` returns nothing. Milestones A and B cannot be run until the user provides the containers
|
||||
(or the checkpoints plus permission to run `rad-convert`). Per the brief, nothing is downloaded or
|
||||
converted without asking.
|
||||
2. **Bring-up without a real model.** The test suite writes synthetic llama checkpoints and converts
|
||||
them to `.rad` itself (`tests/tiny_model.h`, `tests/engine_e2e_test.cpp`; `RAD_E2E_KEEP=1` keeps
|
||||
them): bf16, block-fp8 trunk, fp8 / int8 heads, int4, MXFP4, all on the `llama_dense_fp8` graph
|
||||
MiniCPM5 uses. Those are test fixtures, not library models, and are what the Intel backend is
|
||||
brought up and compared against the host backend on until the real containers exist.
|
||||
Optionally, `HuggingFaceTB/SmolLM2-135M` (real bf16 llama weights, head_dim 64, tied embeddings)
|
||||
could be converted as a real-weights check; that needs the user's OK, since it is a conversion.
|
||||
3. **No ROCm on this machine** (`hipcc` absent, no `/opt/rocm`). "The HIP build must still compile"
|
||||
cannot be checked here; it needs a ROCm host or a ROCm container (the repo's `Dockerfile` may
|
||||
serve). Until then, HIP-side edits are kept to a minimum and listed below for review.
|
||||
|
||||
## Phase 0 results (2026-10-23)
|
||||
|
||||
### Toolchain and device
|
||||
|
||||
- Compiler: `Intel(R) oneAPI DPC++/C++ Compiler 2026.2.0 (2026.2.0.20261001)`, at `/opt/intel/oneapi`
|
||||
(not on PATH by default: `. /opt/intel/oneapi/setvars.sh`).
|
||||
- `sycl-ls`: `[level_zero:gpu][level_zero:0] Intel(R) oneAPI Unified Runtime over Level-Zero V2, Intel(R) Arc(TM) Pro B65 Graphics 20.2.0 [1.17.39395+16]`
|
||||
(also an OpenCL GPU entry for the same card, NEO 26.31.39395.16, and the OpenCL CPU device).
|
||||
- `clinfo -l`: Intel OpenCL (EPYC 7282 CPU), Intel OpenCL Graphics (Arc Pro B65).
|
||||
- `lspci -k`: `01:00.0 Intel Corporation Battlemage G31`, kernel driver `xe`. Linux 7.0.0-38-generic.
|
||||
- User is in `render` and `video`; `/dev/dri/renderD128` is `root:render 0660`.
|
||||
- Host: AMD EPYC 7282, 8 visible cores, 30 GiB RAM (a VM; the bochs VGA is the emulated console).
|
||||
|
||||
### Device limits (`scripts/sycl/devprobe.cpp`)
|
||||
|
||||
| query | value |
|
||||
|---|---|
|
||||
| architecture | `intel_gpu_bmg_g31` (alias `intel_gpu_20_2_0`); AOT target `-device bmg-g31` |
|
||||
| compute units | 160 (20 Xe cores x 8 vector engines) |
|
||||
| max work-group size | 1024 |
|
||||
| sub-group sizes | 16, 32 |
|
||||
| local memory (SLM) per work-group | 131072 B (128 KiB) |
|
||||
| global memory | 34242297856 B (31.89 GiB) |
|
||||
| max single allocation | 32530182144 B (30.30 GiB) |
|
||||
| L2 (global_mem_cache_size) | 18 MiB |
|
||||
| max clock | 2400 MHz |
|
||||
| fp16 / fp64 / atomic64 | yes / yes / yes |
|
||||
| USM device / host / shared / system | yes / yes / yes / yes |
|
||||
| `ext_intel_matrix` aspect | yes |
|
||||
|
||||
### XMX (joint_matrix and ESIMD DPAS)
|
||||
|
||||
`matrix_combinations` reports, for sub-group 16: A/B in {u8,s8} -> s32 at M<=8 N16 K32; fp16 and bf16
|
||||
-> fp32 or 16-bit at M<=8 N16 K16, plus the larger fixed shapes M16N16K16, M1/M32 x N64 x K16/K32;
|
||||
tf32 -> fp32 at M<=8 N16 K8. No FP8 combination is listed (the query enum has no fp8 member).
|
||||
|
||||
Executed on the device, each checked exactly against a host loop:
|
||||
|
||||
| op | result |
|
||||
|---|---|
|
||||
| joint_matrix bf16 x bf16 -> f32, M8 N16 K16 | exact |
|
||||
| joint_matrix fp16 x fp16 -> f32, M8 N16 K16 | exact |
|
||||
| joint_matrix s8 x s8 -> s32, M8 N16 K32 | exact |
|
||||
| ESIMD `xmx::dpas` bf16 -> f32, M8 N16 K16 (control) | exact |
|
||||
| ESIMD `xmx::dpas` s8 -> s32, M8 N16 K32 (control) | exact |
|
||||
| ESIMD `xmx::dpas` **hf8 (E4M3)** -> f32, M8 N16 K32 | **wrong** (values ~1e15..1e24 and inf; expected 31.75) |
|
||||
| ESIMD `xmx::dpas` **bf8 (E5M2)** -> f32, M8 N16 K32 | **wrong** |
|
||||
|
||||
The ESIMD headers declare `hf8`/`bf8`/`e2m1` DPAS argument types, and IGC compiles them for
|
||||
`bmg-g31` (AOT and JIT) without a diagnostic, but the results are garbage while the bf16 and s8
|
||||
controls through the identical harness and VNNI packing are exact. **Conclusion: FP8 is not a native
|
||||
XMX input on this Battlemage part** (the brief's belief holds). The 8-bit float DPAS precisions are
|
||||
for a later generation; the compiler does not reject them for BMG.
|
||||
|
||||
Consequence for the design: fp8 (E4M3) weights are widened in-register before DPAS. E4M3 -> bf16 is
|
||||
exact for every finite E4M3 value (3 mantissa bits fit in bf16's 7; max 448 and the smallest
|
||||
subnormal 2^-9 are inside bf16's range), and it keeps the activations bf16, so **bf16 XMX is the
|
||||
default path for fp8 weights**. (E4M3 -> fp16 is also exact, but the bf16 activations would then have
|
||||
to be narrowed to fp16, which can overflow.) MXFP4 (e2m1) is the same: widen to bf16 in-register.
|
||||
int8 (w4a8, int8 trunks) has native s8 DPAS.
|
||||
|
||||
Reproduce: `scripts/sycl/probe.sh` (prints both tables' raw output).
|
||||
|
||||
### Host baseline (tree at `9eaf10d`, before any change)
|
||||
|
||||
`./build.sh --no-hip` builds cleanly (625 targets, GCC, Ninja). Then:
|
||||
|
||||
- `ctest -L '^fast$' -j8`: 75/80 pass.
|
||||
- `ctest --test-dir build -LE 'gpu|oot' -j8`: **82/88 pass, 540 s**. `engine_e2e_test` (33 s) and
|
||||
`convert_test` pass.
|
||||
|
||||
The six failures are pre-existing and environmental; none touches code this task changes. **This
|
||||
set is the baseline that "passes exactly as before" is measured against:**
|
||||
|
||||
| test | cause | evidence |
|
||||
|---|---|---|
|
||||
| `images_test` | no FFmpeg dev libraries, so `RAD_WITH_FFMPEG` resolves off and pictures cannot be encoded | `500 ... this build has no media decoder: it was configured without libavformat / libavcodec / libswscale`; `pkg-config libavcodec` fails |
|
||||
| `videos_test` | same | `400 ... input_reference: the picture could not be read: this build has no media decoder` |
|
||||
| `glm5next_test` | over its CPU-time budget on this slow VM host | `the binary spent 11.17 s of CPU, over its budget of 10 s (RAD_TEST_CPU_BUDGET)` |
|
||||
| `gbnf_test_shard2` | same | `10.52 s of CPU, over its budget of 10 s` |
|
||||
| `quant_ggml_test` | same | `25.38 s of CPU, over its budget of 25 s` |
|
||||
| `trigger_test` | timing ratio under `-j8` load; passes 3/3 run alone | `trigger_test.cpp:429: CHECK((double)last < (double)first * 1.25)` in `lazy_grammar_waiting_work_does_not_grow_with_the_reply` |
|
||||
|
||||
Installing `libavformat-dev libavcodec-dev libswscale-dev` would clear the first two (the user's
|
||||
call; not needed for this task). After each phase, the same command must show these six and no
|
||||
others; the CPU-budget and timing tests are compared by cause (re-run alone if they flip).
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Tool: BetterBench 0.6.1 (`GGZ14/BetterBench` at `f72bb90`), cloned to `~/tools/BetterBench` and
|
||||
installed editable into its own venv `~/tools/betterbench-venv` (Python 3.14.4). Every flag of the
|
||||
brief's command (`--quick --decode --prefill --no-update-check --name --out --note --api-key`) is
|
||||
present in `betterbench run --help`.
|
||||
|
||||
```sh
|
||||
~/tools/betterbench-venv/bin/betterbench run --endpoint http://127.0.0.1:8000/v1 --model <served name> \
|
||||
--quick --decode --prefill --no-update-check \
|
||||
--name sycl-<model>-<short commit> --out <run dir>/results.json \
|
||||
--note backend=sycl --note gpu=arc-pro-b65 --note commit=<short commit>
|
||||
```
|
||||
|
||||
Discord posting: **`~/.config/radiance-bench.env` does not exist, so `DISCORD_WEBHOOK_URL` is unset**
|
||||
(checked 2026-10-23). Runs are recorded here without posting until the user creates that file.
|
||||
`scripts/bench_report.sh` (quick run, parse `results.json` with `jq`, post, check the HTTP status) is
|
||||
to be written at the first benchmarkable milestone, against a real `results.json`.
|
||||
|
||||
Runs: none yet. Nothing is benchmarked before Milestone A passes its correctness checks. All runs
|
||||
are `--quick` (1 warmup, 5 passes): progress tracking, not publishable numbers.
|
||||
|
||||
| date | commit | model | backend | flags | prefill tok/s (median / 1% low) | decode tok/s (median / 1% low) | vs previous | report |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
|
||||
## Models
|
||||
|
||||
Library (`/mnt/model-library`, read-only), as of 2026-10-23:
|
||||
|
||||
| path | what | useful for |
|
||||
|---|---|---|
|
||||
| `StillDeadcode/minicpm5-2b-bf16/` | README + recipe only, **no weights** | nothing until the `.rad` is supplied |
|
||||
| `HuggingFaceTB/SmolLM2-135M/` | bf16 safetensors, llama | possible bring-up stand-in (blocker 2) |
|
||||
| `Launch80/Swift-1.5-Qwen3.8-27B-Uncensored-Int4-baked/` | 16 GiB int4 safetensors (qwen35, "baked") | possibly a 19-22 GiB-class Milestone B model, if `rad-convert` reads it; unverified |
|
||||
| `Wrapzii/Swift-1.5-Qwen3.8-27b-GPTQ-Int4-baked-v1-embed-int8/` | 17 GiB GPTQ int4 + int8 embed | same |
|
||||
| `unsloth/Qwen3.8-27B-GGUF`, other `*-GGUF` dirs | GGUF quantisations | the engine converts some GGUF (`libquant/lq_ggml.cpp`); unverified for these |
|
||||
| `Qwen/Qwen3-0.6B-GGUF`, `unsloth/Qwen3-8B-GGUF`, `SmolLM3-3B-GGUF`, ... | GGUF | not on the README's model table |
|
||||
|
||||
`/models` (196 GiB, 137 GiB free) already holds copies made before this task: `Qwen3.8-27B-Q4_0.gguf`,
|
||||
`mtp-Qwen3.8-27B-Q4_0.gguf`, and the two Swift 27B directories. They are left as found.
|
||||
|
||||
Planned use: Milestone A = `minicpm5-2b-bf16.rad` (blocked, item 1); Milestone B = `minicpm5-2b-fp8.rad`
|
||||
(blocked) and one of the 27B int4 / MXFP4 containers (to be decided once Phase 1 shows what
|
||||
`rad-convert` accepts, and with the user's OK for any conversion).
|
||||
|
||||
## Decisions
|
||||
|
||||
- D1 (Phase 0): FP8 and FP4 weights are widened to bf16 in-register for XMX; int8 uses native s8 DPAS.
|
||||
Evidence above.
|
||||
|
||||
## HIP-side edits awaiting a ROCm compile check
|
||||
|
||||
None yet.
|
||||
|
||||
## Reproduce the current state
|
||||
|
||||
```sh
|
||||
. /opt/intel/oneapi/setvars.sh
|
||||
scripts/sycl/probe.sh # Phase 0 device tables
|
||||
./build.sh --no-hip # host backend + fast tests
|
||||
ctest --test-dir build -LE 'gpu|oot' # host baseline
|
||||
```
|
||||
@@ -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