-
Notifications
You must be signed in to change notification settings - Fork 738
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
[SYCL][DeviceSanitizer] Checking "sycl::free" related errors #12882
Changes from 108 commits
3d7882b
7bf11b1
13304f9
eb3ae88
f8f76de
e58fa03
ff8449b
fc40624
f153c32
10b83d9
b9d0809
727a642
fb52e33
1b9e96e
006a1e5
f423014
f51e62d
874a38e
caecf6b
47bd3f1
aaa1b80
5f9de16
66895de
1e32baa
ba03cd7
3c921af
eb4a904
15afd9a
27545b5
ad5c2bc
8ca76b7
2c75324
58b8489
4d34fef
163ffda
77e53c4
c30e14f
fc41411
a3a7b36
9707887
2776d4a
f3eadd7
b3d4fe7
9ea798e
32cf548
5e6d983
703b940
04cb89b
0fd1844
b56b333
b241cea
84e8500
34ebffe
6cc327a
ca6ed6b
641bc4b
edb9080
4843366
09e175f
ab6975c
e3788ad
005f463
1a906d2
b2d1109
646b684
4e562eb
8fdf0e3
4f3a415
ee34c0b
7e89aff
090271e
ce226f7
49a4f9e
d81456a
053f17a
5a07c81
e297e4b
5325526
d739818
7d93f23
a35044a
d4ef3c2
0178c1d
7fda0b9
d28267d
e488394
29c1d9e
a5c740d
aded3b9
8b55ebb
a8a19eb
5bf6ed8
a6e0330
0768bd6
61c6a0d
0fda5c2
a718182
dd8e7c8
d9f4f57
97ec20c
dcd9c05
7947ad9
dd653ee
e40a20a
66c4ccf
8367ad1
24535c1
6fe6a8f
b9c0aed
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,155 @@ | ||||||
//===---- asan_libdevice.hpp - Structure and declaration for sanitizer ----===// | ||||||
// | ||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||
// See https://llvm.org/LICENSE.txt for license information. | ||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||
// | ||||||
//===----------------------------------------------------------------------===// | ||||||
#pragma once | ||||||
|
||||||
#include <cinttypes> | ||||||
|
||||||
// NOTE This file should be sync with | ||||||
// unified-runtime/source/loader/layers/sanitizer/device_sanitizer_report.hpp | ||||||
|
||||||
enum class DeviceSanitizerErrorType : int32_t { | ||||||
UNKNOWN, | ||||||
OUT_OF_BOUNDS, | ||||||
MISALIGNED, | ||||||
USE_AFTER_FREE, | ||||||
OUT_OF_SHADOW_BOUNDS, | ||||||
UNKNOWN_DEVICE, | ||||||
NULL_POINTER, | ||||||
}; | ||||||
|
||||||
enum class DeviceSanitizerMemoryType : int32_t { | ||||||
UNKNOWN, | ||||||
USM_DEVICE, | ||||||
USM_HOST, | ||||||
USM_SHARED, | ||||||
LOCAL, | ||||||
PRIVATE, | ||||||
MEM_BUFFER, | ||||||
DEVICE_GLOBAL, | ||||||
}; | ||||||
|
||||||
struct DeviceSanitizerReport { | ||||||
int Flag = 0; | ||||||
|
||||||
char File[256 + 1] = {}; | ||||||
char Func[256 + 1] = {}; | ||||||
|
||||||
int32_t Line = 0; | ||||||
|
||||||
uint64_t GID0 = 0; | ||||||
uint64_t GID1 = 0; | ||||||
uint64_t GID2 = 0; | ||||||
|
||||||
uint64_t LID0 = 0; | ||||||
uint64_t LID1 = 0; | ||||||
uint64_t LID2 = 0; | ||||||
|
||||||
uintptr_t Address = 0; | ||||||
bool IsWrite = false; | ||||||
uint32_t AccessSize = 0; | ||||||
DeviceSanitizerMemoryType MemoryType = DeviceSanitizerMemoryType::UNKNOWN; | ||||||
DeviceSanitizerErrorType ErrorType = DeviceSanitizerErrorType::UNKNOWN; | ||||||
|
||||||
bool IsRecover = false; | ||||||
}; | ||||||
|
||||||
struct LocalArgsInfo { | ||||||
uint32_t ArgIndex = 0; | ||||||
uint64_t Size = 0; | ||||||
uint64_t SizeWithRedZone = 0; | ||||||
}; | ||||||
|
||||||
struct LaunchInfo { | ||||||
uintptr_t PrivateShadowOffset = | ||||||
0; // don't move this field, we use it in AddressSanitizerPass | ||||||
|
||||||
uintptr_t LocalShadowOffset = 0; | ||||||
uintptr_t LocalShadowOffsetEnd = 0; | ||||||
DeviceSanitizerReport SanitizerReport; | ||||||
|
||||||
uint32_t NumLocalArgs = 0; | ||||||
LocalArgsInfo *LocalArgs = nullptr; // ordered by ArgIndex | ||||||
}; | ||||||
|
||||||
constexpr unsigned ASAN_SHADOW_SCALE = 3; | ||||||
constexpr unsigned ASAN_SHADOW_GRANULARITY = 1ULL << ASAN_SHADOW_SCALE; | ||||||
|
||||||
// Based on the observation, only the last 24 bits of the address of the private | ||||||
// variable have changed, we use 31 bits(2G) to be safe. | ||||||
constexpr std::size_t ASAN_PRIVATE_SIZE = 0x7fffffffULL + 1; | ||||||
|
||||||
// These magic values are written to shadow for better error | ||||||
// reporting. | ||||||
constexpr int kUsmDeviceRedzoneMagic = (char)0x81; | ||||||
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.
Suggested change
is the cast necessary? 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. yes, it's necessary, if not, 0x81 will be treated as unsigned 0x81. |
||||||
constexpr int kUsmHostRedzoneMagic = (char)0x82; | ||||||
constexpr int kUsmSharedRedzoneMagic = (char)0x83; | ||||||
constexpr int kMemBufferRedzoneMagic = (char)0x84; | ||||||
constexpr int kDeviceGlobalRedzoneMagic = (char)0x85; | ||||||
constexpr int kNullPointerRedzoneMagic = (char)0x86; | ||||||
|
||||||
constexpr int kUsmDeviceDeallocatedMagic = (char)0x91; | ||||||
constexpr int kUsmHostDeallocatedMagic = (char)0x92; | ||||||
constexpr int kUsmSharedDeallocatedMagic = (char)0x93; | ||||||
constexpr int kMemBufferDeallocatedMagic = (char)0x93; | ||||||
|
||||||
constexpr int kSharedLocalRedzoneMagic = (char)0xa1; | ||||||
|
||||||
// Same with host ASan stack | ||||||
const int kPrivateLeftRedzoneMagic = (char)0xf1; | ||||||
const int kPrivateMidRedzoneMagic = (char)0xf2; | ||||||
const int kPrivateRightRedzoneMagic = (char)0xf3; | ||||||
|
||||||
constexpr auto kSPIR_AsanShadowMemoryGlobalStart = | ||||||
"__AsanShadowMemoryGlobalStart"; | ||||||
constexpr auto kSPIR_AsanShadowMemoryGlobalEnd = "__AsanShadowMemoryGlobalEnd"; | ||||||
|
||||||
constexpr auto kSPIR_DeviceType = "__DeviceType"; | ||||||
constexpr auto kSPIR_AsanDebug = "__AsanDebug"; | ||||||
|
||||||
constexpr auto kSPIR_AsanDeviceGlobalCount = "__AsanDeviceGlobalCount"; | ||||||
constexpr auto kSPIR_AsanDeviceGlobalMetadata = "__AsanDeviceGlobalMetadata"; | ||||||
|
||||||
inline const char *ToString(DeviceSanitizerMemoryType MemoryType) { | ||||||
switch (MemoryType) { | ||||||
case DeviceSanitizerMemoryType::USM_DEVICE: | ||||||
return "Device USM"; | ||||||
case DeviceSanitizerMemoryType::USM_HOST: | ||||||
return "Host USM"; | ||||||
case DeviceSanitizerMemoryType::USM_SHARED: | ||||||
return "Shared USM"; | ||||||
case DeviceSanitizerMemoryType::LOCAL: | ||||||
return "Local Memory"; | ||||||
case DeviceSanitizerMemoryType::PRIVATE: | ||||||
return "Private Memory"; | ||||||
case DeviceSanitizerMemoryType::MEM_BUFFER: | ||||||
return "Memory Buffer"; | ||||||
case DeviceSanitizerMemoryType::DEVICE_GLOBAL: | ||||||
return "Device Global"; | ||||||
default: | ||||||
return "Unknown Memory"; | ||||||
} | ||||||
} | ||||||
|
||||||
inline const char *ToString(DeviceSanitizerErrorType ErrorType) { | ||||||
switch (ErrorType) { | ||||||
case DeviceSanitizerErrorType::OUT_OF_BOUNDS: | ||||||
return "out-of-bounds-access"; | ||||||
case DeviceSanitizerErrorType::MISALIGNED: | ||||||
return "misaligned-access"; | ||||||
case DeviceSanitizerErrorType::USE_AFTER_FREE: | ||||||
return "use-after-free"; | ||||||
case DeviceSanitizerErrorType::OUT_OF_SHADOW_BOUNDS: | ||||||
return "out-of-shadow-bounds-access"; | ||||||
case DeviceSanitizerErrorType::UNKNOWN_DEVICE: | ||||||
return "unknown-device"; | ||||||
case DeviceSanitizerErrorType::NULL_POINTER: | ||||||
return "null-pointer-access"; | ||||||
default: | ||||||
return "unknown-error"; | ||||||
} | ||||||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ class | |
T val; | ||
}; | ||
|
||
enum DeviceType : uintptr_t { UNKNOWN, CPU, GPU_PVC, GPU_DG2 }; | ||
enum DeviceType : uint64_t { UNKNOWN, CPU, GPU_PVC, GPU_DG2 }; | ||
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. should uint32_t be enough here? 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 tried uint32_t, but level zero failed to write global variable in uint32_t. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we make it a public header in UR and just include it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @aelovikov-intel
When building the whole project, clang is firstly built and libdevice is built using the fresh built clang, at that time, sycl/ur component hasn't been built and deployed, so we can only include standard c/c++ headers in libdevice.
Thanks very much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we change that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @aelovikov-intel
Since libdevice component is shared by sycl and omp and libdeivce is a parallel component with sycl and omp , so we intend to minimize its dependency on any sycl/omp specific header files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it apply to UR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @aelovikov-intel
libdevice is a small component, the only dependency is clang itself, there is no technical block including UR header here but it seems to be too "heavy" to introduce UR dependency in order to include a single header, all other functionalities except sanitizer will never depend on UR.
Thanks very much.