Skip to content

Commit ca67394

Browse files
committed
[ASAN] Intercept urProgramLink to enable asan layer for openmp offloading
Signed-off-by: jinge90 <[email protected]>
1 parent 6513abc commit ca67394

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,28 @@ ur_result_t SanitizerInterceptor::enqueueAllocInfo(
537537
}
538538

539539
// Left red zone
540-
UR_CALL(enqueueMemSetShadow(Context, Device, Queue, AllocInfo->AllocBegin,
541-
AllocInfo->UserBegin - AllocInfo->AllocBegin,
542-
ShadowByte, LastEvent, &LastEvent));
540+
uptr LeftRZSize = AllocInfo->UserBegin - AllocInfo->AllocBegin;
541+
if (LeftRZSize != 0) {
542+
UR_CALL(enqueueMemSetShadow(Context, Device, Queue,
543+
AllocInfo->AllocBegin, LeftRZSize,
544+
ShadowByte, LastEvent, &LastEvent));
545+
} else {
546+
context.logger.debug(
547+
"Try to create empty left red zone, Alloc Begin {}",
548+
(void *)AllocInfo->AllocBegin);
549+
}
543550

544551
// Right red zone
545-
UR_CALL(enqueueMemSetShadow(Context, Device, Queue, TailBegin,
546-
TailEnd - TailBegin, ShadowByte, LastEvent,
547-
&LastEvent));
552+
uptr RightRZSize = TailEnd - TailBegin;
553+
if (RightRZSize != 0) {
554+
UR_CALL(enqueueMemSetShadow(Context, Device, Queue, TailBegin,
555+
RightRZSize, ShadowByte, LastEvent,
556+
&LastEvent));
557+
} else {
558+
context.logger.debug(
559+
"Try to create empty right red zone, Alloc Begin {}",
560+
(void *)TailBegin);
561+
}
548562

549563
return UR_RESULT_SUCCESS;
550564
}

source/loader/layers/sanitizer/ur_sanddi.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,35 @@ __urdlllocal ur_result_t UR_APICALL urProgramBuild(
178178
return UR_RESULT_SUCCESS;
179179
}
180180

181+
///////////////////////////////////////////////////////////////////////////////
182+
/// @brief Intercept function for urProgramLink
183+
/// TODO: It is technically possible that user directly calls urProgramLinkExp
184+
/// instead of urProgramLink, intercept urProgramLinkExp if that happens.
185+
__urdlllocal ur_result_t UR_APICALL urProgramLink(
186+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
187+
uint32_t count, ///< [in] number of program handles in `phPrograms`.
188+
const ur_program_handle_t *
189+
phPrograms, ///< [in][range(0, count)] pointer to array of program handles.
190+
const char *
191+
pOptions, ///< [in][optional] pointer to linker options null-terminated string.
192+
ur_program_handle_t
193+
*phProgram ///< [out] pointer to handle of program object created.
194+
) {
195+
auto pfnProgramLink = context.urDdiTable.Program.pfnLink;
196+
197+
if (nullptr == pfnProgramLink) {
198+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
199+
}
200+
201+
context.logger.debug("==== urProgramLink");
202+
203+
UR_CALL(pfnProgramLink(hContext, count, phPrograms, pOptions, phProgram));
204+
205+
UR_CALL(context.interceptor->registerDeviceGlobals(hContext, *phProgram));
206+
207+
return UR_RESULT_SUCCESS;
208+
}
209+
181210
///////////////////////////////////////////////////////////////////////////////
182211
/// @brief Intercept function for urEnqueueKernelLaunch
183212
__urdlllocal ur_result_t UR_APICALL urEnqueueKernelLaunch(
@@ -422,6 +451,7 @@ __urdlllocal ur_result_t UR_APICALL urGetProgramProcAddrTable(
422451
}
423452

424453
pDdiTable->pfnBuild = ur_sanitizer_layer::urProgramBuild;
454+
pDdiTable->pfnLink = ur_sanitizer_layer::urProgramLink;
425455

426456
return UR_RESULT_SUCCESS;
427457
}

0 commit comments

Comments
 (0)