@@ -134,18 +134,23 @@ ur_result_t MsanShadowMemoryGPU::Setup() {
134
134
// shadow memory for each contexts, this will cause out-of-resource error when user uses
135
135
// multiple contexts. Therefore, we just create one shadow memory here.
136
136
static ur_result_t Result = [this ]() {
137
- size_t ShadowSize = GetShadowSize ();
137
+ const size_t ShadowSize = GetShadowSize ();
138
+ // To reserve very large amount of GPU virtual memroy, the pStart param should be beyond
139
+ // the SVM range, so that GFX driver will automatically switch to reservation on the GPU
140
+ // heap.
141
+ const void *StartAddress = (void *)(0x100'0000'0000'0000ULL );
138
142
// TODO: Protect Bad Zone
139
143
auto Result = getContext ()->urDdiTable .VirtualMem .pfnReserve (
140
- Context, nullptr , ShadowSize, (void **)&ShadowBegin);
141
- if (Result == UR_RESULT_SUCCESS) {
142
- ShadowEnd = ShadowBegin + ShadowSize;
143
- // Retain the context which reserves shadow memory
144
- getContext ()->urDdiTable .Context .pfnRetain (Context);
144
+ Context, StartAddress, ShadowSize, (void **)&ShadowBegin);
145
+ if (Result != UR_RESULT_SUCCESS) {
146
+ getContext ()->logger .error (
147
+ " Shadow memory reserved failed with size {}: {}" ,
148
+ (void *)ShadowSize, Result);
149
+ return Result;
145
150
}
146
-
147
- // Set shadow memory for null pointer
148
- ManagedQueue Queue ( Context, Device );
151
+ ShadowEnd = ShadowBegin + ShadowSize;
152
+ // Retain the context which reserves shadow memory
153
+ getContext ()-> urDdiTable . Context . pfnRetain (Context );
149
154
return UR_RESULT_SUCCESS;
150
155
}();
151
156
return Result;
@@ -278,13 +283,21 @@ MsanShadowMemoryGPU::ReleaseShadow(std::shared_ptr<MsanAllocInfo> AI) {
278
283
}
279
284
280
285
uptr MsanShadowMemoryPVC::MemToShadow (uptr Ptr ) {
281
- assert (Ptr & 0xFF00000000000000ULL && " Ptr must be device USM" );
282
- return ShadowBegin + (Ptr & 0x3FFF'FFFF'FFFFULL );
286
+ assert (Ptr & 0xff00'0000'0000'0000ULL && " Ptr must be device USM" );
287
+ if (Ptr < ShadowBegin) {
288
+ return Ptr + (ShadowBegin - 0xff00'0000'0000'0000ULL );
289
+ } else {
290
+ return Ptr - (0xff00'ffff'ffff'ffffULL - ShadowEnd);
291
+ }
283
292
}
284
293
285
294
uptr MsanShadowMemoryDG2::MemToShadow (uptr Ptr ) {
286
- assert (Ptr & 0xFFFF000000000000ULL && " Ptr must be device USM" );
287
- return ShadowBegin + (Ptr & 0x3FFF'FFFF'FFFFULL );
295
+ assert (Ptr & 0xffff'0000'0000'0000ULL && " Ptr must be device USM" );
296
+ if (Ptr < ShadowBegin) {
297
+ return Ptr + (ShadowBegin - 0xffff'8000'0000'0000ULL );
298
+ } else {
299
+ return Ptr - (0xffff'ffff'ffff'ffffULL - ShadowEnd);
300
+ }
288
301
}
289
302
290
303
} // namespace msan
0 commit comments