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