-
Notifications
You must be signed in to change notification settings - Fork 61
Description
🐛 Describe the bug
When performing tensor indexing on an XPU device with out-of-bounds indices, the process crashes with a Core Dump instead of raising a catchable Python exception.
I wrote a simple script to reproduce the issue as follows:
import torch
def reproduce_core_dump():
if hasattr(torch, 'xpu') and torch.xpu.is_available():
device = "xpu"
elif torch.cuda.is_available():
device = "cuda"
else:
device = "cpu"
print(f"Running reproduction script on device: {device}")
batch, seq_len, heads, dim = 2, 7, 4, 8
data = torch.randn(batch, seq_len, heads, dim, device=device)
flat_data = data.reshape(-1, heads, dim) # shape: [14, 4, 8]
print(f"Flattened tensor shape: {flat_data.shape}")
indices = torch.tensor([1, 2, 90], device=device, dtype=torch.long)
print(f"Indices to access: {indices}")
print(f"Max index: {indices.max().item()}")
print("Executing out-of-bounds indexing...")
try:
# expected behavior: should raise RuntimeError or IndexError
# actual behavior (XPU): may cause Core Dump / Segmentation Fault
output = flat_data[indices]
if device == "xpu":
torch.xpu.synchronize()
elif device == "cuda":
torch.cuda.synchronize()
print("Operation finished without python exception (Unexpected for OOB).")
print(f"Output shape: {output.shape}")
except Exception as e:
print(f"Caught expected exception: {type(e).__name__}: {e}")
if __name__ == "__main__":
reproduce_core_dump()
The XPU output:
Running reproduction script on device: xpu
Flattened tensor shape: torch.Size([14, 4, 8])
Indices to access: tensor([ 1, 2, 90], device='xpu:0')
Max index: 90
Executing out-of-bounds indexing...
AssertHandler::printMessage
...
Aborted (core dumped)
The CUDA output:
Running reproduction script on device: cuda
Flattened tensor shape: torch.Size([14, 4, 8])
Indices to access: tensor([ 1, 2, 90], device='cuda:0')
Max index: 90
Executing out-of-bounds indexing...
...
Caught expected exception: AcceleratorError: CUDA error: device-side assert triggered
Search for `cudaErrorAssert' in https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html for more information.
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
The CPU output:
Running reproduction script on device: cpu
Flattened tensor shape: torch.Size([14, 4, 8])
Indices to access: tensor([ 1, 2, 90])
Max index: 90
Executing out-of-bounds indexing...
Caught expected exception: IndexError: index 90 is out of bounds for dimension 0 with size 14
I think the XPU backend should handle out-of-bounds indexing gracefully by raising a Python-level exception (e.g., IndexError or RuntimeError), consistent with CPU and CUDA behaviors. Otherwise, users would be unable to handle such situations on the front end during actual use.
Thanks!
Versions
PyTorch version: 2.10.0.dev20251118+xpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: Ubuntu 24.04.2 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 4.1.2
Libc version: glibc-2.39
Python version: 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-87-generic-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: True
XPU used to build PyTorch: 20250201
Intel GPU driver version:
- intel-opencl-icd: 25.18.33578.15-1146~24.04
- libze1: 1.21.9.0-1136~24.04
Intel GPU models onboard: - Intel(R) Data Center GPU Max 1550
- Intel(R) Data Center GPU Max 1550
Intel GPU models detected: - [0] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1550', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBD5, uuid=b5bd62c5-d716-1138-0000-000000000001, driver_version='1.6.33578+15', total_memory=65520MB, max_compute_units=512, gpu_eu_count=512, gpu_subslice_count=64, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
- [1] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1550', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBD5, uuid=b5bd62c5-d716-1138-0000-000000000002, driver_version='1.6.33578+15', total_memory=65520MB, max_compute_units=512, gpu_eu_count=512, gpu_subslice_count=64, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 52 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 112
On-line CPU(s) list: 0-111
Vendor ID: GenuineIntel
BIOS Vendor ID: Intel(R) Corporation
Model name: Intel(R) Xeon(R) Platinum 8480+
BIOS Model name: Intel(R) Xeon(R) Platinum 8480+ CPU @ 2.0GHz
BIOS CPU family: 179
CPU family: 6
Model: 143
Thread(s) per core: 1
Core(s) per socket: 56
Socket(s): 2
Stepping: 6
CPU(s) scaling MHz: 31%
CPU max MHz: 3800.0000
CPU min MHz: 800.0000
BogoMIPS: 4000.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect user_shstk avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities ibpb_exit_to_user
Virtualization: VT-x
L1d cache: 5.3 MiB (112 instances)
L1i cache: 3.5 MiB (112 instances)
L2 cache: 224 MiB (112 instances)
L3 cache: 210 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0-55
NUMA node1 CPU(s): 56-111
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Mitigation; IBPB before exit to userspace
Versions of relevant libraries:
[pip3] dpcpp-cpp-rt==2025.2.1
[pip3] galore-torch==1.0
[pip3] impi-rt==2021.16.1
[pip3] intel-cmplr-lib-rt==2025.2.1
[pip3] intel-cmplr-lib-ur==2025.2.1
[pip3] intel-cmplr-lic-rt==2025.2.1
[pip3] intel-opencl-rt==2025.2.1
[pip3] intel-openmp==2025.2.1
[pip3] intel-pti==0.13.1
[pip3] intel-sycl-rt==2025.2.1
[pip3] mkl==2025.2.0
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.2.6
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] oneccl==2021.16.1
[pip3] oneccl-devel==2021.16.1
[pip3] onemkl-sycl-blas==2025.2.0
[pip3] onemkl-sycl-dft==2025.2.0
[pip3] onemkl-sycl-lapack==2025.2.0
[pip3] onemkl-sycl-rng==2025.2.0
[pip3] onemkl-sycl-sparse==2025.2.0
[pip3] onnx==1.19.1
[pip3] pytorch-msssim==1.0.0
[pip3] pytorch-triton-xpu==3.5.0+git1b0418a9
[pip3] tbb==2022.2.0
[pip3] tcmlib==1.4.0
[pip3] torch==2.10.0.dev20251118+xpu
[pip3] torchao==0.14.0.dev20250922+xpu
[pip3] torchaudio==2.10.0.dev20251119+xpu
[pip3] torchcodec==0.8.1
[pip3] torchdata==0.11.0
[pip3] torchmetrics==1.8.2
[pip3] torchvision==0.25.0.dev20251119+xpu
[pip3] umf==0.11.0
[conda] Could not collect