-
Notifications
You must be signed in to change notification settings - Fork 769
[DeviceSanitizer] Support multiple error reports (-fsanitize-recover=address) #13948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
9615480
90cfa79
d094485
2e3b590
9dca074
2c85b6f
da0db46
9a37182
fe8247d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,16 +63,19 @@ struct LocalArgsInfo { | |
uint64_t SizeWithRedZone = 0; | ||
}; | ||
|
||
constexpr std::size_t ASAN_MAX_NUM_REPORTS = 10; | ||
|
||
struct LaunchInfo { | ||
uintptr_t PrivateShadowOffset = | ||
0; // don't move this field, we use it in AddressSanitizerPass | ||
// Don't move this field, we use it in AddressSanitizerPass | ||
uintptr_t PrivateShadowOffset = 0; | ||
|
||
uintptr_t LocalShadowOffset = 0; | ||
uintptr_t LocalShadowOffsetEnd = 0; | ||
DeviceSanitizerReport SanitizerReport; | ||
|
||
uint32_t NumLocalArgs = 0; | ||
LocalArgsInfo *LocalArgs = nullptr; // ordered by ArgIndex | ||
LocalArgsInfo *LocalArgs = nullptr; // Ordered by ArgIndex | ||
|
||
DeviceSanitizerReport SanitizerReport[ASAN_MAX_NUM_REPORTS]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any concerns about register-pressure related to this? Would it make sense to somehow let users use a more light-weight version with fewer reports? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
|
||
constexpr unsigned ASAN_SHADOW_SCALE = 3; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,8 +286,17 @@ bool MemIsZero(__SYCL_GLOBAL__ const char *beg, uptr size) { | |
bool __asan_internal_report_save(DeviceSanitizerErrorType error_type) { | ||
const int Expected = ASAN_REPORT_NONE; | ||
int Desired = ASAN_REPORT_START; | ||
auto &SanitizerReport = | ||
((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->SanitizerReport; | ||
|
||
// work-group linear id | ||
const auto WG_LID = | ||
__spirv_BuiltInWorkgroupId.x * __spirv_BuiltInNumWorkgroups.y * | ||
__spirv_BuiltInNumWorkgroups.z + | ||
__spirv_BuiltInWorkgroupId.y * __spirv_BuiltInNumWorkgroups.z + | ||
__spirv_BuiltInWorkgroupId.z; | ||
|
||
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo) | ||
->SanitizerReport[WG_LID % ASAN_MAX_NUM_REPORTS]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given an error in a workgroup and another error in an another workgroup, these two errors may be saved to the same index and either of them has a chance to be kept. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What does predicable mean here? Maybe it would be better to save more different types of error, but it's too complicated to implement now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right, order is indeterministic. Could you please elaborate why we can't guarantee that all of the two errors are not reported in my case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't understand, why does either of them has a chance to be kept? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the order of workgroups execution is indeterministic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep. I think it's okay to save either one. |
||
|
||
if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) == | ||
Expected) { | ||
SanitizerReport.ErrorType = error_type; | ||
|
@@ -315,8 +324,15 @@ bool __asan_internal_report_save( | |
launch_info->NumLocalArgs, launch_info->LocalArgs); | ||
} | ||
|
||
auto &SanitizerReport = | ||
((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->SanitizerReport; | ||
// work-group linear id | ||
const auto WG_LID = | ||
__spirv_BuiltInWorkgroupId.x * __spirv_BuiltInNumWorkgroups.y * | ||
__spirv_BuiltInNumWorkgroups.z + | ||
__spirv_BuiltInWorkgroupId.y * __spirv_BuiltInNumWorkgroups.z + | ||
__spirv_BuiltInWorkgroupId.z; | ||
|
||
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo) | ||
->SanitizerReport[WG_LID % ASAN_MAX_NUM_REPORTS]; | ||
|
||
if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) == | ||
Expected) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,14 +99,14 @@ if(SYCL_PI_UR_USE_FETCH_CONTENT) | |
CACHE PATH "Path to external '${name}' adapter source dir" FORCE) | ||
endfunction() | ||
|
||
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git") | ||
# commit 4f105262c30ac231b8db1e250f36e88ef9f0a36d | ||
# Merge: 0f118d75 92fce2ee | ||
set(UNIFIED_RUNTIME_REPO "https://github.com/AllanZyne/unified-runtime.git") | ||
AllanZyne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# commit 396fb20498c315a526c961d7cb645b42795acd2c | ||
# Merge: 719bb9cd e2ffea69 | ||
# Author: Kenneth Benzie (Benie) <[email protected]> | ||
# Date: Mon Jun 10 13:23:16 2024 +0100 | ||
# Merge pull request #1409 from omarahmed1111/Add-CTS-tests-for-image-format | ||
# [CTS] Add CTS tests for urMemImageCreate entry-point | ||
set(UNIFIED_RUNTIME_TAG 4f105262c30ac231b8db1e250f36e88ef9f0a36d) | ||
# Date: Thu May 23 10:53:03 2024 +0100 | ||
# Merge pull request #1501 from RossBrunton/ross/kerneltests | ||
# [Testing] Spec clarifications and testing updates for kernel | ||
set(UNIFIED_RUNTIME_TAG review/yang/multiple_reports) | ||
AllanZyne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fetch_adapter_source(level_zero | ||
${UNIFIED_RUNTIME_REPO} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// REQUIRES: linux, cpu | ||
// RUN: %{build} %device_asan_flags -Xarch_device -fsanitize-recover=address -O2 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} %t 2>&1 | FileCheck %s | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
int main() { | ||
sycl::queue Q; | ||
constexpr std::size_t N = 4; | ||
auto *array = sycl::malloc_device<int>(N, Q); | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class Kernel1>( | ||
sycl::nd_range<1>(N + 1, 1), | ||
[=](sycl::nd_item<1> item) { ++array[item.get_global_id(0)]; }); | ||
}).wait(); | ||
// CHECK: ERROR: DeviceSanitizer: out-of-bounds-access on Device USM | ||
// CHECK: {{READ of size 4 at kernel <.*Kernel1> LID\(0, 0, 0\) GID\(4, 0, 0\)}} | ||
// CHECK: {{ #0 .* .*multiple_kernels.cpp:}}[[@LINE-4]] | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class Kernel2>( | ||
sycl::nd_range<1>(N + 1, 1), | ||
[=](sycl::nd_item<1> item) { ++array[item.get_global_id(0)]; }); | ||
}).wait(); | ||
// CHECK: ERROR: DeviceSanitizer: out-of-bounds-access on Device USM | ||
// CHECK: {{READ of size 4 at kernel <.*Kernel2> LID\(0, 0, 0\) GID\(4, 0, 0\)}} | ||
// CHECK: {{ #0 .* .*multiple_kernels.cpp:}}[[@LINE-4]] | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class Kernel3>( | ||
sycl::nd_range<1>(N + 1, 1), | ||
[=](sycl::nd_item<1> item) { ++array[item.get_global_id(0)]; }); | ||
}).wait(); | ||
// CHECK: ERROR: DeviceSanitizer: out-of-bounds-access on Device USM | ||
// CHECK: {{READ of size 4 at kernel <.*Kernel3> LID\(0, 0, 0\) GID\(4, 0, 0\)}} | ||
// CHECK: {{ #0 .* .*multiple_kernels.cpp:}}[[@LINE-4]] | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class Kernel4>( | ||
sycl::nd_range<1>(N + 1, 1), | ||
[=](sycl::nd_item<1> item) { ++array[item.get_global_id(0)]; }); | ||
}).wait(); | ||
// CHECK: ERROR: DeviceSanitizer: out-of-bounds-access on Device USM | ||
// CHECK: {{READ of size 4 at kernel <.*Kernel4> LID\(0, 0, 0\) GID\(4, 0, 0\)}} | ||
// CHECK: {{ #0 .* .*multiple_kernels.cpp:}}[[@LINE-4]] | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// REQUIRES: linux, cpu | ||
// RUN: %{build} %device_asan_flags -Xarch_device -fsanitize-recover=address -O2 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} %t 2>&1 | FileCheck %s | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
int main() { | ||
sycl::queue Q; | ||
constexpr std::size_t N = 1024; | ||
auto *array = sycl::malloc_device<int>(N, Q); | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class Kernel>( | ||
sycl::nd_range<1>(N + 20, 1), | ||
[=](sycl::nd_item<1> item) { ++array[item.get_global_id(0)]; }); | ||
}).wait(); | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK: ====ERROR: DeviceSanitizer | ||
// CHECK-NOT: ====ERROR: DeviceSanitizer | ||
|
||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.