@@ -27,6 +27,15 @@ uptr MemToShadow_CPU(uptr USM_SHADOW_BASE, uptr UPtr) {
27
27
return USM_SHADOW_BASE + (UPtr >> ASAN_SHADOW_SCALE);
28
28
}
29
29
30
+ uptr MemToShadow_DG2 (uptr USM_SHADOW_BASE, uptr UPtr) {
31
+ if (UPtr & 0xFFFF000000000000ULL ) { // Device USM
32
+ return USM_SHADOW_BASE + 0x80000000000ULL +
33
+ ((UPtr & 0x7FFFFFFFFFFFULL ) >> ASAN_SHADOW_SCALE);
34
+ } else { // Host/Shared USM
35
+ return USM_SHADOW_BASE + (UPtr >> ASAN_SHADOW_SCALE);
36
+ }
37
+ }
38
+
30
39
uptr MemToShadow_PVC (uptr USM_SHADOW_BASE, uptr UPtr) {
31
40
if (UPtr & 0xFF00000000000000ULL ) { // Device USM
32
41
return USM_SHADOW_BASE + 0x80000000000ULL +
@@ -56,6 +65,9 @@ ur_result_t enqueueMemSetShadow(ur_context_handle_t Context,
56
65
return UR_RESULT_SUCCESS;
57
66
}
58
67
if (DeviceInfo->Type == DeviceType::CPU) {
68
+ // /
69
+ // / CPU Device: CPU needs to use a special memset function
70
+ // /
59
71
uptr ShadowBegin = MemToShadow_CPU (DeviceInfo->ShadowOffset , Ptr );
60
72
uptr ShadowEnd =
61
73
MemToShadow_CPU (DeviceInfo->ShadowOffset , Ptr + Size - 1 );
@@ -72,10 +84,25 @@ ur_result_t enqueueMemSetShadow(ur_context_handle_t Context,
72
84
(void *)ShadowBegin, ShadowEnd - ShadowBegin + 1 ,
73
85
(void *)(size_t )Value);
74
86
MemSet ((void *)ShadowBegin, Value, ShadowEnd - ShadowBegin + 1 );
75
- } else if (DeviceInfo->Type == DeviceType::GPU_PVC) {
76
- uptr ShadowBegin = MemToShadow_PVC (DeviceInfo->ShadowOffset , Ptr );
77
- uptr ShadowEnd =
78
- MemToShadow_PVC (DeviceInfo->ShadowOffset , Ptr + Size - 1 );
87
+ } else {
88
+ // /
89
+ // / GPU Device: GPU needs to manually map physical memory before memset
90
+ // /
91
+ uptr ShadowBegin = 0 , ShadowEnd = 0 ;
92
+
93
+ if (DeviceInfo->Type == DeviceType::GPU_PVC) {
94
+ ShadowBegin = MemToShadow_PVC (DeviceInfo->ShadowOffset , Ptr );
95
+ ShadowEnd =
96
+ MemToShadow_PVC (DeviceInfo->ShadowOffset , Ptr + Size - 1 );
97
+ } else if (DeviceInfo->Type == DeviceType::GPU_DG2) {
98
+ ShadowBegin = MemToShadow_DG2 (DeviceInfo->ShadowOffset , Ptr );
99
+ ShadowEnd =
100
+ MemToShadow_DG2 (DeviceInfo->ShadowOffset , Ptr + Size - 1 );
101
+ } else {
102
+ getContext ()->logger .error (" Unsupport device type" );
103
+ return UR_RESULT_ERROR_INVALID_ARGUMENT;
104
+ }
105
+
79
106
assert (ShadowBegin <= ShadowEnd);
80
107
{
81
108
static const size_t PageSize =
@@ -108,7 +135,9 @@ ur_result_t enqueueMemSetShadow(ur_context_handle_t Context,
108
135
Context, (void *)MappedPtr, PageSize, PhysicalMem, 0 ,
109
136
UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE);
110
137
if (URes != UR_RESULT_SUCCESS) {
111
- getContext ()->logger .debug (" urVirtualMemMap(): {}" , URes);
138
+ getContext ()->logger .debug (" urVirtualMemMap({}, {}): {}" ,
139
+ (void *)MappedPtr, PageSize,
140
+ URes);
112
141
}
113
142
114
143
// Initialize to zero
@@ -137,9 +166,6 @@ ur_result_t enqueueMemSetShadow(ur_context_handle_t Context,
137
166
getContext ()->logger .error (" urEnqueueUSMFill(): {}" , URes);
138
167
return URes;
139
168
}
140
- } else {
141
- getContext ()->logger .error (" Unsupport device type" );
142
- return UR_RESULT_ERROR_INVALID_ARGUMENT;
143
169
}
144
170
return UR_RESULT_SUCCESS;
145
171
}
@@ -158,6 +184,7 @@ SanitizerInterceptor::SanitizerInterceptor(logger::Logger &logger)
158
184
SanitizerInterceptor::~SanitizerInterceptor () {
159
185
DestroyShadowMemoryOnCPU ();
160
186
DestroyShadowMemoryOnPVC ();
187
+ DestroyShadowMemoryOnDG2 ();
161
188
}
162
189
163
190
// / The memory chunk allocated from the underlying allocator looks like this:
@@ -390,6 +417,8 @@ ur_result_t DeviceInfo::allocShadowMemory(ur_context_handle_t Context) {
390
417
UR_CALL (SetupShadowMemoryOnCPU (ShadowOffset, ShadowOffsetEnd));
391
418
} else if (Type == DeviceType::GPU_PVC) {
392
419
UR_CALL (SetupShadowMemoryOnPVC (Context, ShadowOffset, ShadowOffsetEnd));
420
+ } else if (Type == DeviceType::GPU_DG2) {
421
+ UR_CALL (SetupShadowMemoryOnDG2 (Context, ShadowOffset, ShadowOffsetEnd));
393
422
} else {
394
423
getContext ()->logger .error (" Unsupport device type" );
395
424
return UR_RESULT_ERROR_INVALID_ARGUMENT;
@@ -586,12 +615,6 @@ SanitizerInterceptor::insertDevice(ur_device_handle_t Device,
586
615
587
616
DI = std::make_shared<ur_sanitizer_layer::DeviceInfo>(Device);
588
617
589
- // Query device type
590
- DI->Type = GetDeviceType (Device);
591
- if (DI->Type == DeviceType::UNKNOWN) {
592
- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
593
- }
594
-
595
618
// Query alignment
596
619
UR_CALL (getContext ()->urDdiTable .Device .pfnGetInfo (
597
620
Device, UR_DEVICE_INFO_MEM_BASE_ADDR_ALIGN, sizeof (DI->Alignment ),
@@ -786,7 +809,8 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
786
809
// Write shadow memory offset for local memory
787
810
if (Options (logger).DetectLocals ) {
788
811
// CPU needn't this
789
- if (DeviceInfo->Type == DeviceType::GPU_PVC) {
812
+ if (DeviceInfo->Type == DeviceType::GPU_PVC ||
813
+ DeviceInfo->Type == DeviceType::GPU_DG2) {
790
814
const size_t LocalMemorySize =
791
815
GetDeviceLocalMemorySize (DeviceInfo->Handle );
792
816
const size_t LocalShadowMemorySize =
@@ -826,7 +850,8 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
826
850
if (Options (logger).DetectPrivates ) {
827
851
if (DeviceInfo->Type == DeviceType::CPU) {
828
852
LaunchInfo.Data ->PrivateShadowOffset = DeviceInfo->ShadowOffset ;
829
- } else if (DeviceInfo->Type == DeviceType::GPU_PVC) {
853
+ } else if (DeviceInfo->Type == DeviceType::GPU_PVC ||
854
+ DeviceInfo->Type == DeviceType::GPU_DG2) {
830
855
const size_t PrivateShadowMemorySize =
831
856
(NumWG * ASAN_PRIVATE_SIZE) >> ASAN_SHADOW_SCALE;
832
857
@@ -907,8 +932,8 @@ ur_result_t USMLaunchInfo::updateKernelInfo(const KernelInfo &KI) {
907
932
USMLaunchInfo::~USMLaunchInfo () {
908
933
[[maybe_unused]] ur_result_t Result;
909
934
if (Data) {
910
- auto Type = GetDeviceType (Device);
911
- if (Type == DeviceType::GPU_PVC) {
935
+ auto Type = GetDeviceType (Context, Device);
936
+ if (Type == DeviceType::GPU_PVC || Type == DeviceType::GPU_DG2 ) {
912
937
if (Data->PrivateShadowOffset ) {
913
938
Result = getContext ()->urDdiTable .USM .pfnFree (
914
939
Context, (void *)Data->PrivateShadowOffset );
0 commit comments