Skip to content

Add SYCL backend - #22

Open
zjin-lcf wants to merge 5 commits into
PyFR:masterfrom
zjin-lcf:add-sycl-backend
Open

Add SYCL backend#22
zjin-lcf wants to merge 5 commits into
PyFR:masterfrom
zjin-lcf:add-sycl-backend

Conversation

@zjin-lcf

@zjin-lcf zjin-lcf commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Adds a SYCL code-generation backend to GiMMiK, mirroring the structure of the existing OpenCL backend.

  • gimmik/sycl.pySYCLMatMul (platform='sycl'), registered in gimmik/__init__.py.
  • gimmik/kernels/sycl/ — Mako templates for the cstream, bstream, bstream-msplit, and cstream-ksplit kernels. Each emits a self-contained launcher of the form sycl::event kname(sycl::queue& q, ...) that submits the kernel to a queue. Shared-memory kernels use sycl::local_accessor and nd_range, with a compile-time [[sycl::reqd_work_group_size]] annotation.
  • Supports fp32/fp64, the beta term, and both static-n and dynamic-n signatures.

Kernel variants / tuning

  • width-2 (sycl::double2 / sycl::float2) variants of every kernel when the leading dimension is even, at both single and double precision.
  • preload-C variants of bstream-msplit and cstream-ksplit (load C up-front), emitted for beta != 0 as extra autotune candidates.
  • Throughput tuning for the Intel Level Zero backend: explicit nd_range launches, 1D flattened local_accessors with compile-time offsets, and hoisting the B-row loads in cstream so the width-2 kernel does not become memory-bound (IGC does not CSE vector-typed loads). Per-kernel Arc B580 numbers are in the commit messages.

Benchmarks (bench/)

  • An OpenCL-vs-SYCL performance harness plus a correctness-validation suite.

Test plan

  • SYCLMatMul(...).kernels(dtype) generates all variants for fp32/fp64.
  • Correctness suite: every generated kernel verified against a NumPy reference across {fp32, fp64} × {beta=0, beta!=0} × {static-n, dynamic-n}, including the width-2 (float2/double2) and preload-C variants. All pass (70/70 SYCL, 46/46 OpenCL).
  • Runs on an Intel Arc B580 and an Intel Data Center GPU (Level Zero and OpenCL runtimes).

Add a SYCL code-generation backend mirroring the existing OpenCL backend.

- gimmik/sycl.py: SYCLMatMul (platform='sycl'), registered in __init__
- gimmik/kernels/sycl/: cstream, bstream, bstream-msplit, cstream-ksplit
  Mako templates emitting self-contained launcher functions of the form
  `sycl::event kname(sycl::queue& q, ...)`, using local_accessor and
  nd_range for the shared-memory kernels. Supports fp32/fp64, beta,
  static- and dynamic-n signatures, and the fp32 float2 vector variants.
- bench/: OpenCL-vs-SYCL benchmark and a correctness-validation suite that
  checks every generated kernel against a NumPy reference.
- README: mention SYCL support.
@FreddieWitherden

Copy link
Copy Markdown
Contributor

Is there a use-case for SYCL? Our expectation was that those working on SYCL would consume the OpenCL kernels.

zjin-lcf and others added 4 commits August 1, 2026 10:27
- Launch the non-tiled cstream/bstream kernels via an explicit nd_range
  instead of a basic parallel_for.  The Level Zero runtime otherwise
  auto-picks a poor work-group size for cstream, nearly halving its
  bandwidth (~113 -> ~210 GB/s on Arc B580); bstream is unaffected.
- Re-assert __restrict on the pointers used inside the cstream/bstream
  kernel bodies (lost when the launcher pointers are captured by value).
- Flatten the shared-memory local_accessor in bstream-msplit and
  cstream-ksplit from multi-dimensional to 1D with compile-time constant
  offsets.  IGC does not constant-fold the runtime-held strides of a
  multi-dim local_accessor, so the flat form removes redundant address
  arithmetic (bstream-msplit ~208 -> ~257 GB/s on Arc B580).

Co-authored-by: Cursor <cursoragent@cursor.com>
Annotate the SYCL kernel lambdas with [[sycl::reqd_work_group_size(...)]]
so the launch geometry is known at compile time. On AMD (DPC++ amdgcn
backend) this lets the compiler size the register file for the actual
work-group instead of the conservative default, eliminating the register
spilling that otherwise appeared in the cstream/bstream kernels. The hint
matches the geometry already used at launch, so Intel and NVIDIA codegen
are unaffected.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Emit width-2 (sycl::double2 / sycl::float2) variants of every kernel
  when the leading dimension is even, at both single and double
  precision (previously float2 only, and only for cstream/bstream-msplit).
- Add preload-C variants of bstream-msplit and cstream-ksplit that load C
  up-front; emitted only for beta != 0, as extra autotune candidates.
- Hoist every used row of B into a register in cstream before the dot
  products. IGC does not eliminate redundant vector-typed (width > 1)
  loads, so the previous form reloaded B once per non-zero and made the
  width-2 cstream memory-bound (~66 -> ~190 GB/s on Arc B580); width-1
  also improves (~210 -> ~226 GB/s).

Co-authored-by: Cursor <cursoragent@cursor.com>
- bench_gen.py: honour GMK_BETA / GMK_ALIGNE so the width-2 and
  preload-C kernels are emitted; wrap width>1 kernels (which take vector
  pointers) in a uniform double* entry point; tag preloaded kernels; and
  wipe the kernel dir between runs so a stale kernel from a different
  config is never picked up by the build glob.
- validate_gen.py: add fp64 double2 and preload cases (beta != 0) so the
  correctness suite covers the new variants.
- ocl_bench.cpp: allow overriding the matched OpenCL vendor via
  GMK_OCL_VENDOR (defaults to Intel).

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants