Repository navigation
Add reorder_batched_ad_lengths and reorder_batched_ad_indices XPU compatible operators - #87
Merged
Merged
Conversation
aagalleg
force-pushed
the
feat/reorder_batched_ad
branch
from
July 20, 2026 17:41
ecd2a4d to
bfe2040
Compare
aagalleg
force-pushed
the
feat/reorder_batched_ad
branch
from
July 21, 2026 18:39
bfe2040 to
0cc129f
Compare
Contributor
|
Merged
5 tasks done
Implement reorder_batched_ad_lengths and reorder_batched_ad_indices operators with SYCL kernels for Intel XPU devices. (cherry picked from commit efbf5ca)
Add build system integration and Python API for reorder_batched_ad operators introduced in the previous commit. (cherry picked from commit 693ffcf)
Add comprehensive test suite for reorder_batched_ad_lengths and reorder_batched_ad_indices operators, covering both broadcast and non-broadcast modes. (cherry picked from commit 11faaf1)
(cherry picked from commit 0cc129f)
Signed-off-by: Felipe Leza Alvarez <felipe.leza.alvarez@intel.com> (cherry picked from commit 603a554)
…ng standards Signed-off-by: Felipe Leza Alvarez <felipe.leza.alvarez@intel.com> (cherry picked from commit 8a3c89b)
Signed-off-by: Felipe Leza Alvarez <felipe.leza.alvarez@intel.com> (cherry picked from commit e19631d)
The four kernels in reorder_batched_ad.cpp were SYCL free-function kernels launched through the sycl_kernel_submit helper, which builds a kernel bundle per launch and pulls the comm/ helper directory into this file. Convert them to functors and submit them with queue.submit / parallel_for, which is the pattern already used by the other kernels in this package. Kernel bodies, global/local ranges and kernel arguments are unchanged, so behaviour is identical and only the submission mechanism differs. The host side now takes the queue from c10::xpu::getCurrentXPUStream() and reads the sub-group and work-group limits from at::xpu::getDeviceProperties, so reorder_batched_ad.h no longer includes comm/SYCLContext.h. (cherry picked from commit 42f484d)
Introduce packages/fbgemm-xpu/src/fbgemm_xpu/fbgemm_utils/ with: - dispatch_macros.h: FBGEMM_DISPATCH_* macros for floating/integral scalar type dispatch, mirroring upstream fbgemm_gpu conventions. - tensor_utils.h: helpers to check that a set of tensors are defined and reside on the same XPU device, raising a descriptive TORCH_CHECK message otherwise. - utils.h: XPU work-group sizing helpers (syclDeviceMaxWorkGroupSize, xpu_calc_xblock_count) and the SYCL_DEVICE_GUARD macro, factored out for reuse across SYCL kernel implementations.
…cl_kernels
Fold reorder_batched_ad_op.cpp into sycl_kernels/reorder_batched_ad.{h,cpp}
so each kernel dispatcher function directly returns the output tensor and
registers itself with TORCH_LIBRARY_IMPL, removing the separate host-side
wrapper file and its duplicate tensor-allocation logic.
Replace the file-local xpu_max_sub_group_size()/xpu_device_max_work_group_size()
helpers with the shared kThreadGroupSize/kMaxThreads constants from
fbgemm_utils/utils.h, and switch the fbgemm_utils includes to their new
top-level path.
Also fix NarrowBroadcastIndicesKernel to bail out before indexing
cat_ad_offsets_ for warps launched past reordered_cat_ad_batches_, avoiding
an out-of-bounds read introduced by the work-group rounding.
aagalleg
force-pushed
the
feat/reorder_batched_ad
branch
from
September 2, 2026 00:24
e93d159 to
e1a175e
Compare
aagalleg
marked this pull request as ready for review
September 2, 2026 00:59
aagalleg
requested review from
dvrogozh,
flezaalv,
luis-real,
mkrze and
molintc
as code owners
September 2, 2026 00:59
mkrze
reviewed
Sep 2, 2026
Comment on lines
+183
to
+184
| const auto b_t = | ||
| item.get_group(0) * item.get_local_range(1) + item.get_local_id(1); |
Contributor
There was a problem hiding this comment.
Critical — transposed dimensions, indices kernel
Same transposed mapping as in ReorderBatchedAdLengthsKernel: b_t comes from
get_local_id(1) on line 184, while both copy loops (lines 206 and 215) index
with get_local_id(0). Adjacent work-items copy different segments instead of
adjacent elements, so the stores to reordered_cat_ad_indices_ are scattered.
Measured on B60, B=64, T=64, A=16, sweeping segment length so the inner copy
width is A*L:
| width | as-is | transposed | speedup |
|---|---|---|---|
| 128 | 0.0439 ms (96 GB/s) | 0.0200 ms (210 GB/s) | 2.20× |
| 256 | 0.0522 ms (161 GB/s) | 0.0156 ms (539 GB/s) | 3.36× |
| 1024 | 0.1584 ms (212 GB/s) | 0.0629 ms (533 GB/s) | 2.52× |
Same fix: b_t from dimension 0, copy index from dimension 1. Ranges at lines
474–475 already have both dimensions equal, so they stay as they are.
mkrze
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements
reorder_batched_ad_lengthsandreorder_batched_ad_indicesoperators for Intel XPU devices, porting FBGEMM's batched advertisement reordering functionality from CUDA to SYCL. These operators transform sparse embedding data from ragged[B x T x #num_ads_b]layout to table-first[T][B][#num_ads_b]layout for efficient embedding lookups in advertising and recommendation systems.Changes
Operator Implementation
sycl_kernels/reorder_batched_ad.h: Public API header with top-level operator implementations for XPU..sycl_kernels/reorder_batched_ad.cpp: SYCL kernel implementations.Build System Integration
CMakeLists.txt: Addsreorder_batched_ad.cppto thehost_sourceslist, ensuring SYCL compilation with theicpxcompiler and AOT targetsTesting
The patch adds XPU support to fbgemm_gpu/test/sparse/reorder_batched_test.py by importing fbgemm_xpu and using accelerator_unavailable / current_accelerator() instead of the CUDA-only gpu_unavailable / .cuda() helpers.
Tests enabled on XPU:
test_reorder_batched_ad_lengths — validates reorder_batched_ad_lengths in both broadcast and non-broadcast modes.
test_reorder_batched_ad_indices — validates reorder_batched_ad_indices in both broadcast and non-broadcast modes.