Add asynchronous_complete_cumsum operator for XPU - #73
Conversation
dvrogozh
left a comment
There was a problem hiding this comment.
In addition to inline comments:
- Repository has lint CI - please, address identified issues.
- What we implement and merge must be tested under CI. And IMHO doing that by engineers who implemented the code is the best variant rather than offloading that to dedicated CI engineers. Thus, please, modify
.github/workflows/ci.ymland add a test section for FBGEMM following the pattern outlined for torchcodec (see link below). The test job for FBGEMM will be much simpler. Target onlybmgfor now is fine. Note that fbgemm wheel is already getting build by CI.
torchlib-xpu/.github/workflows/ci.yml
Line 199 in d4230aa
| .has_value(); | ||
| } | ||
|
|
||
| } // namespace fbgemm_xpu::utils::torch No newline at end of file |
There was a problem hiding this comment.
add new line in end of file
| } | ||
| } | ||
|
|
||
| void InvertPermuteKernelInt64::operator()(const sycl::nd_item<1>& item) const { |
There was a problem hiding this comment.
This seems templetable kernel over the operand type. Why don't we do that especially considering that the reference CUDA kernel is doing exactly that [1]?
| * @brief Permute1DDataWithWeightsKernel operator implementation | ||
| */ | ||
| template <typename offsets_t, typename indices_t, typename weights_t> | ||
| void Permute1DDataWithWeightsKernel<offsets_t, indices_t, weights_t>::operator()( |
There was a problem hiding this comment.
Why not to follow CUDA reference [1] and additionally parameterize with has_weight?
|
|
||
| __all__ = [ | ||
| "dense_embedding_codegen_lookup_function", | ||
| "invert_permute", |
There was a problem hiding this comment.
Here I am confused. Why do we expose these XPU specific APIs from fbgemm xpu? who is supposed to use them? My understanding was that we are just register low level entrypoints for XPU key so that standard fbgemm APIs start to work on XPU device. Shouldn't that be that user calls fbgemm::invert_permute for example?
|
|
||
| def asynchronous_complete_cumsum(t_in: Tensor) -> Tensor: | ||
| """Computes complete cumulative sum: output[0] = 0, output[i] = sum(t_in[0:i]).""" | ||
| return torch.ops.fbgemm.asynchronous_complete_cumsum.default(t_in) No newline at end of file |
There was a problem hiding this comment.
add empty line in end of file
| @@ -0,0 +1,71 @@ | |||
| """ | |||
There was a problem hiding this comment.
Should also have a copyright.
| For 1D input [a, b, c], returns [0, a, a+b, a+b+c]. | ||
| For 2D input, cumsum along dimension 1 (columns). | ||
| """ | ||
|
|
There was a problem hiding this comment.
Tests are eventually good, but our side tests won't guarantee that what we've implemented correctly integrates with the upstream FBGEMM. We must explore if upstream tests cover what we are implementing and use them if they are. If not, then we need to raise PRs with upstream to add test coverage. That's critical concern - we need to resolve that before proceeding.
| torch.manual_seed(SEED) | ||
|
|
||
| def test_basic_int32(self): | ||
| if not torch.xpu.is_available(): |
There was a problem hiding this comment.
This check is inconsistent with checks in other test file: @unittest.skipIf(not torch.xpu.is_available(), "XPU not available").
389845d to
dcdd4df
Compare
Remove .gitkeep placeholders
- Add invert_permute kernel to CMake build - Implement invert_permute Python wrapper in ops.py - Register invert_permute operator with schema existence check - Add torch_library.h utility for schema validation
Add SYCL/XPU kernel implementation for invert_permute operation.
Add complete test coverage for invert_permute operator on XPU devices, covering correctness, validation, parity, and performance. Test coverage includes: - Correctness tests for int32/int64 with edge cases (empty, single element, identity, reverse, random permutations) - Input validation tests for invalid dimensions and dtypes - Meta function tests for torch.compile compatibility - PyTorch opcheck validation for operator conventions - Parametric tests with varying sizes (1 to 1M elements) - CPU-XPU parity tests to ensure consistent results - Performance benchmarks measuring execution time and bandwidth
Replace the custom standalone test_invert_permute.py with a git-am patch applied to upstream FBGEMM v1.7.0 misc_ops_test.py, following the torchcodec-xpu convention. The patch makes test_invert_permute run on XPU (permute.xpu(), gated on torch.xpu.is_available()) and skips the remaining operator tests that are not implemented on XPU.
Collapse the two type-specific kernel functors (InvertPermuteKernelInt32, InvertPermuteKernelInt64) into a single templated functor InvertPermuteKernel<index_t>, mirroring the reference CUDA kernel invert_permute_kernel<index_t>.
…cture - Fix test patches to match FBGEMM v1.8.0 tests. - Move test patches from test/patches/ subdirectory to patches/ at the package root level for better organization. Remove now-unnecessary .gitkeep file and update patch with correct base commit reference.
Replace TODO placeholders with actual commands to apply the FBGEMM XPU test patch and execute pytest for misc_ops_test.py in the CI pipeline.
- CMakeLists: add permute_1d_sparse_data.cpp to build sources - ops.py: add Python wrapper with type hints - ops_registry.cpp: register operator schema in fbgemm namespace
Implement SYCL/XPU kernel implementation of permute_1D_sparse_data operator for sparse jagged/1D format data permutation.
Replaced test for upstream patched FBGEMM tests that enables testing XPU. This file is no longer needed.
Signed-off-by: Felipe Leza Alvarez <felipe.leza.alvarez@intel.com>
Add SYCL port of FBGEMM's asynchronous_complete_cumsum operator for Intel XPU devices. The operator computes a complete cumulative sum with a leading zero (e.g., [a, b, c] → [0, a, a+b, a+b+c]).
Integrate asynchronous_complete_cumsum operator into fbgemm-xpu: - Add Python wrapper with complete cumsum documentation - Register operator schema in torch library - Include implementation in CMake build
Delete the accidentally tracked submodule reference to FBGEMM-v1.7.0.
c458218 to
bc7c7a9
Compare
Signed-off-by: Felipe Leza Alvarez <felipe.leza.alvarez@intel.com>
Signed-off-by: Felipe Leza Alvarez <felipe.leza.alvarez@intel.com>
Depends on: #72
This PR introduces the
asynchronous_complete_cumsumoperator to fbgemm-xpu, enabling complete cumulative sum computation with a leading zero on Intel XPU devices.Changes
Core Implementation
asynchronous_complete_cumsum.cpp/h): SYCL port of FBGEMM's asynchronous complete cumsum operator that computes cumulative sum with prepended zero (e.g.,[a, b, c]→[0, a, a+b, a+b+c])ops_registry.cpp): Registers the operator with PyTorch's dispatch system using conditional schema registration to avoid conflictsops.py): Clean Python wrapper function with type hints and documentation for easy integrationInfrastructure
CMakeLists.txt): Added implementation to build configurationTesting
test_asynchronous_complete_cumsum.py):cc: @flezaalv, @manuelhsantana