Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/src/device.h
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | private: | ||||
static const uint64_t INFRefCount = ~(uint64_t)0; | static const uint64_t INFRefCount = ~(uint64_t)0; | ||||
static std::string refCountToStr(uint64_t RefCount) { | static std::string refCountToStr(uint64_t RefCount) { | ||||
return RefCount == INFRefCount ? "INF" : std::to_string(RefCount); | return RefCount == INFRefCount ? "INF" : std::to_string(RefCount); | ||||
} | } | ||||
struct StatesTy { | struct StatesTy { | ||||
StatesTy(uint64_t DRC, uint64_t HRC) | StatesTy(uint64_t DRC, uint64_t HRC) | ||||
: DynRefCount(DRC), HoldRefCount(HRC) {} | : DynRefCount(DRC), HoldRefCount(HRC) {} | ||||
/// this copy constructor is added to make HostDataToTargetTy copiable | |||||
/// when it is used by std::set copy constructor | |||||
StatesTy(const StatesTy &S) | |||||
: DynRefCount(S.DynRefCount), HoldRefCount(S.HoldRefCount) {} | |||||
/// The dynamic reference count is the standard reference count as of OpenMP | /// The dynamic reference count is the standard reference count as of OpenMP | ||||
/// 4.5. The hold reference count is an OpenMP extension for the sake of | /// 4.5. The hold reference count is an OpenMP extension for the sake of | ||||
/// OpenACC support. | /// OpenACC support. | ||||
/// | /// | ||||
/// The 'ompx_hold' map type modifier is permitted only on "omp target" and | /// The 'ompx_hold' map type modifier is permitted only on "omp target" and | ||||
/// "omp target data", and "delete" is permitted only on "omp target exit | /// "omp target data", and "delete" is permitted only on "omp target exit | ||||
/// data" and associated runtime library routines. As a result, we really | /// data" and associated runtime library routines. As a result, we really | ||||
/// need to implement "reset" functionality only for the dynamic reference | /// need to implement "reset" functionality only for the dynamic reference | ||||
Show All 25 Lines | HostDataToTargetTy(uintptr_t BP, uintptr_t B, uintptr_t E, uintptr_t TB, | ||||
: HstPtrBase(BP), HstPtrBegin(B), HstPtrEnd(E), HstPtrName(Name), | : HstPtrBase(BP), HstPtrBegin(B), HstPtrEnd(E), HstPtrName(Name), | ||||
TgtPtrBegin(TB), States(std::make_unique<StatesTy>(UseHoldRefCount ? 0 | TgtPtrBegin(TB), States(std::make_unique<StatesTy>(UseHoldRefCount ? 0 | ||||
: IsINF ? INFRefCount | : IsINF ? INFRefCount | ||||
: 1, | : 1, | ||||
!UseHoldRefCount ? 0 | !UseHoldRefCount ? 0 | ||||
: IsINF ? INFRefCount | : IsINF ? INFRefCount | ||||
: 1)) {} | : 1)) {} | ||||
HostDataToTargetTy(const HostDataToTargetTy &Entry) | |||||
: HstPtrBase(Entry.HstPtrBase), HstPtrBegin(Entry.HstPtrBegin), | |||||
HstPtrEnd(Entry.HstPtrEnd), HstPtrName(Entry.HstPtrName), | |||||
TgtPtrBegin(Entry.TgtPtrBegin), | |||||
States(std::make_unique<StatesTy>(*Entry.States)) {} | |||||
/// Get the total reference count. This is smarter than just getDynRefCount() | /// Get the total reference count. This is smarter than just getDynRefCount() | ||||
/// + getHoldRefCount() because it handles the case where at least one is | /// + getHoldRefCount() because it handles the case where at least one is | ||||
/// infinity and the other is non-zero. | /// infinity and the other is non-zero. | ||||
uint64_t getTotalRefCount() const { | uint64_t getTotalRefCount() const { | ||||
if (States->DynRefCount == INFRefCount || | if (States->DynRefCount == INFRefCount || | ||||
States->HoldRefCount == INFRefCount) | States->HoldRefCount == INFRefCount) | ||||
return INFRefCount; | return INFRefCount; | ||||
return States->DynRefCount + States->HoldRefCount; | return States->DynRefCount + States->HoldRefCount; | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | struct DeviceTy { | ||||
std::mutex DataMapMtx, PendingGlobalsMtx, ShadowMtx; | std::mutex DataMapMtx, PendingGlobalsMtx, ShadowMtx; | ||||
// NOTE: Once libomp gains full target-task support, this state should be | // NOTE: Once libomp gains full target-task support, this state should be | ||||
// moved into the target task in libomp. | // moved into the target task in libomp. | ||||
std::map<int32_t, uint64_t> LoopTripCnt; | std::map<int32_t, uint64_t> LoopTripCnt; | ||||
DeviceTy(RTLInfoTy *RTL); | DeviceTy(RTLInfoTy *RTL); | ||||
// The existence of mutexes makes DeviceTy non-copyable. We need to | |||||
// provide a copy constructor and an assignment operator explicitly. | |||||
DeviceTy(const DeviceTy &D); | |||||
tianshilei1992: Mark them as `delete` if you expect it should not be copied at all. | |||||
ye-luoAuthorUnsubmitted Added. It makes the non-copyable nature explicitly expressed. ye-luo: Added. It makes the non-copyable nature explicitly expressed. | |||||
DeviceTy &operator=(const DeviceTy &D); | |||||
~DeviceTy(); | ~DeviceTy(); | ||||
// Return true if data can be copied to DstDevice directly | // Return true if data can be copied to DstDevice directly | ||||
bool isDataExchangable(const DeviceTy &DstDevice); | bool isDataExchangable(const DeviceTy &DstDevice); | ||||
LookupResult lookupMapping(void *HstPtrBegin, int64_t Size); | LookupResult lookupMapping(void *HstPtrBegin, int64_t Size); | ||||
/// Get the target pointer based on host pointer begin and base. If the | /// Get the target pointer based on host pointer begin and base. If the | ||||
/// mapping already exists, the target pointer will be returned directly. In | /// mapping already exists, the target pointer will be returned directly. In | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | struct DeviceTy { | ||||
int32_t destroyEvent(void *Event); | int32_t destroyEvent(void *Event); | ||||
/// } | /// } | ||||
private: | private: | ||||
// Call to RTL | // Call to RTL | ||||
void init(); // To be called only via DeviceTy::initOnce() | void init(); // To be called only via DeviceTy::initOnce() | ||||
}; | }; | ||||
/// Map between Device ID (i.e. openmp device id) and its DeviceTy. | |||||
typedef std::vector<DeviceTy> DevicesTy; | |||||
extern bool device_is_ready(int device_num); | extern bool device_is_ready(int device_num); | ||||
/// Struct for the data required to handle plugins | /// Struct for the data required to handle plugins | ||||
struct PluginManager { | struct PluginManager { | ||||
/// RTLs identified on the host | /// RTLs identified on the host | ||||
RTLsTy RTLs; | RTLsTy RTLs; | ||||
/// Devices associated with RTLs | /// Devices associated with RTLs | ||||
DevicesTy Devices; | std::vector<std::unique_ptr<DeviceTy>> Devices; | ||||
std::mutex RTLsMtx; ///< For RTLs and Devices | std::mutex RTLsMtx; ///< For RTLs and Devices | ||||
/// Translation table retreived from the binary | /// Translation table retreived from the binary | ||||
HostEntriesBeginToTransTableTy HostEntriesBeginToTransTable; | HostEntriesBeginToTransTableTy HostEntriesBeginToTransTable; | ||||
std::mutex TrlTblMtx; ///< For Translation Table | std::mutex TrlTblMtx; ///< For Translation Table | ||||
/// Host offload entries in order of image registration | /// Host offload entries in order of image registration | ||||
std::vector<__tgt_offload_entry *> HostEntriesBeginRegistrationOrder; | std::vector<__tgt_offload_entry *> HostEntriesBeginRegistrationOrder; | ||||
Show All 12 Lines |
Mark them as delete if you expect it should not be copied at all.