Add invert_permute operator with SYCL implementation for XPU - #71
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
Hi @dvrogozh, regarding the CI, we added it here: #86. Please take a look and let me know if you have any comments. |
1- Done. |
dvrogozh
left a comment
There was a problem hiding this comment.
@aagalleg, this looks exactly as what I expect to see from the enabling stand point. The only missing part is actual integration into CI run here: https://github.com/intel/torchlib-xpu/blob/main/.github/workflows/ci.yml. Do you work on that?
@flezaalv was working on the CI integration in PR #86. He added a fbgemm-ci.yml file in the workflows directory, not directly to ci.yml. |
@dvrogozh I added a dedicated CI file because I think torchcodec-xpu and fbgemm-xpu packages will have different release times. Please let me know if you have any comments. |
We have a complexity here as besides |
6728c1e to
df495b2
Compare
|
@dvrogozh Patch apply and testing were added to CI. |
dvrogozh
left a comment
There was a problem hiding this comment.
../../../../github/home/miniconda3/envs/test-env/lib/python3.10/site-packages/torch/xpu/__init__.py:251
/github/home/miniconda3/envs/test-env/lib/python3.10/site-packages/torch/xpu/__init__.py:251: UserWarning: Can't initialize Level Zero Sysman
return _enum_zes_device_infos(visible_mask)
../../../../github/home/miniconda3/envs/test-env/lib/python3.10/site-packages/torch/xpu/__init__.py:278
/github/home/miniconda3/envs/test-env/lib/python3.10/site-packages/torch/xpu/__init__.py:278: UserWarning: XPU device count is zero! (Triggered internally at /__w/pytorch/pytorch/c10/xpu/XPUFunctions.cpp:117.)
count = torch._C._xpu_getDeviceCount() if zes_count < 0 else zes_count
These warnings in the tests are related to XPU. I am especially worried about the 2nd one as it basically says that XPU is unavailable. With that I am confused considering that torch.xpu.is_available() was returning True.
Same warning exists in TorchCodec CI as well: https://github.com/intel/torchlib-xpu/actions/runs/29928230040/job/88954373767. |
|
Ok, I think above 2 warnings are related. The XPU works for us because there is a fallback to detect XPU devices with SYCL runtime if detection with L0 has failed. I am not sure though why L0 path has failed - this seems to be an issue (not with torchlib). |
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.
6cad528 to
bacbaec
Compare
|
Issue with CI runner is tracked and closed in #104. |
This PR introduces the
invert_permuteoperator to fbgemm-xpu, enabling inverse permutations on Intel XPU devices.Changes
Core Implementation
invert_permute_kernel.cpp/h): High-performance SYCL implementation that computes inverse permutations on XPU devicesops_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 for easy integrationInfrastructure
CMakeLists.txt): Added SYCL kernel to build configurationtorch_library.h): Helper utilities for schema existence checking and operator registration.gitkeepfiles from populated directoriesTesting
test_invert_permute.py):cc: @manuelhsantana, @flezaalv