Intel® oneAPI DPC++/C++ Compiler
Developer Guide and Reference
Device-Side Compiler Sanitizers
Device-Side AddressSanitizer
The device-side AddressSanitizer (ASan) supports the error checks in the following table for OpenMP and SYCL* device code.
Feature | OpenMP C/C++ | SYCL |
---|---|---|
bad-context |
n/a |
Supported |
bad-free |
n/a |
Supported |
double-free |
n/a |
Supported |
invalid argument |
Supported |
Supported |
kernel filter |
Not supported |
Supported |
memory leak |
Supported |
Supported |
memory overhead statistics |
Supported |
Supported |
misaligned access |
Supported |
Supported |
multiple error reports |
Supported |
Supported |
nullpointer access |
Supported |
Supported |
out-of-bounds on device global |
Supported |
Supported |
out-of-bounds on global unified shared memory (USM) |
Supported |
Supported |
out-of-bounds on local |
Supported |
Supported |
out-of-bounds on memory buffer |
n/a |
Supported |
out-of-bounds on private |
Supported |
Supported |
use-after-free |
Supported |
Supported |
OpenMP
Compile your OpenMP C/C++ application and execute it with ASan enabled (only supported on GPU), for example:
icpx -fiopenmp -fopenmp-targets=spir64 -Xarch_device -fsanitize=address -g -O2 -o demo demo.cpp
Run on GPU with:
export LIBOMPTARGET_PLUGIN=unified_runtime export UR_ENABLE_LAYERS=UR_LAYER_ASAN export ZE_AFFINITY_MASK=0 ./demo
SYCL
Compile a SYCL example with ASan enabled:
icpx -fsycl -Xarch_device -fsanitize=address -g -O2 -o demo demo.cpp
Run on CPU with:
export ONEAPI_DEVICE_SELECTOR=opencl:cpu ./demo
Run on GPU with:
export ONEAPI_DEVICE_SELECTOR=level_zero:gpu export ZE_AFFINITY_MASK=0 ./demo
Flag | Default Value | Description |
---|---|---|
-mllvm -asan-spir-locals=0 | 1 | 1 |
Enable ASan detection for local memory. Set the value to 0 to disable this check. Use the runtime flag: detect_locals. |
-mllvm -asan-spir-privates=0 | 1 | 1 |
Enable ASan detection for private memory. Set the value to 0 to disable this check. Use the runtime flag: detect_privates |
Runtime Flags
Runtime flags can be passed to the device-side ASan with the UR_LAYER_ASAN_OPTIONS environment variable, shown in the following example:
UR_LAYER_ASAN_OPTIONS=redzone:32 ./demo UR_LAYER_ASAN_OPTIONS="quarantine_size_mb:0; print_stats:1" ./demo
Flag | Default Value | Description |
---|---|---|
detect_kernel_arguments | true |
Enable runtime support for detecting invalid kernel arguments, such as using pointers from different context or device. |
detect_leaks | true |
Enable memory leak detection. |
detect_locals | true |
Enable runtime support for detecting out-of-bounds errors on local memory, such as shared local memory (SLM). |
detect_privates | true |
Enable runtime support for detecting out-of-bounds errors on private memory. |
halt_on_error | true |
Crash the program after printing the first error report. The flag is only effective if your code was compiled with the -fsanitize-recover=address compile option. |
print_stats | false |
Print memory overhead statistics after printing an error message. |
quarantine_size_mb | 0 |
The size (in MB) of quarantine used to detect use-after-free errors. Lower values may reduce memory usage, but increase the chance of false negatives. The default value is 0, indicating that while the sanitizer continues to detect use-after-free errors, it does not employ quarantine to minimize false negatives, thereby reducing memory overhead. |
redzone | 16 |
Minimal size (in bytes) of redzones around USM heap objects. Requirement: redzone >= 16, is a power of two. |
Device-Side MemorySanitizer
The device-side MemorySanitizer (MSan), a tool in LLVM used to detect the use of uninitialized memory (UUM) in C/C++ code, supports OpenMP and SYCL device code starting with the 2025.1 release. To activate this feature for device code, use the -Xarch_device -fsanitize=memory options when compiling your source code. This SYCL accelerator extension provides a device-side MSan, focusing on device USM to address common use cases.
Support was extended in 2025.2 release to include a local and private memory check. You can enable this feature by configuring the following compiler options.
OpenMP
Compiling and running OpenMP C/C++ code with MSan enabled:
- Compile your OpenMP C/C++ example with device-side MSan enabled:
icpx -fiopenmp -fopenmp-targets=spir64 -Xarch_device -fsanitize=memory -g -o demo demo.cpp
- Run your example on GPU:
export LIBOMPTARGET_PLUGIN=unified_runtime export UR_ENABLE_LAYERS=UR_LAYER_MSAN export ZE_AFFINITY_MASK=0 ./demo
SYCL
Compiling and running SYCL code with MSan enabled:
- Compile your SYCL example with device-side MSan enabled:
icpx -fsycl -Xarch_device -fsanitize=memory -g -o demo demo.cpp
- Run your example on GPU:
export ZE_AFFINITY_MASK=0 export ONEAPI_DEVICE_SELECTOR=level_zero:gpu ./demo
- Run your example on CPU:
export ONEAPI_DEVICE_SELECTOR=opencl:cpu ./demo
Flag | Default Value | Description |
---|---|---|
-mllvm -msan-spir-locals=0 | 1 | 1 |
Enable MSan detection for local memory. Set the value to 0 to disable this check. |
-mllvm -msan-spir-privates=0 | 1 | 1 |
Enable MSan detection for private memory. Set the value to 0 to disable this check. |
Runtime Flags
Runtime flags can be passed to the device-side MSan with the UR_LAYER_MSAN_OPTIONS environment variable, shown in the following example:
UR_LAYER_MSAN_OPTIONS=recover:true ./demo
Flag | Default Value | Description |
---|---|---|
recover | false |
Terminate the kernel execution after detecting the first error. If its value is true, the kernel will continue executing even after an error is detected. |
Device-Side ThreadSanitizer
The device-side ThreadSanitizer (TSan), a tool in LLVM used to detect data races in C/C++ code, supports OpenMP and SYCL device code starting with the Intel® oneAPI DPC++/C++ Compiler 2025.2 release. To activate this feature for device code, use the -Xarch_device -fsanitize= thread options when compiling your source code, focusing on device USM to address common use cases.
Compiling and running OpenMP code with TSan enabled:
- Compile your OpenMP C/C++ example with device-side TSan enabled:
icpx -fiopenmp -fopenmp-targets=spir64 -Xarch_device -fsanitize=thread -g -o demo demo.cpp
- Run your example on GPU:
export LIBOMPTARGET_PLUGIN=unified_runtime export UR_ENABLE_LAYERS=UR_LAYER_TSAN export ZE_AFFINITY_MASK=0 ./demo
SYCL
Compiling and running OpenMP code with TSan enabled:
- Compile your SYCL example with device-side TSan enabled:
icpx -fsycl -Xarch_device -fsanitize=thread -g -o demo demo.cpp
- Run your example on GPU:
export ZE_AFFINITY_MASK=0 export ONEAPI_DEVICE_SELECTOR=level_zero:gpu ./demo
- Run your example on CPU:
export ONEAPI_DEVICE_SELECTOR=opencl:cpu ./demo