intel / intel/llvm

Non-masked AVX512 instructions in both SYCL and host code could trigger SIGFPE

Open
#17,300 10 comments 0 reactions 0 assignees View on GitHub
bug confirmed
Dominant language
LLVM
Stars
1.5k
Forks
854
Avg merge
3d 17h
Merged PRs (30d)
137

Description

### Describe the bug

Compiling SYCL kernels or host code involving for-loops with remainders generates vectorized instructions that are not correctly masked.
Registers used to save the resulting values will contain invalid numbers for those lanes that should have been masked.
Even though such memory chunks will normally never be accessed, allowing the computation of such values will trigger floating point exceptions whenever enabled.

### To reproduce

Here is an example of host code exemplifying the issue: https://godbolt.org/z/rqrE13an1

Shortly, a for-loop such as:

```cpp
for (size_t i{0}; i < n_elements; i++) {
a[i] /= b[i];
}
```

will generate instructions relative to the remainder of the loop that mask only `mov` operations, while leaving the `div` operation unmasked:

```asm
vmovupd zmm0 {k1} {z}, zmmword ptr [rbx + 8*rax]
vmovupd zmm1 {k1} {z}, zmmword ptr [r14 + 8*rax]
vdivpd zmm0, zmm0, zmm1
vmovupd zmmword ptr [rbx + 8*rax] {k1}, zmm0
```

Similarly, the same behavior can be reproduced within SYCL kernels: https://godbolt.org/z/ce7KP4T6v
(Unfortunately Compiler-Explorer does not show assembly relative to device code, but the same instructions as above may be retrieved with gdb-oneapi, for instance)

In this case, work-items belonging to the same sub-group and accessing contiguous memory will be translated to vectorized instructions that present the same issue.

```cpp
for (size_t i{local_id}; i < n_elements; i += sub_group_size) {
a_d[i] /= b_d[i];
}
```

We noticed that on host code the problem occurs with `-O3` and `-O2` compiler optimizations, while the SYCL counterpart is also occurring with `-O1` optimizations.

### Environment

- OS: Ubuntu 22.04
- Target device and vendor: x86 Intel CPU
- DPC++ version: 2024.2.0 and 2025.0.0
- Dependencies version:
```
[opencl:cpu][opencl:0] Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz OpenCL 3.0 (Build 0) [2024.18.6.0.02_160000]

Platforms: 1
Platform [#1]:
Version : OpenCL 3.0 LINUX
Name : Intel(R) OpenCL
Vendor : Intel(R) Corporation
Devices : 1
Device [#0]:
Type : cpu
Version : OpenCL 3.0 (Build 0)
Name : Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz
Vendor : Intel(R) Corporation
Driver : 2024.18.6.0.02_160000
Aspects : cpu fp16 fp64 online_compiler online_linker queue_profiling usm_device_allocations usm_host_allocations usm_shared_allocations usm_system_allocations usm_atomic_host_allocations usm_atomic_shared_allocations atomic64 ext_oneapi_srgb ext_oneapi_native_assert ext_intel_legacy_image ext_oneapi_ballot_group ext_oneapi_fixed_size_group ext_oneapi_opportunistic_group ext_oneapi_tangle_group
info::device::sub_group_sizes: 4 8 16 32 64
default_selector() : cpu, Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz OpenCL 3.0 (Build 0) [2024.18.6.0.02_160000]
accelerator_selector() : No device of requested type available. Please chec...
cpu_selector() : cpu, Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz OpenCL 3.0 (Build 0) [2024.18.6.0.02_160000]
gpu_selector() : No device of requested type available. Please chec...
custom_selector(gpu) : No device of requested type available. Please chec...
custom_selector(cpu) : cpu, Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz OpenCL 3.0 (Build 0) [2024.18.6.0.02_160000]
custom_selector(acc) : No device of requested type available. Please chec...
```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.