21 : MEvent(Event), MPlugin(Plugin) {
28 if (MEvent.has_value())
36 assert(MPtr ==
nullptr &&
"MPtr has not been cleaned up.");
37 assert(!MZeroInitEvent.has_value() &&
38 "MZeroInitEvent has not been cleaned up.");
42 std::lock_guard<std::mutex> Lock(MZeroInitEventMutex);
44 if (MZeroInitEvent.has_value()) {
45 if (get_event_info<info::event::command_execution_status>(
58 const std::shared_ptr<queue_impl> &QueueImpl) {
60 "USM allocations should not be acquired for device_global with "
61 "device_image_scope property.");
62 const std::shared_ptr<context_impl> &CtxImpl = QueueImpl->getContextImplPtr();
63 const std::shared_ptr<device_impl> &DevImpl = QueueImpl->getDeviceImplPtr();
64 std::lock_guard<std::mutex> Lock(MDeviceToUSMPtrMapMutex);
66 auto DGUSMPtr = MDeviceToUSMPtrMap.find({DevImpl.get(), CtxImpl.get()});
67 if (DGUSMPtr != MDeviceToUSMPtrMap.end())
68 return DGUSMPtr->second;
72 sycl::usm::alloc::device);
74 auto NewAllocIt = MDeviceToUSMPtrMap.emplace(
75 std::piecewise_construct,
76 std::forward_as_tuple(DevImpl.get(), CtxImpl.get()),
77 std::forward_as_tuple(NewDGUSMPtr));
78 assert(NewAllocIt.second &&
79 "USM allocation for device and context already happened.");
84 std::lock_guard<std::mutex> Lock(NewAlloc.MZeroInitEventMutex);
87 std::vector<RT::PiEvent>{}, &InitEvent);
88 NewAlloc.MZeroInitEvent = InitEvent;
97 std::lock_guard<std::mutex> Lock{MDeviceToUSMPtrMapMutex};
101 if (USMPtrIt != MDeviceToUSMPtrMap.end()) {
104 if (USMMem.MZeroInitEvent.has_value())
106 *USMMem.MZeroInitEvent);
110 USMMem.MPtr =
nullptr;
111 USMMem.MZeroInitEvent = {};
113 MDeviceToUSMPtrMap.erase(USMPtrIt);