Skip to content

Commit a21402e

Browse files
authored
Merge pull request #1584 from zhaomaosu/simplify-device-global
[DeviceSanitizer] Remove device global "__AsanDeviceGlobalCount"
2 parents 98cb262 + 2d30aad commit a21402e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -417,22 +417,25 @@ ur_result_t SanitizerInterceptor::registerProgram(ur_context_handle_t Context,
417417
for (auto Device : Devices) {
418418
ManagedQueue Queue(Context, Device);
419419

420-
uint64_t NumOfDeviceGlobal;
420+
size_t MetadataSize;
421+
void *MetadataPtr;
421422
auto Result =
422-
getContext()->urDdiTable.Enqueue.pfnDeviceGlobalVariableRead(
423-
Queue, Program, kSPIR_AsanDeviceGlobalCount, true,
424-
sizeof(NumOfDeviceGlobal), 0, &NumOfDeviceGlobal, 0, nullptr,
425-
nullptr);
423+
getContext()->urDdiTable.Program.pfnGetGlobalVariablePointer(
424+
Device, Program, kSPIR_AsanDeviceGlobalMetadata, &MetadataSize,
425+
&MetadataPtr);
426426
if (Result != UR_RESULT_SUCCESS) {
427427
getContext()->logger.info("No device globals");
428428
continue;
429429
}
430430

431+
const uint64_t NumOfDeviceGlobal =
432+
MetadataSize / sizeof(DeviceGlobalInfo);
433+
assert((MetadataSize % sizeof(DeviceGlobalInfo) == 0) &&
434+
"DeviceGlobal metadata size is not correct");
431435
std::vector<DeviceGlobalInfo> GVInfos(NumOfDeviceGlobal);
432-
Result = getContext()->urDdiTable.Enqueue.pfnDeviceGlobalVariableRead(
433-
Queue, Program, kSPIR_AsanDeviceGlobalMetadata, true,
434-
sizeof(DeviceGlobalInfo) * NumOfDeviceGlobal, 0, &GVInfos[0], 0,
435-
nullptr, nullptr);
436+
Result = getContext()->urDdiTable.Enqueue.pfnUSMMemcpy(
437+
Queue, true, &GVInfos[0], MetadataPtr,
438+
sizeof(DeviceGlobalInfo) * NumOfDeviceGlobal, 0, nullptr, nullptr);
436439
if (Result != UR_RESULT_SUCCESS) {
437440
getContext()->logger.error("Device Global[{}] Read Failed: {}",
438441
kSPIR_AsanDeviceGlobalMetadata, Result);

source/loader/layers/sanitizer/asan_libdevice.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ const int kPrivateLeftRedzoneMagic = (char)0xf1;
121121
const int kPrivateMidRedzoneMagic = (char)0xf2;
122122
const int kPrivateRightRedzoneMagic = (char)0xf3;
123123

124-
constexpr auto kSPIR_AsanDeviceGlobalCount = "__AsanDeviceGlobalCount";
125124
constexpr auto kSPIR_AsanDeviceGlobalMetadata = "__AsanDeviceGlobalMetadata";
126125

127126
inline const char *ToString(DeviceSanitizerMemoryType MemoryType) {

0 commit comments

Comments
 (0)