17 inline namespace _V1 {
24 assert(MPtr ==
nullptr &&
"MPtr has not been cleaned up.");
25 assert(!MInitEvent.has_value() &&
"MInitEvent has not been cleaned up.");
29 std::lock_guard<std::mutex> Lock(MInitEventMutex);
31 if (MInitEvent.has_value()) {
32 if (get_event_info<info::event::command_execution_status>(
34 Plugin->call<UrApiKind::urEventRelease>(*MInitEvent);
45 const std::shared_ptr<queue_impl> &QueueImpl) {
47 "USM allocations should not be acquired for device_global with "
48 "device_image_scope property.");
49 const std::shared_ptr<context_impl> &CtxImpl = QueueImpl->getContextImplPtr();
50 const std::shared_ptr<device_impl> &DevImpl = QueueImpl->getDeviceImplPtr();
51 std::lock_guard<std::mutex> Lock(MDeviceToUSMPtrMapMutex);
53 auto DGUSMPtr = MDeviceToUSMPtrMap.find({DevImpl.get(), CtxImpl.get()});
54 if (DGUSMPtr != MDeviceToUSMPtrMap.end())
55 return DGUSMPtr->second;
59 sycl::usm::alloc::device);
61 auto NewAllocIt = MDeviceToUSMPtrMap.emplace(
62 std::piecewise_construct,
63 std::forward_as_tuple(DevImpl.get(), CtxImpl.get()),
64 std::forward_as_tuple(NewDGUSMPtr));
65 assert(NewAllocIt.second &&
66 "USM allocation for device and context already happened.");
71 std::lock_guard<std::mutex> Lock(NewAlloc.MInitEventMutex);
72 ur_event_handle_t InitEvent;
84 std::vector<ur_event_handle_t>{}, &InitEvent,
86 NewAlloc.MInitEvent = InitEvent;
95 std::lock_guard<std::mutex> Lock{MDeviceToUSMPtrMapMutex};
99 if (USMPtrIt != MDeviceToUSMPtrMap.end()) {
102 if (USMMem.MInitEvent.has_value())
103 CtxImpl->
getPlugin()->call<UrApiKind::urEventRelease>(
108 USMMem.MPtr =
nullptr;
109 USMMem.MInitEvent = {};
111 MDeviceToUSMPtrMap.erase(USMPtrIt);
static void copy_usm(const void *SrcMem, QueueImplPtr Queue, size_t Len, void *DstMem, std::vector< ur_event_handle_t > DepEvents, ur_event_handle_t *OutEvent, const detail::EventImplPtr &OutEventImpl)
const std::vector< device > & getDevices() const
Unlike ‘get_info<info::context::devices>’, this function returns a reference.
const PluginPtr & getPlugin() const
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
void freeInternal(void *Ptr, const context_impl *CtxImpl)
void * alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList)
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
std::shared_ptr< plugin > PluginPtr
bool MIsDeviceImageScopeDecorated
DeviceGlobalUSMMem & getOrAllocateDeviceGlobalUSM(const std::shared_ptr< queue_impl > &QueueImpl)
const void * MDeviceGlobalPtr
std::uint32_t MDeviceGlobalTSize
void removeAssociatedResources(const context_impl *CtxImpl)
OwnedUrEvent getInitEvent(const PluginPtr &Plugin)