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>(
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);
83 std::vector<sycl::detail::pi::PiEvent>{},
85 NewAlloc.MInitEvent = InitEvent;
94 std::lock_guard<std::mutex> Lock{MDeviceToUSMPtrMapMutex};
98 if (USMPtrIt != MDeviceToUSMPtrMap.end()) {
101 if (USMMem.MInitEvent.has_value())
107 USMMem.MPtr =
nullptr;
108 USMMem.MInitEvent = {};
110 MDeviceToUSMPtrMap.erase(USMPtrIt);