61 context{createSyclObjFromImpl<device>(Device), {}, {}});
64 Device->get_platform().ext_oneapi_get_default_context());
66 if (DefaultContext->hasDevice(Device))
67 return DefaultContext;
70 context{createSyclObjFromImpl<device>(Device), {}, {}});
81 :
queue_impl(Device, getDefaultOrNew(Device), AsyncHandler, PropList){};
94 : MDevice(Device), MContext(Context), MAsyncHandler(AsyncHandler),
95 MPropList(PropList), MHostQueue(MDevice->is_host()),
96 MAssertHappenedBuffer(
range<1>{1}),
97 MIsInorder(has_property<property::queue::in_order>()),
99 has_property<ext::oneapi::property::queue::discard_events>()),
100 MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
101 MHasDiscardEventsSupport(
104 : (MIsInorder &&
getPlugin().getBackend() !=
105 backend::ext_oneapi_level_zero))) {
106 if (has_property<ext::oneapi::property::queue::discard_events>() &&
107 has_property<property::queue::enable_profiling>()) {
109 "Queue cannot be constructed with both of "
110 "discard_events and enable_profiling.");
112 if (!Context->hasDevice(Device))
113 throw cl::sycl::invalid_object_error(
114 "Queue cannot be constructed with the given context and device "
115 "as the context does not contain the given device.",
122 MQueues.push_back(createQueue(QOrder));
134 : MContext(Context), MAsyncHandler(AsyncHandler), MPropList(),
135 MHostQueue(false), MAssertHappenedBuffer(
range<1>{1}),
136 MIsInorder(has_property<property::queue::in_order>()),
138 has_property<ext::oneapi::property::queue::discard_events>()),
139 MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
140 MHasDiscardEventsSupport(
143 : (MIsInorder &&
getPlugin().getBackend() !=
144 backend::ext_oneapi_level_zero))) {
145 if (has_property<ext::oneapi::property::queue::discard_events>() &&
146 has_property<property::queue::enable_profiling>()) {
148 "Queue cannot be constructed with both of "
149 "discard_events and enable_profiling.");
152 MQueues.push_back(pi::cast<RT::PiQueue>(
PiQueue));
155 const detail::plugin &Plugin =
getPlugin();
158 sizeof(Device), &Device,
nullptr);
160 DeviceImplPtr(
new device_impl(Device, Context->getPlatformImpl()));
164 throw_asynchronous();
173 throw invalid_object_error(
174 "This instance of queue doesn't support OpenCL interoperability",
178 return pi::cast<cl_command_queue>(MQueues[0]);
183 return createSyclObjFromImpl<context>(MContext);
204 template <info::queue Param>
223 const std::shared_ptr<queue_impl> &Self,
224 const std::shared_ptr<queue_impl> &SecondQueue,
228 return submit_impl(CGF, Self, Self, SecondQueue, Loc, PostProcess);
231 std::lock_guard<std::mutex> Lock(MMutex);
232 MExceptions.PushBack(std::current_exception());
234 return SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue, Loc,
248 const std::shared_ptr<queue_impl> &Self,
251 return submit_impl(CGF, Self, Self,
nullptr, Loc, PostProcess);
267 throw_asynchronous();
283 std::lock_guard<std::mutex> Lock(MMutex);
284 std::swap(Exceptions, MExceptions);
289 if (Exceptions.
size())
290 MAsyncHandler(std::move(Exceptions));
306 if (MPropList.has_property<
315 assert(Plugin.
getBackend() == MDevice->getPlugin().getBackend());
317 Context, Device, CreationFlags, &Queue);
336 bool ReuseQueue =
false;
338 std::lock_guard<std::mutex> Lock(MMutex);
344 MQueues.push_back({});
345 PIQ = &MQueues.back();
349 PIQ = &MQueues[MNextQueueIdx];
369 return getExclusiveQueueHandleRef();
375 return MPropList.has_property<propertyT>();
382 return MPropList.get_property<propertyT>();
394 event memset(
const std::shared_ptr<queue_impl> &Self,
void *Ptr,
int Value,
395 size_t Count,
const std::vector<event> &DepEvents);
406 event memcpy(
const std::shared_ptr<queue_impl> &Self,
void *Dest,
407 const void *Src,
size_t Count,
408 const std::vector<event> &DepEvents);
419 event mem_advise(
const std::shared_ptr<queue_impl> &Self,
const void *Ptr,
421 const std::vector<event> &DepEvents);
427 std::lock_guard<std::mutex> Lock(MMutex);
428 MExceptions.PushBack(ExceptionPtr);
432 return GlobalHandler::instance().getHostTaskThreadPool();
441 return MAssertHappenedBuffer;
446 template <
typename HandlerType = handler>
451 auto IsExpDepManaged = [](
const CG::CGTYPE &Type) {
452 return (Type == CG::CGTYPE::CodeplayHostTask ||
453 Type == CG::CGTYPE::CodeplayInteropTask);
458 std::lock_guard<std::mutex> Lock{MLastEventMtx};
460 if (MLastCGType == CG::CGTYPE::None)
464 bool NeedSeparateDependencyMgmt =
465 IsExpDepManaged(Type) || IsExpDepManaged(MLastCGType);
467 if (NeedSeparateDependencyMgmt)
468 Handler.depends_on(MLastEvent);
470 EventRet = Handler.finalize();
472 MLastEvent = EventRet;
475 EventRet = Handler.finalize();
489 event submit_impl(
const std::function<
void(
handler &)> &CGF,
490 const std::shared_ptr<queue_impl> &Self,
491 const std::shared_ptr<queue_impl> &PrimaryQueue,
492 const std::shared_ptr<queue_impl> &SecondaryQueue,
494 const SubmitPostProcessF *PostProcess) {
495 handler Handler(Self, PrimaryQueue, SecondaryQueue, MHostQueue);
496 Handler.saveCodeLoc(Loc);
506 bool IsKernel = Type == CG::Kernel;
507 bool KernelUsesAssert =
false;
511 KernelUsesAssert = !(Handler.MKernel && Handler.MKernel->isInterop()) &&
512 ProgramManager::getInstance().kernelUsesAssert(
513 Handler.MOSModuleHandle, Handler.MKernelName);
515 finalizeHandler(Handler, Type, Event);
517 (*PostProcess)(IsKernel, KernelUsesAssert, Event);
519 finalizeHandler(Handler, Type, Event);
527 void *instrumentationProlog(
const detail::code_location &CodeLoc,
528 std::string &Name, int32_t StreamID,
531 void instrumentationEpilog(
void *TelementryEvent, std::string &Name,
532 int32_t StreamID, uint64_t IId);
539 void addSharedEvent(
const event &Event);
544 void addEvent(
const event &Event);
553 std::vector<std::weak_ptr<event_impl>> MEventsWeak;
558 std::vector<event> MEventsShared;
559 exception_list MExceptions;
561 const property_list MPropList;
564 std::vector<RT::PiQueue> MQueues;
566 size_t MNextQueueIdx = 0;
568 const bool MHostQueue =
false;
570 bool MSupportOOO =
true;
573 buffer<AssertHappened, 1> MAssertHappenedBuffer;
578 std::mutex MLastEventMtx;
582 CG::CGTYPE MLastCGType = CG::CGTYPE::None;
584 const bool MIsInorder;
597 const bool MHasDiscardEventsSupport;