-
Notifications
You must be signed in to change notification settings - Fork 116
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
[UR][Layer] Add Sanitizer Layer #1074
Changes from 1 commit
4c9fe03
d6e589b
67fcd5e
1096b0f
c36bd72
6ba94ac
9ae8a99
9f90e43
336ce89
84a3afa
a8dadc1
4d63350
25b1183
e6bc306
23fb1b3
cb8a761
5c44b1d
a377c94
96eea7a
0a72ea9
8fa86dd
d9a51a7
730bf45
fed541a
ad2b1a7
dec5f32
ca58886
11cca13
3e6194e
89febf0
1b81df9
030400d
7208518
668a11e
f623135
7be8667
e4a47ac
61c0ca9
0ad1bb1
cc4402a
bf358c1
d5e7946
50666b7
de03096
b47ca29
1e2b6a0
42f6755
5aaba09
8dc90fd
3b819f6
54220e9
2328b48
e59d7c7
bba6f82
a084650
1148ccb
fa92f72
524a83d
e9a2093
a1c4ddc
71d8657
40b5ef6
0b00798
b29930b
c42bd9a
bc8cdb2
3bede09
5dc2d5c
30c0bc1
86d4056
49e2f4f
79998b9
6cc4913
577ddd3
4ee0e10
dc127d5
b59d931
28315db
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 |
---|---|---|
|
@@ -88,11 +88,14 @@ ur_result_t SanitizerInterceptor::allocateMemory( | |
assert(Alignment == 0 || IsPowerOfTwo(Alignment)); | ||
|
||
auto ContextInfo = getContextInfo(Context); | ||
// Device is nullptr if Type == USMMemoryType::HOST | ||
auto DeviceInfo = ContextInfo->getDeviceInfo(Device); | ||
std::shared_ptr<DeviceInfo> DeviceInfo; | ||
if (Device) { | ||
DeviceInfo = ContextInfo->getDeviceInfo(Device); | ||
} | ||
|
||
if (Alignment == 0) { | ||
Alignment = DeviceInfo->Alignment; | ||
Alignment = | ||
DeviceInfo ? DeviceInfo->Alignment : ASAN_SHADOW_GRANULARITY; | ||
} | ||
|
||
// Copy from LLVM compiler-rt/lib/asan | ||
|
@@ -133,9 +136,15 @@ ur_result_t SanitizerInterceptor::allocateMemory( | |
USMAllocInfo{AllocBegin, UserBegin, UserEnd, NeededSize, Type}); | ||
|
||
// For updating shadow memory | ||
{ | ||
if (DeviceInfo) { // device/shared USM | ||
std::scoped_lock<ur_shared_mutex> Guard(DeviceInfo->Mutex); | ||
DeviceInfo->AllocInfos.emplace_back(AllocInfo); | ||
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 think 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, thanks for pointing this issue. |
||
} else { // host USM's AllocInfo needs to insert into all devices | ||
for (auto &pair : ContextInfo->DeviceMap) { | ||
auto DeviceInfo = pair.second; | ||
std::scoped_lock<ur_shared_mutex> Guard(DeviceInfo->Mutex); | ||
DeviceInfo->AllocInfos.emplace_back(AllocInfo); | ||
} | ||
} | ||
|
||
// For memory release | ||
|
@@ -185,9 +194,7 @@ ur_result_t SanitizerInterceptor::releaseMemory(ur_context_handle_t Context, | |
|
||
bool SanitizerInterceptor::preLaunchKernel(ur_kernel_handle_t Kernel, | ||
ur_queue_handle_t Queue, | ||
ur_event_handle_t *Event) { | ||
assert(Event != nullptr); | ||
|
||
ur_event_handle_t &Event) { | ||
AllanZyne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prepareLaunch(Queue, Kernel); | ||
|
||
UR_CALL(updateShadowMemory(Queue)); | ||
|
@@ -198,15 +205,15 @@ bool SanitizerInterceptor::preLaunchKernel(ur_kernel_handle_t Kernel, | |
auto QueueInfo = ContextInfo->getQueueInfo(Queue); | ||
|
||
std::scoped_lock<ur_mutex> Guard(QueueInfo->Mutex); | ||
*Event = QueueInfo->LastEvent; | ||
Event = QueueInfo->LastEvent; | ||
QueueInfo->LastEvent = nullptr; | ||
|
||
return true; | ||
} | ||
|
||
void SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel, | ||
ur_queue_handle_t Queue, | ||
ur_event_handle_t *Event) { | ||
ur_event_handle_t &Event) { | ||
auto Program = getProgram(Kernel); | ||
ur_event_handle_t ReadEvent{}; | ||
|
||
|
@@ -215,16 +222,10 @@ void SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel, | |
auto Result = context.urDdiTable.Enqueue.pfnDeviceGlobalVariableRead( | ||
Queue, Program, kSPIR_DeviceSanitizerReportMem, true, | ||
sizeof(SPIR_DeviceSanitizerReportMem), 0, | ||
&SPIR_DeviceSanitizerReportMem, Event ? 1 : 0, Event, &ReadEvent); | ||
&SPIR_DeviceSanitizerReportMem, 1, &Event, &ReadEvent); | ||
|
||
if (Result == UR_RESULT_SUCCESS) { | ||
if (Event) { | ||
*Event = ReadEvent; | ||
} else { | ||
[[maybe_unused]] auto Result = | ||
context.urDdiTable.Event.pfnWait(1, &ReadEvent); | ||
assert(Result == UR_RESULT_SUCCESS); | ||
} | ||
Event = ReadEvent; | ||
|
||
auto AH = &SPIR_DeviceSanitizerReportMem; | ||
if (!AH->Flag) { | ||
|
@@ -476,12 +477,6 @@ ur_result_t SanitizerInterceptor::updateShadowMemory(ur_queue_handle_t Queue) { | |
|
||
ur_event_handle_t LastEvent = QueueInfo->LastEvent; | ||
|
||
// FIXME: Always update host USM, but it'd be better to update host USM | ||
// selectively, or each devices once | ||
for (auto &AllocInfo : HostInfo->AllocInfos) { | ||
UR_CALL(enqueueAllocInfo(Context, Device, Queue, AllocInfo, LastEvent)); | ||
} | ||
|
||
for (auto &AllocInfo : DeviceInfo->AllocInfos) { | ||
UR_CALL(enqueueAllocInfo(Context, Device, Queue, AllocInfo, LastEvent)); | ||
} | ||
|
@@ -495,17 +490,6 @@ ur_result_t SanitizerInterceptor::updateShadowMemory(ur_queue_handle_t Queue) { | |
ur_result_t SanitizerInterceptor::insertContext(ur_context_handle_t Context) { | ||
auto ContextInfo = std::make_shared<ur_sanitizer_layer::ContextInfo>(); | ||
|
||
// Host Device | ||
auto DeviceInfo = std::make_shared<ur_sanitizer_layer::DeviceInfo>(); | ||
DeviceInfo->Type = DeviceType::CPU; | ||
DeviceInfo->Alignment = ASAN_SHADOW_GRANULARITY; | ||
|
||
// TODO: Check if host asan is enabled | ||
DeviceInfo->ShadowOffset = 0; | ||
DeviceInfo->ShadowOffsetEnd = 0; | ||
|
||
ContextInfo->DeviceMap.emplace(nullptr, std::move(DeviceInfo)); | ||
|
||
std::scoped_lock<ur_shared_mutex> Guard(m_ContextMapMutex); | ||
assert(m_ContextMap.find(Context) == m_ContextMap.end()); | ||
m_ContextMap.emplace(Context, std::move(ContextInfo)); | ||
AllanZyne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
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.
nit: brace not needed for single line code according to llvm coding style. What's the coding style using in UR? Please also see other changes in this commit.
Is the 4-space indent aligning with UR coding style?
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.
I searched some of UR codes, they add braces for single line code as well.
Yes.