Skip to content

sycl : add Kronecker product FWHT support for sizes 384, 640, 768, 1280 - #28016

Merged
Titaniumtown merged 1 commit into
ggml-org:masterfrom
philip-jingxin:sycl-fwht-kronecker
Sep 1, 2026
Merged

Titaniumtown merged 1 commit into
ggml-org:masterfrom
philip-jingxin:sycl-fwht-kronecker

Conversation

@philip-jingxin

@philip-jingxin philip-jingxin commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Extends FWHT with Kronecker product to support non-power-of-two common embedding dimensions 384, 640, 768, 1280

Additional information

Changes

  • Implemented kronecker_kernel to handle base blocks of $m=12$ and $m=20$ using the Paley I matrix construction.
  • Extended operator tests in tests/test-backend-ops.cpp to cover non-power-of-two sizes for Hadamard transformation.

Testing & Verification

Environment

  • Device: Intel(R) UHD Graphics 770
  • Driver Version: 26.05.037020
  • Command: ./build_hadamard/bin/test-backend-ops test -o MUL_MAT_HADAMARD -b SYCL0

Correctness Test

Passed 16/16 verification tests, including non-power-of-two sizes (m= 384, 640, 768, 1280) across various configurations:

Backend 1/2: SYCL0
  Device description: Intel(R) UHD Graphics 770
  MUL_MAT_HADAMARD(m=384,  n=1,  k=384):  OK
  MUL_MAT_HADAMARD(m=384,  n=32, k=384):  OK
  MUL_MAT_HADAMARD(m=384,  n=4,  k=384):  OK
  MUL_MAT_HADAMARD(m=640,  n=1,  k=640):  OK
  MUL_MAT_HADAMARD(m=640,  n=32, k=640):  OK
  MUL_MAT_HADAMARD(m=768,  n=1,  k=768):  OK
  MUL_MAT_HADAMARD(m=1280, n=1,  k=1280): OK
  16/16 tests passed

Performance Benchmarks

Measured on Intel UHD Graphics 770:

Size Batch Latency (us/run) Throughput
384 1 4.20 us 70.19 GFLOPS
384 32 5.33 us 1.77 TFLOPS
640 1 16.74 us 48.95 GFLOPS
640 32 19.57 us 1.34 TFLOPS
768 1 17.23 us 68.47 GFLOPS
1280 1 72.43 us 45.24 GFLOPS

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Gemini was used to debug and ensure the correctness of the implementation.

@philip-jingxin
philip-jingxin requested review from a team and ggerganov as code owners August 30, 2026 10:33
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language labels Aug 30, 2026

@philip-jingxin philip-jingxin left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr extends the FWHT to support a wider range of common embeddings. If you guys find this useful, I'll extends this to more generalized dimensions. Thanks @ggerganov

@arthw arthw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good job!
The UT cases are passed on B60 and iGPU in Ultra 7 265K.

Thank you!

@Titaniumtown
Titaniumtown merged commit 1f3d318 into ggml-org:master Sep 1, 2026
1 check passed
@Titaniumtown

Copy link
Copy Markdown
Contributor

@philip-jingxin Thank you! Very reasonable changes.

@Titaniumtown

Titaniumtown commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

I too hastilly merged this PR, I believe as it breaks github actions. @philip-jingxin can you create a follow-up PR fixing the build issues?

@philip-jingxin

Copy link
Copy Markdown
Contributor Author

I too hastilly merged this PR, I believe as it breaks github actions. @philip-jingxin can you create a follow-up PR fixing the build issues?

@Titaniumtown My bad! I've created a follow-up PR fixing the -Werror,-Wunused-variable warning and reintroducing the feature. Here you go: #28254

Thanks!

