@@ -101,7 +101,7 @@ ur_result_t DeviceInfo::allocShadowMemory() {
101
101
return UR_RESULT_SUCCESS;
102
102
}
103
103
104
- void ContextInfo ::insertAllocInfo (TsanAllocInfo AI) {
104
+ void DeviceInfo ::insertAllocInfo (TsanAllocInfo AI) {
105
105
std::scoped_lock<ur_shared_mutex> Guard (AllocInfosMutex);
106
106
AllocInfos.insert (std::move (AI));
107
107
}
@@ -153,7 +153,15 @@ ur_result_t TsanInterceptor::allocateMemory(ur_context_handle_t Context,
153
153
154
154
auto AI = TsanAllocInfo{reinterpret_cast <uptr>(Allocated), Size};
155
155
// For updating shadow memory
156
- CI->insertAllocInfo (std::move (AI));
156
+ if (Device) {
157
+ auto DI = getDeviceInfo (Device);
158
+ DI->insertAllocInfo (std::move (AI));
159
+ } else {
160
+ for (const auto &Device : CI->DeviceList ) {
161
+ auto DI = getDeviceInfo (Device);
162
+ DI->insertAllocInfo (AI);
163
+ }
164
+ }
157
165
158
166
*ResultPtr = Allocated;
159
167
return UR_RESULT_SUCCESS;
@@ -163,11 +171,14 @@ ur_result_t TsanInterceptor::releaseMemory(ur_context_handle_t Context,
163
171
void *Ptr) {
164
172
auto CI = getContextInfo (Context);
165
173
auto Addr = reinterpret_cast <uptr>(Ptr);
166
- {
167
- std::scoped_lock<ur_shared_mutex> Guard (CI->AllocInfosMutex );
168
- auto It = std::find_if (CI->AllocInfos .begin (), CI->AllocInfos .end (),
174
+
175
+ for (const auto &Device : CI->DeviceList ) {
176
+ auto DI = getDeviceInfo (Device);
177
+ std::scoped_lock<ur_shared_mutex> Guard (DI->AllocInfosMutex );
178
+ auto It = std::find_if (DI->AllocInfos .begin (), DI->AllocInfos .end (),
169
179
[&](auto &P) { return P.AllocBegin == Addr; });
170
- CI->AllocInfos .erase (It);
180
+ if (It != DI->AllocInfos .end ())
181
+ DI->AllocInfos .erase (It);
171
182
}
172
183
173
184
UR_CALL (getContext ()->urDdiTable .USM .pfnFree (Context, Ptr));
@@ -343,7 +354,7 @@ ur_result_t TsanInterceptor::preLaunchKernel(ur_kernel_handle_t Kernel,
343
354
344
355
UR_CALL (prepareLaunch (CI, DI, InternalQueue, Kernel, LaunchInfo));
345
356
346
- UR_CALL (updateShadowMemory (CI, DI, Kernel, InternalQueue));
357
+ UR_CALL (updateShadowMemory (DI, Kernel, InternalQueue));
347
358
348
359
UR_CALL (getContext ()->urDdiTable .Queue .pfnFinish (InternalQueue));
349
360
@@ -470,12 +481,12 @@ ur_result_t TsanInterceptor::prepareLaunch(std::shared_ptr<ContextInfo> &,
470
481
return UR_RESULT_SUCCESS;
471
482
}
472
483
473
- ur_result_t TsanInterceptor::updateShadowMemory (
474
- std::shared_ptr<ContextInfo> &CI, std::shared_ptr<DeviceInfo> &DI ,
475
- ur_kernel_handle_t Kernel, ur_queue_handle_t Queue) {
484
+ ur_result_t TsanInterceptor::updateShadowMemory (std::shared_ptr<DeviceInfo> &DI,
485
+ ur_kernel_handle_t Kernel ,
486
+ ur_queue_handle_t Queue) {
476
487
auto &PI = getProgramInfo (GetProgram (Kernel));
477
- std::scoped_lock<ur_shared_mutex> Guard (CI ->AllocInfosMutex );
478
- for (auto &AllocInfo : CI ->AllocInfos ) {
488
+ std::scoped_lock<ur_shared_mutex> Guard (DI ->AllocInfosMutex );
489
+ for (auto &AllocInfo : DI ->AllocInfos ) {
479
490
UR_CALL (DI->Shadow ->CleanShadow (Queue, AllocInfo.AllocBegin ,
480
491
AllocInfo.AllocSize ));
481
492
}
0 commit comments