[release/2.13] Hardcoded torch.cuda API calls in upstream tests — porting bug
- Dominant language
- Python
- Stars
- 113
- Forks
- 129
- Avg merge
- 5d 9h
- Merged PRs (30d)
- 112
Description
Cases:
op_ut,third_party.torch-xpu-ops.test.xpu.nn.test_convolution_xpu.TestConvolutionNN,test_slow_conv_dilated3d_unbatched
op_ut,third_party.torch-xpu-ops.test.xpu.test_indexing_xpu.TestIndexingXPU,test_index_add_smem_stage_alignment_regression_xpu_bfloat16
op_ut,third_party.torch-xpu-ops.test.xpu.test_indexing_xpu.TestIndexingXPU,test_index_add_smem_stage_alignment_regression_xpu_float32
## Root Cause
These upstream PyTorch tests contain hardcoded `torch.cuda` API calls that fail on XPU-only builds:
- **index_add tests** (`test_indexing.py:2152`): call `torch.cuda.get_device_properties(0).multi_processor_count` to determine shared memory staging parameters. This triggers `AssertionError: Torch not compiled with CUDA enabled` on XPU builds.
- **slow_conv test** (`test_convolution.py:613`): uses `torch.randn(..., device=device)` which internally triggers CUDA lazy init on this code path.
This is a classic CUDA→XPU porting issue. The XPU test wraps the upstream test but the upstream code still uses CUDA-specific APIs.
**Fix:** Either:
1. Override the test method in the XPU test file to replace `torch.cuda.get_device_properties(0).multi_processor_count` with `torch.xpu.get_device_properties(0).max_compute_units` (or equivalent).
2. Submit an upstream PyTorch PR to make the test device-agnostic.
3. Skip these tests on XPU with an appropriate comment.
## Reproducer
```bash
source ~/.bashrc && cd third_party/torch-xpu-ops/test/xpu && python -m pytest -sxv test_indexing_xpu.py -k "test_index_add_smem_stage_alignment_regression_xpu_bfloat16"
```
```bash
source ~/.bashrc && cd third_party/torch-xpu-ops/test/xpu && python -m pytest -sxv nn/test_convolution_xpu.py -k "test_slow_conv_dilated3d_unbatched"
```
## Representative Error
```
Traceback (most recent call last):
File "test/test_indexing.py", line 2152, in test_index_add_smem_stage_alignment_regression
sm = torch.cuda.get_device_properties(0).multi_processor_count
File "torch/cuda/__init__.py", line 733, in get_device_properties
_lazy_init()
File "torch/cuda/__init__.py", line 518, in _lazy_init
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
```
Contributor guide
Assessment
This issue has not been assessed yet.