Skip to content

Commit fa87eba

Browse files
committed
Apply copilot suggestions
1 parent 7af03c0 commit fa87eba

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

unified-runtime/source/loader/layers/sanitizer/asan/asan_ddi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,11 @@ ur_result_t UR_APICALL urEnqueueCooperativeKernelLaunchExp(
14361436
/// are not NULL, phEvent must not refer to an element of the
14371437
/// phEventWaitList array.
14381438
ur_event_handle_t *phEvent) {
1439+
// This mutex is to prevent concurrent kernel launches across different queues
1440+
// as the DeviceTSAN local shadow memory does not support concurrent
1441+
// kernel launches now.
1442+
std::scoped_lock<ur_shared_mutex> Guard(
1443+
getAsanInterceptor()->KernelLaunchMutex);
14391444

14401445
UR_LOG_L(getContext()->logger, DEBUG,
14411446
"==== urEnqueueCooperativeKernelLaunchExp");

unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ ur_result_t urEnqueueKernelLaunch(
421421
/// [out][optional] return an event object that identifies this
422422
/// particular kernel execution instance.
423423
ur_event_handle_t *phEvent) {
424+
// This mutex is to prevent concurrent kernel launches across different queues
425+
// as the DeviceMSAN local/private shadow memory does not support concurrent
426+
// kernel launches now.
427+
std::scoped_lock<ur_shared_mutex> Guard(
428+
getMsanInterceptor()->KernelLaunchMutex);
429+
424430
UR_LOG_L(getContext()->logger, DEBUG, "==== urEnqueueKernelLaunch");
425431

426432
USMLaunchInfo LaunchInfo(GetContext(hQueue), GetDevice(hQueue),
@@ -1346,6 +1352,11 @@ ur_result_t UR_APICALL urEnqueueCooperativeKernelLaunchExp(
13461352
/// are not NULL, phEvent must not refer to an element of the
13471353
/// phEventWaitList array.
13481354
ur_event_handle_t *phEvent) {
1355+
// This mutex is to prevent concurrent kernel launches across different queues
1356+
// as the DeviceTSAN local shadow memory does not support concurrent
1357+
// kernel launches now.
1358+
std::scoped_lock<ur_shared_mutex> Guard(
1359+
getMsanInterceptor()->KernelLaunchMutex);
13491360

13501361
UR_LOG_L(getContext()->logger, DEBUG,
13511362
"==== urEnqueueCooperativeKernelLaunchExp");

unified-runtime/source/loader/layers/sanitizer/msan/msan_interceptor.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ class MsanInterceptor {
337337

338338
bool isNormalExit() { return m_NormalExit; }
339339

340+
ur_shared_mutex KernelLaunchMutex;
341+
340342
private:
341343
/// Initialize Global Variables & Kernel Name at first Launch
342344
ur_result_t prepareLaunch(std::shared_ptr<msan::DeviceInfo> &DeviceInfo,

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_ddi.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,12 @@ ur_result_t urEnqueueKernelLaunch(
11631163
/// [out][optional] return an event object that identifies this
11641164
/// particular kernel execution instance.
11651165
ur_event_handle_t *phEvent) {
1166+
// This mutex is to prevent concurrent kernel launches across different queues
1167+
// as the DeviceTSAN local shadow memory does not support concurrent
1168+
// kernel launches now.
1169+
std::scoped_lock<ur_shared_mutex> Guard(
1170+
getTsanInterceptor()->KernelLaunchMutex);
1171+
11661172
UR_LOG_L(getContext()->logger, DEBUG, "==== urEnqueueKernelLaunch");
11671173

11681174
LaunchInfo LaunchInfo(GetContext(hQueue), GetDevice(hQueue), pGlobalWorkSize,
@@ -1212,6 +1218,12 @@ ur_result_t UR_APICALL urEnqueueCooperativeKernelLaunchExp(
12121218
/// are not NULL, phEvent must not refer to an element of the
12131219
/// phEventWaitList array.
12141220
ur_event_handle_t *phEvent) {
1221+
// This mutex is to prevent concurrent kernel launches across different queues
1222+
// as the DeviceTSAN local shadow memory does not support concurrent
1223+
// kernel launches now.
1224+
std::scoped_lock<ur_shared_mutex> Guard(
1225+
getTsanInterceptor()->KernelLaunchMutex);
1226+
12151227
UR_LOG_L(getContext()->logger, DEBUG,
12161228
"==== urEnqueueCooperativeKernelLaunchExp");
12171229

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_interceptor.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ class TsanInterceptor {
226226
return m_KernelMap[Kernel];
227227
}
228228

229+
ur_shared_mutex KernelLaunchMutex;
230+
229231
private:
230232
ur_result_t updateShadowMemory(std::shared_ptr<ContextInfo> &CI,
231233
std::shared_ptr<DeviceInfo> &DI,

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_shadow.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ ur_result_t ShadowMemoryGPU::AllocLocalShadow(ur_queue_handle_t Queue,
196196
uptr &End) {
197197
const size_t LocalMemorySize = GetDeviceLocalMemorySize(Device);
198198
const size_t RequiredShadowSize = NumWG * LocalMemorySize;
199-
static size_t LastAllocedSize = 0;
200-
if (RequiredShadowSize > LastAllocedSize) {
199+
static size_t LastAllocatedSize = 0;
200+
if (RequiredShadowSize > LastAllocatedSize) {
201201
if (LocalShadowOffset) {
202202
UR_CALL(getContext()->urDdiTable.USM.pfnFree(Context,
203203
(void *)LocalShadowOffset));
204204
LocalShadowOffset = 0;
205-
LastAllocedSize = 0;
205+
LastAllocatedSize = 0;
206206
}
207207

208208
UR_CALL(getContext()->urDdiTable.USM.pfnDeviceAlloc(
@@ -216,12 +216,12 @@ ur_result_t ShadowMemoryGPU::AllocLocalShadow(ur_queue_handle_t Queue,
216216
UR_CALL(getContext()->urDdiTable.USM.pfnFree(Context,
217217
(void *)LocalShadowOffset));
218218
LocalShadowOffset = 0;
219-
LastAllocedSize = 0;
219+
LastAllocatedSize = 0;
220220

221221
return URes;
222222
}
223223

224-
LastAllocedSize = RequiredShadowSize;
224+
LastAllocatedSize = RequiredShadowSize;
225225
}
226226

227227
Begin = LocalShadowOffset;

0 commit comments

Comments
 (0)