Skip to content

Commit

Permalink
Merge pull request #1584 from zhaomaosu/simplify-device-global
Browse files Browse the repository at this point in the history
[DeviceSanitizer] Remove device global "__AsanDeviceGlobalCount"
  • Loading branch information
callumfare authored Nov 19, 2024
2 parents e3247c2 + e36941c commit 0ea47d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 12 additions & 9 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,22 +417,25 @@ ur_result_t SanitizerInterceptor::registerProgram(ur_context_handle_t Context,
for (auto Device : Devices) {
ManagedQueue Queue(Context, Device);

uint64_t NumOfDeviceGlobal;
size_t MetadataSize;
void *MetadataPtr;
auto Result =
getContext()->urDdiTable.Enqueue.pfnDeviceGlobalVariableRead(
Queue, Program, kSPIR_AsanDeviceGlobalCount, true,
sizeof(NumOfDeviceGlobal), 0, &NumOfDeviceGlobal, 0, nullptr,
nullptr);
getContext()->urDdiTable.Program.pfnGetGlobalVariablePointer(
Device, Program, kSPIR_AsanDeviceGlobalMetadata, &MetadataSize,
&MetadataPtr);
if (Result != UR_RESULT_SUCCESS) {
getContext()->logger.info("No device globals");
continue;
}

const uint64_t NumOfDeviceGlobal =
MetadataSize / sizeof(DeviceGlobalInfo);
assert((MetadataSize % sizeof(DeviceGlobalInfo) == 0) &&
"DeviceGlobal metadata size is not correct");
std::vector<DeviceGlobalInfo> GVInfos(NumOfDeviceGlobal);
Result = getContext()->urDdiTable.Enqueue.pfnDeviceGlobalVariableRead(
Queue, Program, kSPIR_AsanDeviceGlobalMetadata, true,
sizeof(DeviceGlobalInfo) * NumOfDeviceGlobal, 0, &GVInfos[0], 0,
nullptr, nullptr);
Result = getContext()->urDdiTable.Enqueue.pfnUSMMemcpy(
Queue, true, &GVInfos[0], MetadataPtr,
sizeof(DeviceGlobalInfo) * NumOfDeviceGlobal, 0, nullptr, nullptr);
if (Result != UR_RESULT_SUCCESS) {
getContext()->logger.error("Device Global[{}] Read Failed: {}",
kSPIR_AsanDeviceGlobalMetadata, Result);
Expand Down
1 change: 0 additions & 1 deletion source/loader/layers/sanitizer/asan_libdevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const int kPrivateLeftRedzoneMagic = (char)0xf1;
const int kPrivateMidRedzoneMagic = (char)0xf2;
const int kPrivateRightRedzoneMagic = (char)0xf3;

constexpr auto kSPIR_AsanDeviceGlobalCount = "__AsanDeviceGlobalCount";
constexpr auto kSPIR_AsanDeviceGlobalMetadata = "__AsanDeviceGlobalMetadata";

inline const char *ToString(DeviceSanitizerMemoryType MemoryType) {
Expand Down

0 comments on commit 0ea47d7

Please sign in to comment.