Skip to content

Commit e3eeb4e

Browse files
authored
Merge pull request #2224 from zhaomaosu/refactor-launch-info
[DeviceASAN] Move GlobalShadowOffset, DeviceType, Debug into LaunchInfo
2 parents c742ca4 + 55d5d01 commit e3eeb4e

File tree

3 files changed

+15
-46
lines changed

3 files changed

+15
-46
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -414,42 +414,6 @@ ur_result_t SanitizerInterceptor::registerProgram(ur_context_handle_t Context,
414414

415415
for (auto Device : Devices) {
416416
ManagedQueue Queue(Context, Device);
417-
auto DeviceInfo = getDeviceInfo(Device);
418-
419-
// Write global variable to program
420-
auto EnqueueWriteGlobal = [&Queue, &Program](
421-
const char *Name, const void *Value,
422-
size_t Size, bool ReportWarning = true) {
423-
auto Result =
424-
getContext()->urDdiTable.Enqueue.pfnDeviceGlobalVariableWrite(
425-
Queue, Program, Name, false, Size, 0, Value, 0, nullptr,
426-
nullptr);
427-
if (ReportWarning && Result != UR_RESULT_SUCCESS) {
428-
getContext()->logger.warning(
429-
"Failed to write device global \"{}\": {}", Name, Result);
430-
return false;
431-
}
432-
return true;
433-
};
434-
435-
// Write debug
436-
// We use "uint64_t" here because EnqueueWriteGlobal will fail when it's "uint32_t"
437-
// Because EnqueueWriteGlobal is a async write, so
438-
// we need to extend its lifetime
439-
static uint64_t Debug = getOptions().Debug ? 1 : 0;
440-
EnqueueWriteGlobal(kSPIR_AsanDebug, &Debug, sizeof(Debug), false);
441-
442-
// Write shadow memory offset for global memory
443-
EnqueueWriteGlobal(kSPIR_AsanShadowMemoryGlobalStart,
444-
&DeviceInfo->Shadow->ShadowBegin,
445-
sizeof(DeviceInfo->Shadow->ShadowBegin));
446-
EnqueueWriteGlobal(kSPIR_AsanShadowMemoryGlobalEnd,
447-
&DeviceInfo->Shadow->ShadowEnd,
448-
sizeof(DeviceInfo->Shadow->ShadowEnd));
449-
450-
// Write device type
451-
EnqueueWriteGlobal(kSPIR_DeviceType, &DeviceInfo->Type,
452-
sizeof(DeviceInfo->Type));
453417

454418
uint64_t NumOfDeviceGlobal;
455419
auto Result =
@@ -687,6 +651,11 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
687651
}
688652
}
689653

654+
LaunchInfo.Data->GlobalShadowOffset = DeviceInfo->Shadow->ShadowBegin;
655+
LaunchInfo.Data->GlobalShadowOffsetEnd = DeviceInfo->Shadow->ShadowEnd;
656+
LaunchInfo.Data->DeviceTy = DeviceInfo->Type;
657+
LaunchInfo.Data->Debug = getOptions().Debug ? 1 : 0;
658+
690659
if (LaunchInfo.LocalWorkSize.empty()) {
691660
LaunchInfo.LocalWorkSize.resize(LaunchInfo.WorkDim);
692661
auto URes =

source/loader/layers/sanitizer/asan_libdevice.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
namespace ur_sanitizer_layer {
1818

19+
enum class DeviceType : uint32_t { UNKNOWN = 0, CPU, GPU_PVC, GPU_DG2 };
20+
1921
enum class DeviceSanitizerErrorType : int32_t {
2022
UNKNOWN,
2123
OUT_OF_BOUNDS,
@@ -70,14 +72,20 @@ struct LocalArgsInfo {
7072
constexpr std::size_t ASAN_MAX_NUM_REPORTS = 10;
7173

7274
struct LaunchInfo {
75+
uintptr_t GlobalShadowOffset = 0;
76+
uintptr_t GlobalShadowOffsetEnd = 0;
77+
7378
uintptr_t PrivateShadowOffset = 0;
7479
uintptr_t PrivateShadowOffsetEnd = 0;
7580

7681
uintptr_t LocalShadowOffset = 0;
7782
uintptr_t LocalShadowOffsetEnd = 0;
7883

79-
uint32_t NumLocalArgs = 0;
8084
LocalArgsInfo *LocalArgs = nullptr; // Ordered by ArgIndex
85+
uint32_t NumLocalArgs = 0;
86+
87+
DeviceType DeviceTy = DeviceType::UNKNOWN;
88+
uint32_t Debug = 0;
8189

8290
DeviceSanitizerReport SanitizerReport[ASAN_MAX_NUM_REPORTS];
8391
};
@@ -110,13 +118,6 @@ const int kPrivateLeftRedzoneMagic = (char)0xf1;
110118
const int kPrivateMidRedzoneMagic = (char)0xf2;
111119
const int kPrivateRightRedzoneMagic = (char)0xf3;
112120

113-
constexpr auto kSPIR_AsanShadowMemoryGlobalStart =
114-
"__AsanShadowMemoryGlobalStart";
115-
constexpr auto kSPIR_AsanShadowMemoryGlobalEnd = "__AsanShadowMemoryGlobalEnd";
116-
117-
constexpr auto kSPIR_DeviceType = "__DeviceType";
118-
constexpr auto kSPIR_AsanDebug = "__AsanDebug";
119-
120121
constexpr auto kSPIR_AsanDeviceGlobalCount = "__AsanDeviceGlobalCount";
121122
constexpr auto kSPIR_AsanDeviceGlobalMetadata = "__AsanDeviceGlobalMetadata";
122123

source/loader/layers/sanitizer/common.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#pragma once
1414

15+
#include "asan_libdevice.hpp"
1516
#include "ur/ur.hpp"
1617
#include "ur_ddi.h"
1718

@@ -137,8 +138,6 @@ struct SourceInfo {
137138
int column = 0;
138139
};
139140

140-
enum class DeviceType : uint64_t { UNKNOWN = 0, CPU, GPU_PVC, GPU_DG2 };
141-
142141
inline const char *ToString(DeviceType Type) {
143142
switch (Type) {
144143
case DeviceType::UNKNOWN:

0 commit comments

Comments
 (0)