Skip to content

fbgemm-xpu: port expand_into_jagged_permute to SYCL/XPU - #123

Merged
dvrogozh merged 8 commits into
intel:mainfrom
mkrze:ptxpulib-116-expand-into-jagged-permute
Aug 28, 2026
Merged

dvrogozh merged 8 commits into
intel:mainfrom
mkrze:ptxpulib-116-expand-into-jagged-permute

Conversation

@mkrze

@mkrze mkrze commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Port fbgemm::expand_into_jagged_permute to SYCL/XPU by mirroring the existing CUDA two-dimensional launch structure and grid-stride algorithm.

Changes

  • Add the ExpandIntoJaggedPermuteKernel<index_t> SYCL functor.
  • Add the expand_into_jagged_permute_xpu host launcher.
  • Support both int32 and int64 index tensors.
  • Validate that all inputs:
    • are XPU tensors;
    • reside on the same XPU device;
    • have compatible lengths.
  • Submit the kernel through the current stream of the input tensor’s device, preserving multi-XPU correctness.
  • Register the implementation using TORCH_LIBRARY_IMPL(fbgemm, XPU, m).
  • Add a guarded schema definition in ops_registry.cpp.
  • Add the kernel source to CMake host_sources.
  • Keep the complete host_sources list alphabetically ordered.
  • Enable the upstream FBGEMM test through the shared test patch.
  • Follow the PR Add block_bucketize_sparse_features operator #76 device-agnostic test convention using:
    • accelerator_available;
    • current_accelerator();
    • .to(device).

Kernel mapping

The SYCL work-group mirrors the CUDA launch:

  • dimension 1 assigns jagged segments/tables;
  • dimension 0 assigns elements within each segment;
  • a grid-stride loop processes additional segments.

For every output segment:

output_permute[output_offsets[t] + i] =
    input_offsets[permute[t]] + i

Upstream synchronization

The merge:

  • retains the upstream block-bucketize schemas and implementation;
  • retains the expand_into_jagged_permute schema and XPU implementation;
  • keeps the CMake host_sources list alphabetically ordered.

Validation

Validated with:

  • Python 3.12.3
  • PyTorch 2.13.0+xpu
  • Intel B60 XPU
  • FBGEMM v1.8.0

Results:

  • torch.xpu.is_available() == True
  • import fbgemm_xpu succeeds
  • the dispatch table contains the XPU implementation
  • CPU and XPU results match
  • both int32 and int64 paths pass
  • the FBGEMM test patch applies cleanly
  • the wheel builds successfully
  • patched test files: 26 passed, 15 skipped, 0 failed

The skipped tests require CUDA or operators that have not yet been ported to XPU.

CC: @dvrogozh @flezaalv @aagalleg

mkrze and others added 4 commits August 19, 2026 21:23
Add a SYCL implementation of the FBGEMM expand_into_jagged_permute
operator for Intel XPU, mirroring the CUDA kernel structure:

- add the 2D nd_range functor and XPU dispatch implementation;
- validate that all inputs share one XPU and launch on that device's
  current stream, preserving correctness in multi-XPU applications;
- register the guarded schema and add the kernel to host_sources;
- enable expand_into_jagged_permute_test.py for XPU in the FBGEMM test
  patch.

Validated on an Intel B60 with torch 2.13.0+xpu. The standalone patch
applies cleanly and its test files pass on XPU (8 passed, 11 skipped for
CUDA-only or not-yet-ported cases).
Follow the shared accelerator convention so the patched test exercises the active backend without hardcoding CUDA or XPU.
Pick up the permute_2D_sparse_data split and torchcodec updates from main while retaining both guarded operator schemas.

Co-authored-by: Cursor <cursoragent@cursor.com>
Retain the expand_into_jagged_permute implementation while incorporating the
upstream block_bucketize operator and TorchCodec documentation update. Combine
the FBGEMM test patch and keep the host source list alphabetically ordered.

@dvrogozh dvrogozh 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.

LGTM

@dvrogozh

Copy link
Copy Markdown
Contributor

Rebase, please as other patch we merged gives a conflict.

@dvrogozh

Copy link
Copy Markdown
Contributor

Also, please, update README following #124.

mkrze added 4 commits August 27, 2026 10:38
Retain the expand_into_jagged_permute schema, kernel, and test enablement
while picking up the get_infos_metadata XPU dispatch, the README supported-
operator list, and the TBE utils CI entries from main. Keep the CMake
host_sources list alphabetically ordered and regenerate the FBGEMM test patch
so both test additions land in one patch.
Template ExpandIntoJaggedPermuteKernel on <index_t, offsets_t> and type the
offset pointers as offsets_t, mirroring the CUDA kernel so the index and
offset roles stay distinguishable.

Swap the two nd_range dimensions. SYCL varies the last dimension of an
nd_item fastest, whereas CUDA varies threadIdx.x fastest, so the previous
1:1 transcription mapped consecutive work-items onto different tables and
scattered the stores to output_permute. Mapping CUDA .x onto SYCL dimension 1
restores coalesced stores: 4096x4096 elements go from 0.886 ms to 0.343 ms
(303 -> 782 GB/s) on an Intel B60.
The test-fbgemm job enumerates pytest modules explicitly, so the test enabled
by the FBGEMM patch would otherwise never run.
It is part of the documented FBGEMM sparse ops stable API, so it belongs in
the first list introduced by intel#124.

@dvrogozh dvrogozh 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.

LGTM

@aagalleg aagalleg 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.

LGTM

@dvrogozh
dvrogozh merged commit 8ec70a7 into intel:main Aug 28, 2026
17 checks passed
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.

3 participants