@@ -191,38 +191,50 @@ static int initLibrary(DeviceTy &Device) {
191
191
*EntryDeviceEnd = TargetTable->EntriesEnd ;
192
192
CurrDeviceEntry != EntryDeviceEnd;
193
193
CurrDeviceEntry++, CurrHostEntry++) {
194
- if (CurrDeviceEntry->size != 0 ) {
195
- // has data.
196
- assert (CurrDeviceEntry->size == CurrHostEntry->size &&
197
- " data size mismatch" );
198
-
199
- // Fortran may use multiple weak declarations for the same symbol,
200
- // therefore we must allow for multiple weak symbols to be loaded from
201
- // the fat binary. Treat these mappings as any other "regular"
202
- // mapping. Add entry to map.
203
- if (Device.getTgtPtrBegin (HDTTMap, CurrHostEntry->addr ,
204
- CurrHostEntry->size ))
205
- continue ;
206
-
207
- DP (" Add mapping from host " DPxMOD " to device " DPxMOD
208
- " with size %zu"
209
- " \n " ,
210
- DPxPTR (CurrHostEntry->addr ), DPxPTR (CurrDeviceEntry->addr ),
211
- CurrDeviceEntry->size );
212
- HDTTMap->emplace (new HostDataToTargetTy (
213
- (uintptr_t )CurrHostEntry->addr /* HstPtrBase*/ ,
214
- (uintptr_t )CurrHostEntry->addr /* HstPtrBegin*/ ,
215
- (uintptr_t )CurrHostEntry->addr +
216
- CurrHostEntry->size /* HstPtrEnd*/ ,
217
- (uintptr_t )CurrDeviceEntry->addr /* TgtAllocBegin*/ ,
218
- (uintptr_t )CurrDeviceEntry->addr /* TgtPtrBegin*/ ,
219
- false /* UseHoldRefCount*/ , CurrHostEntry->name ,
220
- true /* IsRefCountINF*/ ));
221
-
222
- // Notify about the new mapping.
223
- if (Device.notifyDataMapped (CurrHostEntry->addr , CurrHostEntry->size ))
194
+ if (CurrDeviceEntry->size == 0 )
195
+ continue ;
196
+
197
+ assert (CurrDeviceEntry->size == CurrHostEntry->size &&
198
+ " data size mismatch" );
199
+
200
+ // Fortran may use multiple weak declarations for the same symbol,
201
+ // therefore we must allow for multiple weak symbols to be loaded from
202
+ // the fat binary. Treat these mappings as any other "regular"
203
+ // mapping. Add entry to map.
204
+ if (Device.getTgtPtrBegin (HDTTMap, CurrHostEntry->addr ,
205
+ CurrHostEntry->size ))
206
+ continue ;
207
+
208
+ void *CurrDeviceEntryAddr = CurrDeviceEntry->addr ;
209
+
210
+ // For indirect mapping, follow the indirection and map the actual
211
+ // target.
212
+ if (CurrDeviceEntry->flags & OMP_DECLARE_TARGET_INDIRECT) {
213
+ AsyncInfoTy AsyncInfo (Device);
214
+ void *DevPtr;
215
+ Device.retrieveData (&DevPtr, CurrDeviceEntryAddr, sizeof (void *),
216
+ AsyncInfo);
217
+ if (AsyncInfo.synchronize () != OFFLOAD_SUCCESS)
224
218
return OFFLOAD_FAIL;
219
+ CurrDeviceEntryAddr = DevPtr;
225
220
}
221
+
222
+ DP (" Add mapping from host " DPxMOD " to device " DPxMOD " with size %zu"
223
+ " , name \" %s\"\n " ,
224
+ DPxPTR (CurrHostEntry->addr ), DPxPTR (CurrDeviceEntry->addr ),
225
+ CurrDeviceEntry->size , CurrDeviceEntry->name );
226
+ HDTTMap->emplace (new HostDataToTargetTy (
227
+ (uintptr_t )CurrHostEntry->addr /* HstPtrBase*/ ,
228
+ (uintptr_t )CurrHostEntry->addr /* HstPtrBegin*/ ,
229
+ (uintptr_t )CurrHostEntry->addr + CurrHostEntry->size /* HstPtrEnd*/ ,
230
+ (uintptr_t )CurrDeviceEntryAddr /* TgtAllocBegin*/ ,
231
+ (uintptr_t )CurrDeviceEntryAddr /* TgtPtrBegin*/ ,
232
+ false /* UseHoldRefCount*/ , CurrHostEntry->name ,
233
+ true /* IsRefCountINF*/ ));
234
+
235
+ // Notify about the new mapping.
236
+ if (Device.notifyDataMapped (CurrHostEntry->addr , CurrHostEntry->size ))
237
+ return OFFLOAD_FAIL;
226
238
}
227
239
}
228
240
}
0 commit comments