@@ -53,19 +53,6 @@ struct DeviceTy {
53
53
54
54
bool HasMappedGlobalData = false ;
55
55
56
- // / Host data to device map type with a wrapper key indirection that allows
57
- // / concurrent modification of the entries without invalidating the underlying
58
- // / entries.
59
- using HostDataToTargetListTy =
60
- std::set<HostDataToTargetMapKeyTy, std::less<>>;
61
-
62
- // / The HDTTMap is a protected object that can only be accessed by one thread
63
- // / at a time.
64
- ProtectedObj<HostDataToTargetListTy> HostDataToTargetMap;
65
-
66
- // / The type used to access the HDTT map.
67
- using HDTTMapAccessorTy = decltype (HostDataToTargetMap)::AccessorTy;
68
-
69
56
PendingCtorsDtorsPerLibrary PendingCtorsDtors;
70
57
71
58
std::mutex PendingGlobalsMtx;
@@ -80,71 +67,8 @@ struct DeviceTy {
80
67
// / Try to initialize the device and return any failure.
81
68
llvm::Error init ();
82
69
83
- // Return true if data can be copied to DstDevice directly
84
- bool isDataExchangable (const DeviceTy &DstDevice);
85
-
86
- // / Lookup the mapping of \p HstPtrBegin in \p HDTTMap. The accessor ensures
87
- // / exclusive access to the HDTT map.
88
- LookupResult lookupMapping (HDTTMapAccessorTy &HDTTMap, void *HstPtrBegin,
89
- int64_t Size,
90
- HostDataToTargetTy *OwnedTPR = nullptr );
91
-
92
- // / Get the target pointer based on host pointer begin and base. If the
93
- // / mapping already exists, the target pointer will be returned directly. In
94
- // / addition, if required, the memory region pointed by \p HstPtrBegin of size
95
- // / \p Size will also be transferred to the device. If the mapping doesn't
96
- // / exist, and if unified shared memory is not enabled, a new mapping will be
97
- // / created and the data will also be transferred accordingly. nullptr will be
98
- // / returned because of any of following reasons:
99
- // / - Data allocation failed;
100
- // / - The user tried to do an illegal mapping;
101
- // / - Data transfer issue fails.
102
- TargetPointerResultTy getTargetPointer (
103
- HDTTMapAccessorTy &HDTTMap, void *HstPtrBegin, void *HstPtrBase,
104
- int64_t TgtPadding, int64_t Size, map_var_info_t HstPtrName,
105
- bool HasFlagTo, bool HasFlagAlways, bool IsImplicit, bool UpdateRefCount,
106
- bool HasCloseModifier, bool HasPresentModifier, bool HasHoldModifier,
107
- AsyncInfoTy &AsyncInfo, HostDataToTargetTy *OwnedTPR = nullptr ,
108
- bool ReleaseHDTTMap = true );
109
-
110
- // / Return the target pointer for \p HstPtrBegin in \p HDTTMap. The accessor
111
- // / ensures exclusive access to the HDTT map.
112
- void *getTgtPtrBegin (HDTTMapAccessorTy &HDTTMap, void *HstPtrBegin,
113
- int64_t Size);
114
-
115
- // / Return the target pointer begin (where the data will be moved).
116
- // / Used by targetDataBegin, targetDataEnd, targetDataUpdate and target.
117
- // / - \p UpdateRefCount and \p UseHoldRefCount controls which and if the entry
118
- // / reference counters will be decremented.
119
- // / - \p MustContain enforces that the query must not extend beyond an already
120
- // / mapped entry to be valid.
121
- // / - \p ForceDelete deletes the entry regardless of its reference counting
122
- // / (unless it is infinite).
123
- // / - \p FromDataEnd tracks the number of threads referencing the entry at
124
- // / targetDataEnd for delayed deletion purpose.
125
- [[nodiscard]] TargetPointerResultTy
126
- getTgtPtrBegin (void *HstPtrBegin, int64_t Size, bool UpdateRefCount,
127
- bool UseHoldRefCount, bool MustContain = false ,
128
- bool ForceDelete = false , bool FromDataEnd = false );
129
-
130
- // / Remove the \p Entry from the data map. Expect the entry's total reference
131
- // / count to be zero and the caller thread to be the last one using it. \p
132
- // / HDTTMap ensure the caller holds exclusive access and can modify the map.
133
- // / Return \c OFFLOAD_SUCCESS if the map entry existed, and return \c
134
- // / OFFLOAD_FAIL if not. It is the caller's responsibility to skip calling
135
- // / this function if the map entry is not expected to exist because \p
136
- // / HstPtrBegin uses shared memory.
137
- [[nodiscard]] int eraseMapEntry (HDTTMapAccessorTy &HDTTMap,
138
- HostDataToTargetTy *Entry, int64_t Size);
139
-
140
- // / Deallocate the \p Entry from the device memory and delete it. Return \c
141
- // / OFFLOAD_SUCCESS if the deallocation operations executed successfully, and
142
- // / return \c OFFLOAD_FAIL otherwise.
143
- [[nodiscard]] int deallocTgtPtrAndEntry (HostDataToTargetTy *Entry,
144
- int64_t Size);
145
-
146
- int associatePtr (void *HstPtrBegin, void *TgtPtrBegin, int64_t Size);
147
- int disassociatePtr (void *HstPtrBegin);
70
+ // / Provide access to the mapping handler.
71
+ MappingInfoTy &getMappingInfo () { return MappingInfo; }
148
72
149
73
__tgt_target_table *loadBinary (__tgt_device_image *Img);
150
74
@@ -159,6 +83,7 @@ struct DeviceTy {
159
83
// / be used (host, shared, device).
160
84
void *allocData (int64_t Size, void *HstPtr = nullptr ,
161
85
int32_t Kind = TARGET_ALLOC_DEFAULT);
86
+
162
87
// / Deallocates memory which \p TgtPtrBegin points at and returns
163
88
// / OFFLOAD_SUCCESS/OFFLOAD_FAIL when succeeds/fails. p Kind dictates what
164
89
// / allocator should be used (host, shared, device).
@@ -170,12 +95,16 @@ struct DeviceTy {
170
95
int32_t submitData (void *TgtPtrBegin, void *HstPtrBegin, int64_t Size,
171
96
AsyncInfoTy &AsyncInfo,
172
97
HostDataToTargetTy *Entry = nullptr ,
173
- DeviceTy::HDTTMapAccessorTy *HDTTMapPtr = nullptr );
98
+ MappingInfoTy::HDTTMapAccessorTy *HDTTMapPtr = nullptr );
99
+
174
100
// Copy data from device back to host
175
101
int32_t retrieveData (void *HstPtrBegin, void *TgtPtrBegin, int64_t Size,
176
102
AsyncInfoTy &AsyncInfo,
177
103
HostDataToTargetTy *Entry = nullptr ,
178
- DeviceTy::HDTTMapAccessorTy *HDTTMapPtr = nullptr );
104
+ MappingInfoTy::HDTTMapAccessorTy *HDTTMapPtr = nullptr );
105
+
106
+ // Return true if data can be copied to DstDevice directly
107
+ bool isDataExchangable (const DeviceTy &DstDevice);
179
108
180
109
// Copy data from current device to destination device directly
181
110
int32_t dataExchange (void *SrcPtr, DeviceTy &DstDev, void *DstPtr,
@@ -240,7 +169,12 @@ struct DeviceTy {
240
169
void deinit ();
241
170
242
171
// / All offload entries available on this device.
243
- llvm::DenseMap<llvm::StringRef, OffloadEntryTy *> DeviceOffloadEntries;
172
+ using DeviceOffloadEntriesMapTy =
173
+ llvm::DenseMap<llvm::StringRef, OffloadEntryTy *>;
174
+ ProtectedObj<DeviceOffloadEntriesMapTy> DeviceOffloadEntries;
175
+
176
+ // / Handler to collect and organize host-2-device mapping information.
177
+ MappingInfoTy MappingInfo;
244
178
};
245
179
246
180
#endif
0 commit comments