Titaniumtown pushed a commit that referenced this pull request Sep 5, 2026
…T support (#28016) (#28254)

* Reapply "sycl : add Kronecker product FWHT support for sizes 384, 640, 768, 12…" (#28184)

This reverts commit c845263.

* tests : fix unused variable M in test-backend-ops

* tests: fix trailing space error and isolate kronecker tests for sycl backend only
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
x1250 pushed a commit to x1250/llama.cpp that referenced this pull request Sep 9, 2026
x1250 pushed a commit to x1250/llama.cpp that referenced this pull request Sep 9, 2026
…T support (ggml-org#28016) (ggml-org#28254)

* Reapply "sycl : add Kronecker product FWHT support for sizes 384, 640, 768, 12…" (ggml-org#28184)

This reverts commit c845263.

* tests : fix unused variable M in test-backend-ops

* tests: fix trailing space error and isolate kronecker tests for sycl backend only
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
…T support (ggml-org#28016) (ggml-org#28254)

* Reapply "sycl : add Kronecker product FWHT support for sizes 384, 640, 768, 12…" (ggml-org#28184)

This reverts commit 79dc68c.

* tests : fix unused variable M in test-backend-ops

* tests: fix trailing space error and isolate kronecker tests for sycl backend only
bri-prism added a commit to PrismML-Eng/llama.cpp that referenced this pull request Oct 2, 2026
…gml-org#28254, ggml-org#29243) (#302)

* sycl : fix test-backend-ops CI break && restore Kronecker product FWHT support (ggml-org#28016) (ggml-org#28254)

* Reapply "sycl : add Kronecker product FWHT support for sizes 384, 640, 768, 12…" (ggml-org#28184)

This reverts commit c845263.

* tests : fix unused variable M in test-backend-ops

* tests: fix trailing space error and isolate kronecker tests for sycl backend only

(cherry picked from commit 4d91760)

* sycl: FWHT kernels for block widths above 512 (ggml-org#29243)

The SYCL FWHT covers 64 to 512 via the standard butterfly network, plus
384/640/768/1280 via the Kronecker/Paley construction added separately in
Hadamard hint can produce (1024, 2048, 4096, 8192); those still fall through
to the default case and run as a dense GEMM against the materialized
rotation tensor, correct but O(n^2) instead of O(n log n).

fwht_kernel_wide runs one row per work-group instead of per sub-group, so
each work-item keeps N/NT values rather than N/WARP_SIZE. Butterflies below
the sub-group width still shuffle; those up to the work-group width go
through work-group local memory; the rest stay in registers. Same butterfly
and sign convention as the existing narrow kernel.

ggml's SYCL backend registration (dpct::dev_mgr) unconditionally requires a
GPU-labeled platform to exist and throws before any op-level test can run,
so test-backend-ops could not be exercised on this box (a GPU-less pod) even
via the CPU device. Verified instead with a standalone harness: the same
kernel body run through a real SYCL CPU device (Intel oneAPI DPC++ 2026.1,
OpenCL CPU backend), checked against an independent recursive-doubling
Hadamard reference, cross-validated by first running the existing unmodified
narrow kernel through the identical harness and confirming it passes (rules
out a reference-convention bug before trusting a pass on the new code).
Random-input results for all four widths, single- and multi-row:

  N=1024 NT=256 rows=1  max_abs_err=1.7e-07  max_rel_err=4.9e-04  PASS
  N=2048 NT=256 rows=1  max_abs_err=1.9e-07  max_rel_err=2.0e-04  PASS
  N=4096 NT=256 rows=1  max_abs_err=2.0e-07  max_rel_err=1.4e-04  PASS
  N=8192 NT=256 rows=1  max_abs_err=2.5e-07  max_rel_err=3.8e-03  PASS
  N=1024 NT=256 rows=7  max_abs_err=2.4e-07  max_rel_err=1.0e-03  PASS
  N=2048 NT=256 rows=5  max_abs_err=3.0e-07  max_rel_err=9.4e-04  PASS
  N=4096 NT=256 rows=3  max_abs_err=2.7e-07  max_rel_err=1.7e-03  PASS
  N=8192 NT=256 rows=2  max_abs_err=2.5e-07  max_rel_err=1.9e-03  PASS

This covers the kernel algorithm itself; it does not exercise the ggml
dispatch/supports_op integration end to end, which needs a real GPU (or a
SYCL GPU plugin) to get past backend registration. test-backend-ops build
is verified: fwht.cpp recompiles with zero warnings as part of ggml-sycl.

(cherry picked from commit c829670)

---------

Co-authored-by: Jingxin (Philip) Li <philipaslee@gmail.com>
imaami pushed a commit to imaami/llama.cpp that referenced this pull request Oct 10, 2026
…gml-org#28254, ggml-org#29243) (ggml-org#302)

* sycl : fix test-backend-ops CI break && restore Kronecker product FWHT support (ggml-org#28016) (ggml-org#28254)

* Reapply "sycl : add Kronecker product FWHT support for sizes 384, 640, 768, 12…" (ggml-org#28184)

This reverts commit c845263.

* tests : fix unused variable M in test-backend-ops

* tests: fix trailing space error and isolate kronecker tests for sycl backend only

(cherry picked from commit 4d91760)

* sycl: FWHT kernels for block widths above 512 (ggml-org#29243)

The SYCL FWHT covers 64 to 512 via the standard butterfly network, plus
384/640/768/1280 via the Kronecker/Paley construction added separately in
Hadamard hint can produce (1024, 2048, 4096, 8192); those still fall through
to the default case and run as a dense GEMM against the materialized
rotation tensor, correct but O(n^2) instead of O(n log n).

fwht_kernel_wide runs one row per work-group instead of per sub-group, so
each work-item keeps N/NT values rather than N/WARP_SIZE. Butterflies below
the sub-group width still shuffle; those up to the work-group width go
through work-group local memory; the rest stay in registers. Same butterfly
and sign convention as the existing narrow kernel.

ggml's SYCL backend registration (dpct::dev_mgr) unconditionally requires a
GPU-labeled platform to exist and throws before any op-level test can run,
so test-backend-ops could not be exercised on this box (a GPU-less pod) even
via the CPU device. Verified instead with a standalone harness: the same
kernel body run through a real SYCL CPU device (Intel oneAPI DPC++ 2026.1,
OpenCL CPU backend), checked against an independent recursive-doubling
Hadamard reference, cross-validated by first running the existing unmodified
narrow kernel through the identical harness and confirming it passes (rules
out a reference-convention bug before trusting a pass on the new code).
Random-input results for all four widths, single- and multi-row:

  N=1024 NT=256 rows=1  max_abs_err=1.7e-07  max_rel_err=4.9e-04  PASS
  N=2048 NT=256 rows=1  max_abs_err=1.9e-07  max_rel_err=2.0e-04  PASS
  N=4096 NT=256 rows=1  max_abs_err=2.0e-07  max_rel_err=1.4e-04  PASS
  N=8192 NT=256 rows=1  max_abs_err=2.5e-07  max_rel_err=3.8e-03  PASS
  N=1024 NT=256 rows=7  max_abs_err=2.4e-07  max_rel_err=1.0e-03  PASS
  N=2048 NT=256 rows=5  max_abs_err=3.0e-07  max_rel_err=9.4e-04  PASS
  N=4096 NT=256 rows=3  max_abs_err=2.7e-07  max_rel_err=1.7e-03  PASS
  N=8192 NT=256 rows=2  max_abs_err=2.5e-07  max_rel_err=1.9e-03  PASS

This covers the kernel algorithm itself; it does not exercise the ggml
dispatch/supports_op integration end to end, which needs a real GPU (or a
SYCL GPU plugin) to get past backend registration. test-backend-ops build
is verified: fwht.cpp recompiles with zero warnings as part of ggml-sycl.

(cherry picked from commit c829670)

---------

Co-authored-by: Jingxin (Philip) Li <philipaslee@gmail.com>
(cherry picked from commit f450c76)
Assisted-by: GitHub Copilot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants