Skip to content

Commit 13e84cf

Browse files
zhaomaosupbalcer
andauthored
[DeviceSanitizer] Only allows to report one error per each kernel launch (#15326)
When error is detected, the corresponding work-item will exit without unpoisoning local/private shadow memory. Then other work-items are easy to cause false alarms. So, we only allows to report one error per each kernel launch by default. UR Part: oneapi-src/unified-runtime#2069 --------- Co-authored-by: Piotr Balcer <[email protected]>
1 parent 62f41d8 commit 13e84cf

File tree

5 files changed

+36
-175
lines changed

5 files changed

+36
-175
lines changed

libdevice/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ set(CMAKE_MODULE_PATH
88
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
99
)
1010

11+
if(EXISTS ${FETCHCONTENT_BASE_DIR}/unified-runtime-src)
12+
set(UR_SANITIZER_INCLUDE_DIR
13+
${FETCHCONTENT_BASE_DIR}/unified-runtime-src/source/loader/layers/sanitizer)
14+
elseif(EXISTS ${SYCL_UR_SOURCE_DIR})
15+
set(UR_SANITIZER_INCLUDE_DIR
16+
${SYCL_UR_SOURCE_DIR}/source/loader/layers/sanitizer)
17+
else()
18+
message(WARNING "Unified Runtime source directory is not provided, \
19+
will not build libdevice sanitizer")
20+
endif()
21+
1122
# Build libdevice for SYCL.
1223
include(SYCLLibdevice)
1324

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ set(cmath_obj_deps device_math.h device.h sycl-compiler)
200200
set(imf_obj_deps device_imf.hpp imf_half.hpp imf_bf16.hpp imf_rounding_op.hpp imf_impl_utils.hpp device.h sycl-compiler)
201201
set(itt_obj_deps device_itt.h spirv_vars.h device.h sycl-compiler)
202202
set(bfloat16_obj_deps sycl-headers sycl-compiler)
203-
if (NOT MSVC)
203+
if (NOT MSVC AND UR_SANITIZER_INCLUDE_DIR)
204204
set(sanitizer_obj_deps
205205
device.h atomic.hpp spirv_vars.h
206-
include/asan_libdevice.hpp
206+
${UR_SANITIZER_INCLUDE_DIR}/asan_libdevice.hpp
207207
include/sanitizer_utils.hpp
208208
include/spir_global_var.hpp
209209
sycl-compiler)
@@ -268,10 +268,12 @@ if(MSVC)
268268
SRC msvc_math.cpp
269269
DEPENDENCIES ${cmath_obj_deps})
270270
else()
271-
add_devicelibs(libsycl-sanitizer
272-
SRC sanitizer_utils.cpp
273-
DEPENDENCIES ${sanitizer_obj_deps}
274-
EXTRA_OPTS -fno-sycl-instrument-device-code)
271+
if(UR_SANITIZER_INCLUDE_DIR)
272+
add_devicelibs(libsycl-sanitizer
273+
SRC sanitizer_utils.cpp
274+
DEPENDENCIES ${sanitizer_obj_deps}
275+
EXTRA_OPTS -fno-sycl-instrument-device-code -I${UR_SANITIZER_INCLUDE_DIR})
276+
endif()
275277
endif()
276278

277279
add_devicelibs(libsycl-fallback-cassert

libdevice/include/asan_libdevice.hpp

Lines changed: 0 additions & 157 deletions
This file was deleted.

libdevice/sanitizer_utils.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "asan_libdevice.hpp"
910
#include "atomic.hpp"
1011
#include "device.h"
1112
#include "spirv_vars.h"
1213

13-
#include "include/asan_libdevice.hpp"
1414
#include "include/sanitizer_utils.hpp"
1515

1616
using uptr = uintptr_t;
@@ -381,8 +381,11 @@ void __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
381381
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
382382
->SanitizerReport[WG_LID % ASAN_MAX_NUM_REPORTS];
383383

384-
if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
385-
Expected) {
384+
if (atomicCompareAndSet(
385+
&(((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->ReportFlag), 1,
386+
0) == 0 &&
387+
atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
388+
Expected) {
386389
SanitizerReport.ErrorType = error_type;
387390
SanitizerReport.IsRecover = false;
388391

@@ -415,8 +418,12 @@ void __asan_internal_report_save(
415418
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
416419
->SanitizerReport[WG_LID % ASAN_MAX_NUM_REPORTS];
417420

418-
if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
419-
Expected) {
421+
if ((is_recover ||
422+
atomicCompareAndSet(
423+
&(((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->ReportFlag), 1,
424+
0) == 0) &&
425+
atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
426+
Expected) {
420427

421428
int FileLength = 0;
422429
int FuncLength = 0;
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# commit d3a518a2a621da6d78f8d25e8460fd3300fff705
2-
# Merge: ab0a706b 77975b87
3-
# Author: aarongreig <[email protected]>
4-
# Date: Fri Oct 25 16:45:53 2024 +0100
5-
# Merge pull request #2219 from kbenzie/benie/cl-adapter-opt-core-func
6-
# [CL] Support using old ICD loaders
7-
set(UNIFIED_RUNTIME_TAG d3a518a2a621da6d78f8d25e8460fd3300fff705)
1+
# commit 66ba7970a6badf781226b75a98c9585ef30ea93a
2+
# Author: Maosu Zhao <[email protected]>
3+
# Date: Mon Oct 28 18:39:57 2024 +0800
4+
# [DeviceSanitizer] Add a report flag to LaunchInfo (#2069)
5+
set(UNIFIED_RUNTIME_TAG 66ba7970a6badf781226b75a98c9585ef30ea93a)

0 commit comments

Comments
 (0)