@@ -29,25 +29,34 @@ ur_result_t setupContext(ur_context_handle_t Context, uint32_t numDevices,
2929 const ur_device_handle_t *phDevices) {
3030 std::shared_ptr<ContextInfo> CI;
3131 UR_CALL (getAsanInterceptor ()->insertContext (Context, CI));
32- for (uint32_t i = 0 ; i < numDevices; ++i) {
33- auto hDevice = phDevices[i];
34- std::shared_ptr<DeviceInfo> DI;
35- UR_CALL (getAsanInterceptor ()->insertDevice (hDevice, DI));
36- DI->Type = GetDeviceType (Context, hDevice);
37- if (DI->Type == DeviceType::UNKNOWN) {
38- getContext ()->logger .error (" Unsupport device" );
39- return UR_RESULT_ERROR_INVALID_DEVICE;
40- }
41- getContext ()->logger .info (
42- " DeviceInfo {} (Type={}, IsSupportSharedSystemUSM={})" ,
43- (void *)DI->Handle , ToString (DI->Type ), DI->IsSupportSharedSystemUSM );
44- getContext ()->logger .info (" Add {} into context {}" , (void *)DI->Handle ,
45- (void *)Context);
46- if (!DI->Shadow ) {
47- UR_CALL (DI->allocShadowMemory (Context));
32+
33+ if (numDevices > 0 ) {
34+ auto DeviceType = GetDeviceType (Context, phDevices[0 ]);
35+ auto ShadowMemory =
36+ getAsanInterceptor ()->getOrCreateShadowMemory (phDevices[0 ], DeviceType);
37+
38+ for (uint32_t i = 0 ; i < numDevices; ++i) {
39+ auto hDevice = phDevices[i];
40+ std::shared_ptr<DeviceInfo> DI;
41+ UR_CALL (getAsanInterceptor ()->insertDevice (hDevice, DI));
42+ DI->Type = GetDeviceType (Context, hDevice);
43+ if (DI->Type == DeviceType::UNKNOWN) {
44+ getContext ()->logger .error (" Unsupport device" );
45+ return UR_RESULT_ERROR_INVALID_DEVICE;
46+ }
47+ if (DI->Type != DeviceType) {
48+ getContext ()->logger .error (" Different device type in the same context" );
49+ return UR_RESULT_ERROR_INVALID_DEVICE;
50+ }
51+ getContext ()->logger .info (
52+ " DeviceInfo {} (Type={}, IsSupportSharedSystemUSM={})" ,
53+ (void *)DI->Handle , ToString (DI->Type ), DI->IsSupportSharedSystemUSM );
54+ getContext ()->logger .info (" Add {} into context {}" , (void *)DI->Handle ,
55+ (void *)Context);
56+ DI->Shadow = ShadowMemory;
57+ CI->DeviceList .emplace_back (hDevice);
58+ CI->AllocInfosMap [hDevice];
4859 }
49- CI->DeviceList .emplace_back (hDevice);
50- CI->AllocInfosMap [hDevice];
5160 }
5261 return UR_RESULT_SUCCESS;
5362}
0 commit comments