diff --git a/sycl/source/detail/cg.hpp b/sycl/source/detail/cg.hpp index ccd546cd968f1..d33d65c3b90e9 100644 --- a/sycl/source/detail/cg.hpp +++ b/sycl/source/detail/cg.hpp @@ -725,14 +725,10 @@ class CGHostTask : public CG { std::shared_ptr MContext; std::vector MArgs; - CGHostTask(std::shared_ptr HostTask, - std::shared_ptr Queue, + CGHostTask(std::shared_ptr HostTask, detail::queue_impl *Queue, std::shared_ptr Context, std::vector Args, CG::StorageInitHelper CGData, - CGType Type, detail::code_location loc = {}) - : CG(Type, std::move(CGData), std::move(loc)), - MHostTask(std::move(HostTask)), MQueue(Queue), MContext(Context), - MArgs(std::move(Args)) {} + CGType Type, detail::code_location loc = {}); }; } // namespace detail diff --git a/sycl/source/detail/graph_impl.hpp b/sycl/source/detail/graph_impl.hpp index 553285d8ade1e..0ef5b506318da 100644 --- a/sycl/source/detail/graph_impl.hpp +++ b/sycl/source/detail/graph_impl.hpp @@ -288,7 +288,7 @@ class node_impl : public std::enable_shared_from_this { return std::make_unique( sycl::detail::CGHostTask( - std::move(HostTaskSPtr), CommandGroupPtr->MQueue, + std::move(HostTaskSPtr), CommandGroupPtr->MQueue.get(), CommandGroupPtr->MContext, std::move(NewArgs), std::move(Data), CommandGroupPtr->getType(), Loc)); } diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 34982e99ead92..40d61c39e0262 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -650,9 +650,12 @@ class queue_impl : public std::enable_shared_from_this { // for in order ones. void revisitUnenqueuedCommandsState(const EventImplPtr &CompletedHostTask); - static ContextImplPtr getContext(const QueueImplPtr &Queue) { + static ContextImplPtr getContext(queue_impl *Queue) { return Queue ? Queue->getContextImplPtr() : nullptr; } + static ContextImplPtr getContext(const QueueImplPtr &Queue) { + return getContext(Queue.get()); + } // Must be called under MMutex protection void doUnenqueuedCommandCleanup( diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 946ad402de46a..2b859e1e57ab0 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -127,11 +127,14 @@ static unsigned long long getQueueID(const std::shared_ptr &Queue) { } #endif -static context_impl *getContext(const QueueImplPtr &Queue) { +static context_impl *getContext(queue_impl *Queue) { if (Queue) return &Queue->getContextImpl(); return nullptr; } +static context_impl *getContext(const std::shared_ptr &Queue) { + return getContext(Queue.get()); +} #ifdef __SYCL_ENABLE_GNU_DEMANGLING struct DemangleHandle { @@ -510,7 +513,7 @@ void Command::waitForPreparedHostEvents() const { HostEvent->waitInternal(); } -void Command::waitForEvents(QueueImplPtr Queue, +void Command::waitForEvents(queue_impl *Queue, std::vector &EventImpls, ur_event_handle_t &Event) { #ifndef NDEBUG @@ -566,12 +569,12 @@ void Command::waitForEvents(QueueImplPtr Queue, /// references to event_impl class members because Command /// should not outlive the event connected to it. Command::Command( - CommandType Type, QueueImplPtr Queue, + CommandType Type, queue_impl *Queue, ur_exp_command_buffer_handle_t CommandBuffer, const std::vector &SyncPoints) - : MQueue(std::move(Queue)), - MEvent(MQueue ? detail::event_impl::create_device_event(*MQueue) - : detail::event_impl::create_incomplete_host_event()), + : MQueue(Queue ? Queue->shared_from_this() : nullptr), + MEvent(Queue ? detail::event_impl::create_device_event(*Queue) + : detail::event_impl::create_incomplete_host_event()), MPreparedDepsEvents(MEvent->getPreparedDepsEvents()), MPreparedHostDepsEvents(MEvent->getPreparedHostDepsEvents()), MType(Type), MCommandBuffer(CommandBuffer), MSyncPointDeps(SyncPoints) { @@ -1034,7 +1037,7 @@ void Command::copySubmissionCodeLocation() { #endif } -AllocaCommandBase::AllocaCommandBase(CommandType Type, QueueImplPtr Queue, +AllocaCommandBase::AllocaCommandBase(CommandType Type, queue_impl *Queue, Requirement Req, AllocaCommandBase *LinkedAllocaCmd, bool IsConst) @@ -1077,10 +1080,10 @@ bool AllocaCommandBase::supportsPostEnqueueCleanup() const { return false; } bool AllocaCommandBase::readyForCleanup() const { return false; } -AllocaCommand::AllocaCommand(QueueImplPtr Queue, Requirement Req, +AllocaCommand::AllocaCommand(queue_impl *Queue, Requirement Req, bool InitFromUserData, AllocaCommandBase *LinkedAllocaCmd, bool IsConst) - : AllocaCommandBase(CommandType::ALLOCA, std::move(Queue), std::move(Req), + : AllocaCommandBase(CommandType::ALLOCA, Queue, std::move(Req), LinkedAllocaCmd, IsConst), MInitFromUserData(InitFromUserData) { // Node event must be created before the dependent edge is added to this @@ -1115,7 +1118,7 @@ ur_result_t AllocaCommand::enqueueImp() { if (!MQueue) { // Do not need to make allocation if we have a linked device allocation - Command::waitForEvents(MQueue, EventImpls, UREvent); + Command::waitForEvents(MQueue.get(), EventImpls, UREvent); MEvent->setHandle(UREvent); return UR_RESULT_SUCCESS; @@ -1155,12 +1158,11 @@ void AllocaCommand::printDot(std::ostream &Stream) const { } } -AllocaSubBufCommand::AllocaSubBufCommand(QueueImplPtr Queue, Requirement Req, +AllocaSubBufCommand::AllocaSubBufCommand(queue_impl *Queue, Requirement Req, AllocaCommandBase *ParentAlloca, std::vector &ToEnqueue, std::vector &ToCleanUp) - : AllocaCommandBase(CommandType::ALLOCA_SUB_BUF, std::move(Queue), - std::move(Req), + : AllocaCommandBase(CommandType::ALLOCA_SUB_BUF, Queue, std::move(Req), /*LinkedAllocaCmd*/ nullptr, /*IsConst*/ false), MParentAlloca(ParentAlloca) { // Node event must be created before the dependent edge @@ -1241,8 +1243,8 @@ void AllocaSubBufCommand::printDot(std::ostream &Stream) const { } } -ReleaseCommand::ReleaseCommand(QueueImplPtr Queue, AllocaCommandBase *AllocaCmd) - : Command(CommandType::RELEASE, std::move(Queue)), MAllocaCmd(AllocaCmd) { +ReleaseCommand::ReleaseCommand(queue_impl *Queue, AllocaCommandBase *AllocaCmd) + : Command(CommandType::RELEASE, Queue), MAllocaCmd(AllocaCmd) { emitInstrumentationDataProxy(); } @@ -1295,9 +1297,9 @@ ur_result_t ReleaseCommand::enqueueImp() { } if (NeedUnmap) { - const QueueImplPtr &Queue = CurAllocaIsHost - ? MAllocaCmd->MLinkedAllocaCmd->getQueue() - : MAllocaCmd->getQueue(); + queue_impl *Queue = CurAllocaIsHost + ? MAllocaCmd->MLinkedAllocaCmd->getQueue() + : MAllocaCmd->getQueue(); assert(Queue); @@ -1328,7 +1330,7 @@ ur_result_t ReleaseCommand::enqueueImp() { } ur_event_handle_t UREvent = nullptr; if (SkipRelease) - Command::waitForEvents(MQueue, EventImpls, UREvent); + Command::waitForEvents(MQueue.get(), EventImpls, UREvent); else { if (auto Result = callMemOpHelper( MemoryManager::release, getContext(MQueue), @@ -1366,11 +1368,10 @@ bool ReleaseCommand::supportsPostEnqueueCleanup() const { return false; } bool ReleaseCommand::readyForCleanup() const { return false; } MapMemObject::MapMemObject(AllocaCommandBase *SrcAllocaCmd, Requirement Req, - void **DstPtr, QueueImplPtr Queue, + void **DstPtr, queue_impl *Queue, access::mode MapMode) - : Command(CommandType::MAP_MEM_OBJ, std::move(Queue)), - MSrcAllocaCmd(SrcAllocaCmd), MSrcReq(std::move(Req)), MDstPtr(DstPtr), - MMapMode(MapMode) { + : Command(CommandType::MAP_MEM_OBJ, Queue), MSrcAllocaCmd(SrcAllocaCmd), + MSrcReq(std::move(Req)), MDstPtr(DstPtr), MMapMode(MapMode) { emitInstrumentationDataProxy(); } @@ -1430,9 +1431,9 @@ void MapMemObject::printDot(std::ostream &Stream) const { } UnMapMemObject::UnMapMemObject(AllocaCommandBase *DstAllocaCmd, Requirement Req, - void **SrcPtr, QueueImplPtr Queue) - : Command(CommandType::UNMAP_MEM_OBJ, std::move(Queue)), - MDstAllocaCmd(DstAllocaCmd), MDstReq(std::move(Req)), MSrcPtr(SrcPtr) { + void **SrcPtr, queue_impl *Queue) + : Command(CommandType::UNMAP_MEM_OBJ, Queue), MDstAllocaCmd(DstAllocaCmd), + MDstReq(std::move(Req)), MSrcPtr(SrcPtr) { emitInstrumentationDataProxy(); } @@ -1516,11 +1517,11 @@ MemCpyCommand::MemCpyCommand(Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd, Requirement DstReq, AllocaCommandBase *DstAllocaCmd, - QueueImplPtr SrcQueue, QueueImplPtr DstQueue) - : Command(CommandType::COPY_MEMORY, std::move(DstQueue)), - MSrcQueue(SrcQueue), MSrcReq(std::move(SrcReq)), - MSrcAllocaCmd(SrcAllocaCmd), MDstReq(std::move(DstReq)), - MDstAllocaCmd(DstAllocaCmd) { + queue_impl *SrcQueue, queue_impl *DstQueue) + : Command(CommandType::COPY_MEMORY, DstQueue), + MSrcQueue(SrcQueue ? SrcQueue->shared_from_this() : nullptr), + MSrcReq(std::move(SrcReq)), MSrcAllocaCmd(SrcAllocaCmd), + MDstReq(std::move(DstReq)), MDstAllocaCmd(DstAllocaCmd) { if (MSrcQueue) { MEvent->setContextImpl(MSrcQueue->getContextImplPtr()); } @@ -1652,7 +1653,7 @@ ur_result_t UpdateHostRequirementCommand::enqueueImp() { waitForPreparedHostEvents(); std::vector EventImpls = MPreparedDepsEvents; ur_event_handle_t UREvent = nullptr; - Command::waitForEvents(MQueue, EventImpls, UREvent); + Command::waitForEvents(MQueue.get(), EventImpls, UREvent); MEvent->setHandle(UREvent); assert(MSrcAllocaCmd && "Expected valid alloca command"); @@ -1689,11 +1690,11 @@ void UpdateHostRequirementCommand::printDot(std::ostream &Stream) const { MemCpyCommandHost::MemCpyCommandHost(Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd, Requirement DstReq, void **DstPtr, - QueueImplPtr SrcQueue, - QueueImplPtr DstQueue) - : Command(CommandType::COPY_MEMORY, std::move(DstQueue)), - MSrcQueue(SrcQueue), MSrcReq(std::move(SrcReq)), - MSrcAllocaCmd(SrcAllocaCmd), MDstReq(std::move(DstReq)), MDstPtr(DstPtr) { + queue_impl *SrcQueue, queue_impl *DstQueue) + : Command(CommandType::COPY_MEMORY, DstQueue), + MSrcQueue(SrcQueue ? SrcQueue->shared_from_this() : nullptr), + MSrcReq(std::move(SrcReq)), MSrcAllocaCmd(SrcAllocaCmd), + MDstReq(std::move(DstReq)), MDstPtr(DstPtr) { if (MSrcQueue) { MEvent->setContextImpl(MSrcQueue->getContextImplPtr()); } @@ -1735,7 +1736,7 @@ ContextImplPtr MemCpyCommandHost::getWorkerContext() const { } ur_result_t MemCpyCommandHost::enqueueImp() { - const QueueImplPtr &Queue = MWorkerQueue; + queue_impl *Queue = MWorkerQueue.get(); waitForPreparedHostEvents(); std::vector EventImpls = MPreparedDepsEvents; std::vector RawEvents = getUrEvents(EventImpls); @@ -1774,7 +1775,7 @@ EmptyCommand::EmptyCommand() : Command(CommandType::EMPTY_TASK, nullptr) { ur_result_t EmptyCommand::enqueueImp() { waitForPreparedHostEvents(); ur_event_handle_t UREvent = nullptr; - waitForEvents(MQueue, MPreparedDepsEvents, UREvent); + waitForEvents(MQueue.get(), MPreparedDepsEvents, UREvent); MEvent->setHandle(UREvent); return UR_RESULT_SUCCESS; } @@ -1858,9 +1859,9 @@ void MemCpyCommandHost::printDot(std::ostream &Stream) const { } UpdateHostRequirementCommand::UpdateHostRequirementCommand( - QueueImplPtr Queue, Requirement Req, AllocaCommandBase *SrcAllocaCmd, + queue_impl *Queue, Requirement Req, AllocaCommandBase *SrcAllocaCmd, void **DstPtr) - : Command(CommandType::UPDATE_REQUIREMENT, std::move(Queue)), + : Command(CommandType::UPDATE_REQUIREMENT, Queue), MSrcAllocaCmd(SrcAllocaCmd), MDstReq(std::move(Req)), MDstPtr(DstPtr) { emitInstrumentationDataProxy(); @@ -1956,11 +1957,10 @@ static std::string_view cgTypeToString(detail::CGType Type) { } ExecCGCommand::ExecCGCommand( - std::unique_ptr CommandGroup, QueueImplPtr Queue, + std::unique_ptr CommandGroup, queue_impl *Queue, bool EventNeeded, ur_exp_command_buffer_handle_t CommandBuffer, const std::vector &Dependencies) - : Command(CommandType::RUN_CG, std::move(Queue), CommandBuffer, - Dependencies), + : Command(CommandType::RUN_CG, Queue, CommandBuffer, Dependencies), MEventNeeded(EventNeeded), MCommandGroup(std::move(CommandGroup)) { if (MCommandGroup->getType() == detail::CGType::CodeplayHostTask) { MEvent->setSubmittedQueue( @@ -2777,20 +2777,18 @@ void enqueueImpKernel( } } -ur_result_t enqueueReadWriteHostPipe(const QueueImplPtr &Queue, +ur_result_t enqueueReadWriteHostPipe(queue_impl &Queue, const std::string &PipeName, bool blocking, void *ptr, size_t size, std::vector &RawEvents, detail::event_impl *OutEventImpl, bool read) { - assert(Queue && - "ReadWrite host pipe submissions should have an associated queue"); detail::HostPipeMapEntry *hostPipeEntry = ProgramManager::getInstance().getHostPipeEntry(PipeName); ur_program_handle_t Program = nullptr; - device Device = Queue->get_device(); - ContextImplPtr ContextImpl = Queue->getContextImplPtr(); + device Device = Queue.get_device(); + ContextImplPtr ContextImpl = Queue.getContextImplPtr(); std::optional CachedProgram = ContextImpl->getProgramForHostPipe(Device, hostPipeEntry); if (CachedProgram) @@ -2799,17 +2797,16 @@ ur_result_t enqueueReadWriteHostPipe(const QueueImplPtr &Queue, // If there was no cached program, build one. device_image_plain devImgPlain = ProgramManager::getInstance().getDeviceImageFromBinaryImage( - hostPipeEntry->getDevBinImage(), Queue->get_context(), - Queue->get_device()); + hostPipeEntry->getDevBinImage(), Queue.get_context(), Device); device_image_plain BuiltImage = ProgramManager::getInstance().build( std::move(devImgPlain), {std::move(Device)}, {}); Program = getSyclObjImpl(BuiltImage)->get_ur_program_ref(); } assert(Program && "Program for this hostpipe is not compiled."); - const AdapterPtr &Adapter = Queue->getAdapter(); + const AdapterPtr &Adapter = Queue.getAdapter(); - ur_queue_handle_t ur_q = Queue->getHandleRef(); + ur_queue_handle_t ur_q = Queue.getHandleRef(); ur_result_t Error; ur_event_handle_t UREvent = nullptr; @@ -3667,7 +3664,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() { if (!EventImpl) { EventImpl = MEvent.get(); } - return enqueueReadWriteHostPipe(MQueue, pipeName, blocking, hostPtr, + return enqueueReadWriteHostPipe(*MQueue, pipeName, blocking, hostPtr, typeSize, RawEvents, EventImpl, read); } case CGType::ExecCommandBuffer: { @@ -3802,7 +3799,7 @@ bool ExecCGCommand::readyForCleanup() const { } UpdateCommandBufferCommand::UpdateCommandBufferCommand( - QueueImplPtr Queue, + queue_impl *Queue, ext::oneapi::experimental::detail::exec_graph_impl *Graph, std::vector> Nodes) @@ -3813,7 +3810,7 @@ ur_result_t UpdateCommandBufferCommand::enqueueImp() { waitForPreparedHostEvents(); std::vector EventImpls = MPreparedDepsEvents; ur_event_handle_t UREvent = nullptr; - Command::waitForEvents(MQueue, EventImpls, UREvent); + Command::waitForEvents(MQueue.get(), EventImpls, UREvent); MEvent->setHandle(UREvent); auto CheckAndFindAlloca = [](Requirement *Req, const DepDesc &Dep) { @@ -3885,6 +3882,15 @@ void UpdateCommandBufferCommand::printDot(std::ostream &Stream) const { void UpdateCommandBufferCommand::emitInstrumentationData() {} bool UpdateCommandBufferCommand::producesPiEvent() const { return false; } +CGHostTask::CGHostTask(std::shared_ptr HostTask, + detail::queue_impl *Queue, + std::shared_ptr Context, + std::vector Args, CG::StorageInitHelper CGData, + CGType Type, detail::code_location loc) + : CG(Type, std::move(CGData), std::move(loc)), + MHostTask(std::move(HostTask)), + MQueue(Queue ? Queue->shared_from_this() : nullptr), MContext(Context), + MArgs(std::move(Args)) {} } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index b9bc793f7a2a5..c5718ee9dc150 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -43,7 +43,6 @@ class event_impl; class context_impl; class DispatchHostTask; -using QueueImplPtr = std::shared_ptr; using EventImplPtr = std::shared_ptr; using ContextImplPtr = std::shared_ptr; using StreamImplPtr = std::shared_ptr; @@ -121,7 +120,7 @@ class Command { }; Command( - CommandType Type, QueueImplPtr Queue, + CommandType Type, queue_impl *Queue, ur_exp_command_buffer_handle_t CommandBuffer = nullptr, const std::vector &SyncPoints = {}); @@ -174,7 +173,7 @@ class Command { MBlockedUsers.push_back(NewUser); } - const QueueImplPtr &getQueue() const { return MQueue; } + queue_impl *getQueue() const { return MQueue.get(); } const EventImplPtr &getEvent() const { return MEvent; } @@ -258,16 +257,16 @@ class Command { #endif // __INTEL_PREVIEW_BREAKING_CHANGES protected: - QueueImplPtr MQueue; + std::shared_ptr MQueue; EventImplPtr MEvent; - QueueImplPtr MWorkerQueue; + std::shared_ptr MWorkerQueue; /// Dependency events prepared for waiting by backend. /// See processDepEvent for details. std::vector &MPreparedDepsEvents; std::vector &MPreparedHostDepsEvents; - void waitForEvents(QueueImplPtr Queue, std::vector &RawEvents, + void waitForEvents(queue_impl *Queue, std::vector &RawEvents, ur_event_handle_t &Event); void waitForPreparedHostEvents() const; @@ -431,7 +430,7 @@ class EmptyCommand : public Command { /// on Host or underlying framework. class ReleaseCommand : public Command { public: - ReleaseCommand(QueueImplPtr Queue, AllocaCommandBase *AllocaCmd); + ReleaseCommand(queue_impl *Queue, AllocaCommandBase *AllocaCmd); void printDot(std::ostream &Stream) const final; void emitInstrumentationData() override; @@ -449,7 +448,7 @@ class ReleaseCommand : public Command { /// Base class for memory allocation commands. class AllocaCommandBase : public Command { public: - AllocaCommandBase(CommandType Type, QueueImplPtr Queue, Requirement Req, + AllocaCommandBase(CommandType Type, queue_impl *Queue, Requirement Req, AllocaCommandBase *LinkedAllocaCmd, bool IsConst); ReleaseCommand *getReleaseCmd() { return &MReleaseCmd; } @@ -494,7 +493,7 @@ class AllocaCommandBase : public Command { /// or underlying framework. class AllocaCommand : public AllocaCommandBase { public: - AllocaCommand(QueueImplPtr Queue, Requirement Req, + AllocaCommand(queue_impl *Queue, Requirement Req, bool InitFromUserData = true, AllocaCommandBase *LinkedAllocaCmd = nullptr, bool IsConst = false); @@ -514,7 +513,7 @@ class AllocaCommand : public AllocaCommandBase { /// The AllocaSubBuf command enqueues creation of sub-buffer of memory object. class AllocaSubBufCommand : public AllocaCommandBase { public: - AllocaSubBufCommand(QueueImplPtr Queue, Requirement Req, + AllocaSubBufCommand(queue_impl *Queue, Requirement Req, AllocaCommandBase *ParentAlloca, std::vector &ToEnqueue, std::vector &ToCleanUp); @@ -534,7 +533,7 @@ class AllocaSubBufCommand : public AllocaCommandBase { class MapMemObject : public Command { public: MapMemObject(AllocaCommandBase *SrcAllocaCmd, Requirement Req, void **DstPtr, - QueueImplPtr Queue, access::mode MapMode); + queue_impl *Queue, access::mode MapMode); void printDot(std::ostream &Stream) const final; const Requirement *getRequirement() const final { return &MSrcReq; } @@ -553,7 +552,7 @@ class MapMemObject : public Command { class UnMapMemObject : public Command { public: UnMapMemObject(AllocaCommandBase *DstAllocaCmd, Requirement Req, - void **SrcPtr, QueueImplPtr Queue); + void **SrcPtr, queue_impl *Queue); void printDot(std::ostream &Stream) const final; const Requirement *getRequirement() const final { return &MDstReq; } @@ -574,7 +573,7 @@ class MemCpyCommand : public Command { public: MemCpyCommand(Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd, Requirement DstReq, AllocaCommandBase *DstAllocaCmd, - QueueImplPtr SrcQueue, QueueImplPtr DstQueue); + queue_impl *SrcQueue, queue_impl *DstQueue); void printDot(std::ostream &Stream) const final; const Requirement *getRequirement() const final { return &MDstReq; } @@ -585,7 +584,7 @@ class MemCpyCommand : public Command { private: ur_result_t enqueueImp() final; - QueueImplPtr MSrcQueue; + std::shared_ptr MSrcQueue; Requirement MSrcReq; AllocaCommandBase *MSrcAllocaCmd = nullptr; Requirement MDstReq; @@ -597,8 +596,8 @@ class MemCpyCommand : public Command { class MemCpyCommandHost : public Command { public: MemCpyCommandHost(Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd, - Requirement DstReq, void **DstPtr, QueueImplPtr SrcQueue, - QueueImplPtr DstQueue); + Requirement DstReq, void **DstPtr, queue_impl *SrcQueue, + queue_impl *DstQueue); void printDot(std::ostream &Stream) const final; const Requirement *getRequirement() const final { return &MDstReq; } @@ -608,20 +607,13 @@ class MemCpyCommandHost : public Command { private: ur_result_t enqueueImp() final; - QueueImplPtr MSrcQueue; + std::shared_ptr MSrcQueue; Requirement MSrcReq; AllocaCommandBase *MSrcAllocaCmd = nullptr; Requirement MDstReq; void **MDstPtr = nullptr; }; -ur_result_t enqueueReadWriteHostPipe(const QueueImplPtr &Queue, - const std::string &PipeName, bool blocking, - void *ptr, size_t size, - std::vector &RawEvents, - detail::event_impl *OutEventImpl, - bool read); - void enqueueImpKernel( queue_impl &Queue, NDRDescT &NDRDesc, std::vector &Args, const std::shared_ptr &KernelBundleImplPtr, @@ -641,7 +633,7 @@ void enqueueImpKernel( class ExecCGCommand : public Command { public: ExecCGCommand( - std::unique_ptr CommandGroup, QueueImplPtr Queue, + std::unique_ptr CommandGroup, queue_impl *Queue, bool EventNeeded, ur_exp_command_buffer_handle_t CommandBuffer = nullptr, const std::vector &Dependencies = {}); @@ -700,7 +692,7 @@ std::pair emitKernelInstrumentationData( class UpdateHostRequirementCommand : public Command { public: - UpdateHostRequirementCommand(QueueImplPtr Queue, Requirement Req, + UpdateHostRequirementCommand(queue_impl *Queue, Requirement Req, AllocaCommandBase *SrcAllocaCmd, void **DstPtr); void printDot(std::ostream &Stream) const final; @@ -718,7 +710,7 @@ class UpdateHostRequirementCommand : public Command { class UpdateCommandBufferCommand : public Command { public: explicit UpdateCommandBufferCommand( - QueueImplPtr Queue, + queue_impl *Queue, ext::oneapi::experimental::detail::exec_graph_impl *Graph, std::vector> Nodes); diff --git a/sycl/source/detail/scheduler/graph_builder.cpp b/sycl/source/detail/scheduler/graph_builder.cpp index eaba6f0033455..1d7df4e86f6a1 100644 --- a/sycl/source/detail/scheduler/graph_builder.cpp +++ b/sycl/source/detail/scheduler/graph_builder.cpp @@ -51,12 +51,15 @@ static bool IsSuitableSubReq(const Requirement *Req) { return Req->MIsSubBuffer; } -static bool isOnSameContext(const ContextImplPtr Context, - const QueueImplPtr &Queue) { +static bool isOnSameContext(const ContextImplPtr Context, queue_impl *Queue) { // Covers case for host usage (nullptr == nullptr) and existing device // contexts comparison. return Context == queue_impl::getContext(Queue); } +static bool isOnSameContext(const ContextImplPtr Context, + const QueueImplPtr &Queue) { + return isOnSameContext(Context, Queue.get()); +} /// Checks if the required access mode is allowed under the current one. static bool isAccessModeAllowed(access::mode Required, access::mode Current) { @@ -276,7 +279,8 @@ UpdateHostRequirementCommand *Scheduler::GraphBuilder::insertUpdateHostReqCmd( AllocaCommandBase *AllocaCmd = findAllocaForReq(Record, Req, Context); assert(AllocaCmd && "There must be alloca for requirement!"); UpdateHostRequirementCommand *UpdateCommand = - new UpdateHostRequirementCommand(Queue, *Req, AllocaCmd, &Req->MData); + new UpdateHostRequirementCommand(Queue.get(), *Req, AllocaCmd, + &Req->MData); // Need copy of requirement because after host accessor destructor call // dependencies become invalid if requirement is stored by pointer. const Requirement *StoredReq = UpdateCommand->getRequirement(); @@ -705,8 +709,8 @@ AllocaCommandBase *Scheduler::GraphBuilder::getOrCreateAllocaForReq( auto *ParentAlloca = getOrCreateAllocaForReq(Record, &ParentRequirement, Queue, ToEnqueue); - AllocaCmd = new AllocaSubBufCommand(Queue, *Req, ParentAlloca, ToEnqueue, - ToCleanUp); + AllocaCmd = new AllocaSubBufCommand(Queue.get(), *Req, ParentAlloca, + ToEnqueue, ToCleanUp); } else { const Requirement FullReq(/*Offset*/ {0, 0, 0}, Req->MMemoryRange, @@ -782,8 +786,8 @@ AllocaCommandBase *Scheduler::GraphBuilder::getOrCreateAllocaForReq( } } - AllocaCmd = - new AllocaCommand(Queue, FullReq, InitFromUserData, LinkedAllocaCmd); + AllocaCmd = new AllocaCommand(Queue.get(), FullReq, InitFromUserData, + LinkedAllocaCmd); // Update linked command if (LinkedAllocaCmd) { @@ -928,9 +932,9 @@ Command *Scheduler::GraphBuilder::addCG( std::vector &Reqs = CommandGroup->getRequirements(); std::vector &Events = CommandGroup->getEvents(); - auto NewCmd = std::make_unique(std::move(CommandGroup), Queue, - EventNeeded, CommandBuffer, - std::move(Dependencies)); + auto NewCmd = std::make_unique( + std::move(CommandGroup), Queue.get(), EventNeeded, CommandBuffer, + std::move(Dependencies)); if (!NewCmd) throw exception(make_error_code(errc::memory_allocation), @@ -1280,7 +1284,7 @@ Command *Scheduler::GraphBuilder::addCommandGraphUpdate( std::vector &Events, std::vector &ToEnqueue) { auto NewCmd = - std::make_unique(Queue, Graph, Nodes); + std::make_unique(Queue.get(), Graph, Nodes); // If there are multiple requirements for the same memory object, its // AllocaCommand creation will be dependent on the access mode of the first // requirement. Combine these access modes to take all of them into account. diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index a28f21c408f80..300a09a17b128 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -701,9 +701,8 @@ event handler::finalize() { detail::context_impl &Context = impl->get_context(); detail::queue_impl *Queue = impl->get_queue_or_null(); CommandGroup.reset(new detail::CGHostTask( - std::move(impl->MHostTask), Queue ? Queue->shared_from_this() : nullptr, - Context.shared_from_this(), std::move(impl->MArgs), - std::move(impl->CGData), getType(), MCodeLoc)); + std::move(impl->MHostTask), Queue, Context.shared_from_this(), + std::move(impl->MArgs), std::move(impl->CGData), getType(), MCodeLoc)); break; } case detail::CGType::Barrier: diff --git a/sycl/unittests/buffer/BufferReleaseBase.hpp b/sycl/unittests/buffer/BufferReleaseBase.hpp index 322b85ffe469c..504c2d4047de6 100644 --- a/sycl/unittests/buffer/BufferReleaseBase.hpp +++ b/sycl/unittests/buffer/BufferReleaseBase.hpp @@ -26,11 +26,11 @@ class MockCmdWithReleaseTracking : public MockCommand { MockCmdWithReleaseTracking( sycl::detail::QueueImplPtr Queue, sycl::detail::Requirement Req, sycl::detail::Command::CommandType Type = sycl::detail::Command::RUN_CG) - : MockCommand(Queue, Req, Type){}; + : MockCommand(Queue.get(), Req, Type) {}; MockCmdWithReleaseTracking( sycl::detail::QueueImplPtr Queue, sycl::detail::Command::CommandType Type = sycl::detail::Command::RUN_CG) - : MockCommand(Queue, Type){}; + : MockCommand(Queue.get(), Type) {}; ~MockCmdWithReleaseTracking() { Release(); } MOCK_METHOD0(Release, void()); }; diff --git a/sycl/unittests/scheduler/BlockedCommands.cpp b/sycl/unittests/scheduler/BlockedCommands.cpp index 0dce062f89363..7f2374e14c986 100644 --- a/sycl/unittests/scheduler/BlockedCommands.cpp +++ b/sycl/unittests/scheduler/BlockedCommands.cpp @@ -14,15 +14,23 @@ using namespace sycl; using namespace testing; -TEST_F(SchedulerTest, BlockedCommands) { - /* +TEST_F(SchedulerTest, DISABLED_BlockedCommands) { + // NOTE: Before https://github.com/intel/llvm/pull/1414 it was + // + // > MockCmd.MRetVal = CL_DEVICE_PARTITION_EQUALLY + // + // where it's `UR_RESULT_ERROR_DEVICE_LOST` now (just to uncomment and make it + // compileable but still skipped). No idea what it should be and the + // PR above seemed to have none either. + sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; - MockCommand MockCmd(detail::getSyclObjImpl(Q)); + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); + MockCommand MockCmd(&QueueImpl); MockCmd.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; MockCmd.MIsBlockable = true; - MockCmd.MRetVal = CL_DEVICE_PARTITION_EQUALLY; + MockCmd.MRetVal = UR_RESULT_ERROR_DEVICE_LOST; MockScheduler MS; auto Lock = MS.acquireGraphReadLock(); @@ -35,7 +43,7 @@ TEST_F(SchedulerTest, BlockedCommands) { MockCmd.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; Res.MResult = detail::EnqueueResultT::SyclEnqueueSuccess; - MockCmd.MRetVal = CL_DEVICE_PARTITION_EQUALLY; + MockCmd.MRetVal = UR_RESULT_ERROR_DEVICE_LOST; Enqueued = MockScheduler::enqueueCommand(&MockCmd, Res, detail::BLOCKING); ASSERT_FALSE(Enqueued) << "Blocked command should not be enqueued\n"; @@ -51,28 +59,29 @@ TEST_F(SchedulerTest, BlockedCommands) { Enqueued = MockScheduler::enqueueCommand(&MockCmd, Res, detail::BLOCKING); ASSERT_TRUE(Enqueued && Res.MResult == detail::EnqueueResultT::SyclEnqueueSuccess) - << "The command is expected to be successfully enqueued.\n";*/ + << "The command is expected to be successfully enqueued.\n"; } TEST_F(SchedulerTest, DontEnqueueDepsIfOneOfThemIsBlocked) { sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); - MockCommand A(detail::getSyclObjImpl(Q)); + MockCommand A(&QueueImpl); A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; A.MIsBlockable = true; A.MRetVal = UR_RESULT_SUCCESS; - MockCommand B(detail::getSyclObjImpl(Q)); + MockCommand B(&QueueImpl); B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; B.MIsBlockable = true; B.MRetVal = UR_RESULT_SUCCESS; - MockCommand C(detail::getSyclObjImpl(Q)); + MockCommand C(&QueueImpl); C.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; C.MIsBlockable = true; - MockCommand D(detail::getSyclObjImpl(Q)); + MockCommand D(&QueueImpl); D.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; D.MIsBlockable = true; D.MRetVal = UR_RESULT_SUCCESS; @@ -107,12 +116,13 @@ TEST_F(SchedulerTest, DontEnqueueDepsIfOneOfThemIsBlocked) { TEST_F(SchedulerTest, EnqueueBlockedCommandEarlyExit) { sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); - MockCommand A(detail::getSyclObjImpl(Q)); + MockCommand A(&QueueImpl); A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; A.MIsBlockable = true; - MockCommand B(detail::getSyclObjImpl(Q)); + MockCommand B(&QueueImpl); B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; B.MRetVal = UR_RESULT_ERROR_OUT_OF_RESOURCES; @@ -153,19 +163,20 @@ TEST_F(SchedulerTest, EnqueueBlockedCommandEarlyExit) { TEST_F(SchedulerTest, EnqueueHostDependency) { sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); - MockCommand A(detail::getSyclObjImpl(Q)); + MockCommand A(&QueueImpl); A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; A.MIsBlockable = true; A.MRetVal = UR_RESULT_SUCCESS; - MockCommand B(detail::getSyclObjImpl(Q)); + MockCommand B(&QueueImpl); B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; B.MIsBlockable = true; B.MRetVal = UR_RESULT_SUCCESS; std::shared_ptr DepEvent = - sycl::detail::event_impl::create_device_event(*detail::getSyclObjImpl(Q)); + sycl::detail::event_impl::create_device_event(QueueImpl); DepEvent->setCommand(&B); std::vector ToCleanUp; diff --git a/sycl/unittests/scheduler/FailedCommands.cpp b/sycl/unittests/scheduler/FailedCommands.cpp index 48f0f906a0fc2..f297f5da7a7eb 100644 --- a/sycl/unittests/scheduler/FailedCommands.cpp +++ b/sycl/unittests/scheduler/FailedCommands.cpp @@ -18,10 +18,11 @@ TEST_F(SchedulerTest, FailedDependency) { unittest::UrMock<> Mock; platform Plt = sycl::platform(); queue Queue(context(Plt), default_selector_v); + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Queue); detail::Requirement MockReq = getMockRequirement(); - MockCommand MDep(detail::getSyclObjImpl(Queue)); - MockCommand MUser(detail::getSyclObjImpl(Queue)); + MockCommand MDep(&QueueImpl); + MockCommand MUser(&QueueImpl); MDep.addUser(&MUser); std::vector ToCleanUp; (void)MUser.addDep(detail::DepDesc{&MDep, &MockReq, nullptr}, ToCleanUp); diff --git a/sycl/unittests/scheduler/GraphCleanup.cpp b/sycl/unittests/scheduler/GraphCleanup.cpp index 6f628f99a84e9..7ac490c7f76f6 100644 --- a/sycl/unittests/scheduler/GraphCleanup.cpp +++ b/sycl/unittests/scheduler/GraphCleanup.cpp @@ -65,23 +65,24 @@ static void verifyCleanup(detail::MemObjRecord *Record, // Check that any non-leaf commands enqueued as part of high level scheduler // calls are cleaned up. static void checkCleanupOnEnqueue(MockScheduler &MS, - detail::QueueImplPtr &QueueImpl, + detail::QueueImplPtr &QueueImplPtr, buffer &Buf, detail::Requirement &MockReq) { + detail::queue_impl &QueueImpl = *QueueImplPtr; bool CommandDeleted = false; std::vector ToCleanUp; std::vector ToEnqueue; detail::MemObjRecord *Record = - MS.getOrInsertMemObjRecord(QueueImpl, &MockReq); + MS.getOrInsertMemObjRecord(QueueImplPtr, &MockReq); detail::AllocaCommandBase *AllocaCmd = - MS.getOrCreateAllocaForReq(Record, &MockReq, QueueImpl, ToEnqueue); + MS.getOrCreateAllocaForReq(Record, &MockReq, QueueImplPtr, ToEnqueue); std::function Callback = [&CommandDeleted]() { CommandDeleted = true; }; // Check addCG. MockCommand *MockCmd = - new MockCommandWithCallback(QueueImpl, MockReq, Callback); + new MockCommandWithCallback(&QueueImpl, MockReq, Callback); (void)MockCmd->addDep(detail::DepDesc(AllocaCmd, &MockReq, nullptr), ToCleanUp); EXPECT_TRUE(ToCleanUp.empty()); @@ -98,13 +99,13 @@ static void checkCleanupOnEnqueue(MockScheduler &MS, /*Requirements*/ {&MockReq}, /*Events*/ {}))}; detail::EventImplPtr Event = - MS.addCG(std::move(CG), QueueImpl, /*EventNeeded=*/true); + MS.addCG(std::move(CG), QueueImplPtr, /*EventNeeded=*/true); auto *Cmd = static_cast(Event->getCommand()); verifyCleanup(Record, AllocaCmd, MockCmd, CommandDeleted); // Check add/releaseHostAccessor. CommandDeleted = false; - MockCmd = new MockCommandWithCallback(QueueImpl, MockReq, Callback); + MockCmd = new MockCommandWithCallback(&QueueImpl, MockReq, Callback); addEdge(MockCmd, Cmd, AllocaCmd); MS.addNodeToLeaves(Record, MockCmd, access::mode::read_write, ToEnqueue); MS.updateLeaves({Cmd}, Record, access::mode::read_write, ToCleanUp); @@ -112,10 +113,10 @@ static void checkCleanupOnEnqueue(MockScheduler &MS, verifyCleanup(Record, AllocaCmd, MockCmd, CommandDeleted); CommandDeleted = false; - MockCmd = new MockCommandWithCallback(QueueImpl, MockReq, Callback); + MockCmd = new MockCommandWithCallback(&QueueImpl, MockReq, Callback); addEdge(MockCmd, AllocaCmd, AllocaCmd); MockCommand *LeafMockCmd = - new MockCommandWithCallback(QueueImpl, MockReq, Callback); + new MockCommandWithCallback(&QueueImpl, MockReq, Callback); addEdge(LeafMockCmd, MockCmd, AllocaCmd); MS.addNodeToLeaves(Record, LeafMockCmd, access::mode::read_write, ToEnqueue); MS.releaseHostAccessor(&MockReq); @@ -125,7 +126,7 @@ static void checkCleanupOnEnqueue(MockScheduler &MS, auto addNewMockCmds = [&]() -> MockCommand * { CommandDeleted = false; MockCmd = LeafMockCmd; - LeafMockCmd = new MockCommandWithCallback(QueueImpl, MockReq, Callback); + LeafMockCmd = new MockCommandWithCallback(&QueueImpl, MockReq, Callback); addEdge(LeafMockCmd, MockCmd, AllocaCmd); MS.addNodeToLeaves(Record, LeafMockCmd, access::mode::read_write, ToEnqueue); @@ -139,7 +140,7 @@ static void checkCleanupOnEnqueue(MockScheduler &MS, verifyCleanup(Record, AllocaCmd, MockCmd, CommandDeleted); CommandDeleted = false; MockCmd = LeafMockCmd; - LeafMockCmd = new MockCommandWithCallback(QueueImpl, MockReq, Callback); + LeafMockCmd = new MockCommandWithCallback(&QueueImpl, MockReq, Callback); addEdge(LeafMockCmd, MockCmd, AllocaCmd); MS.addNodeToLeaves(Record, LeafMockCmd, access::mode::read_write, ToEnqueue); @@ -179,7 +180,7 @@ static void checkCleanupOnLeafUpdate( // Add a mock command as a leaf and enqueue it. MockCommand *MockCmd = - new MockCommandWithCallback(QueueImpl, MockReq, Callback); + new MockCommandWithCallback(QueueImpl.get(), MockReq, Callback); (void)MockCmd->addDep(detail::DepDesc(AllocaCmd, &MockReq, nullptr), ToCleanUp); EXPECT_TRUE(ToCleanUp.empty()); @@ -250,7 +251,8 @@ TEST_F(SchedulerTest, PostEnqueueCleanup) { std::vector> Leaves; for (std::size_t I = 0; I < Record->MWriteLeaves.genericCommandsCapacity(); ++I) - Leaves.push_back(std::make_unique(QueueImpl, MockReq)); + Leaves.push_back( + std::make_unique(QueueImpl.get(), MockReq)); detail::AllocaCommandBase *AllocaCmd = Record->MAllocaCommands[0]; std::vector ToCleanUp; diff --git a/sycl/unittests/scheduler/LeafLimit.cpp b/sycl/unittests/scheduler/LeafLimit.cpp index 7d07dffedf56b..e169b4b89a016 100644 --- a/sycl/unittests/scheduler/LeafLimit.cpp +++ b/sycl/unittests/scheduler/LeafLimit.cpp @@ -30,6 +30,7 @@ inline constexpr auto DisableCleanupName = TEST_F(SchedulerTest, LeafLimit) { sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); // All of the mock commands are owned on the test side, prevent post enqueue // cleanup from deleting some of them. @@ -43,16 +44,14 @@ TEST_F(SchedulerTest, LeafLimit) { buffer Buf(range<1>(1)); detail::Requirement MockReq = getMockRequirement(Buf); - MockDepCmd = - std::make_unique(detail::getSyclObjImpl(Q), MockReq); + MockDepCmd = std::make_unique(&QueueImpl, MockReq); detail::MemObjRecord *Rec = MS.getOrInsertMemObjRecord(detail::getSyclObjImpl(Q), &MockReq); // Create commands that will be added as leaves exceeding the limit by 1 for (std::size_t i = 0; i < Rec->MWriteLeaves.genericCommandsCapacity() + 1; ++i) { - LeavesToAdd.push_back( - std::make_unique(detail::getSyclObjImpl(Q), MockReq)); + LeavesToAdd.push_back(std::make_unique(&QueueImpl, MockReq)); } // Create edges: all soon-to-be leaves are direct users of MockDep std::vector ToCleanUp; diff --git a/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp b/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp index 9f6c0bd7691bb..4af81fd2da891 100644 --- a/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp +++ b/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp @@ -62,8 +62,8 @@ TEST_F(SchedulerTest, LeafLimitDiffContexts) { Rec, &MockReq, detail::getSyclObjImpl(Queue), ToEnqueue); std::ignore = MS.getOrCreateAllocaForReq(Rec, &MockReq, nullptr, ToEnqueue); - DepCmd = - std::make_unique(detail::getSyclObjImpl(Queue), MockReq); + DepCmd = std::make_unique( + detail::getSyclObjImpl(Queue).get(), MockReq); } }; @@ -85,7 +85,7 @@ TEST_F(SchedulerTest, LeafLimitDiffContexts) { auto AddLeafWithDeps = [&AddedLeaves, &MockReq, &MS](const QueueRelatedObjects &QueueStuff) { auto NewLeaf = std::make_unique( - detail::getSyclObjImpl(QueueStuff.Queue), MockReq); + detail::getSyclObjImpl(QueueStuff.Queue).get(), MockReq); // Create edges: all soon-to-be leaves are direct users of MockDep std::vector ToCleanUp; (void)NewLeaf->addDep(detail::DepDesc{QueueStuff.DepCmd.get(), &MockReq, diff --git a/sycl/unittests/scheduler/LeavesCollection.cpp b/sycl/unittests/scheduler/LeavesCollection.cpp index 5e17ac0b42334..712f3b3e4e66e 100644 --- a/sycl/unittests/scheduler/LeavesCollection.cpp +++ b/sycl/unittests/scheduler/LeavesCollection.cpp @@ -33,7 +33,7 @@ class LeavesCollectionTest : public ::testing::Test { std::shared_ptr createGenericCommand(const std::shared_ptr &Q) { - return std::shared_ptr{new MockCommand(Q, Command::RUN_CG)}; + return std::shared_ptr{new MockCommand(Q.get(), Command::RUN_CG)}; } std::shared_ptr createEmptyCommand(const Requirement &Req) { diff --git a/sycl/unittests/scheduler/MemObjCommandCleanup.cpp b/sycl/unittests/scheduler/MemObjCommandCleanup.cpp index 8bb44e68e1fe1..935c13a8beca9 100644 --- a/sycl/unittests/scheduler/MemObjCommandCleanup.cpp +++ b/sycl/unittests/scheduler/MemObjCommandCleanup.cpp @@ -18,6 +18,7 @@ using namespace sycl; TEST_F(SchedulerTest, MemObjCommandCleanupAllocaUsers) { sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); MockScheduler MS; buffer BufA(range<1>(1)); @@ -29,22 +30,22 @@ TEST_F(SchedulerTest, MemObjCommandCleanupAllocaUsers) { // Create 2 fake allocas, one of which will be cleaned up detail::AllocaCommand *MockAllocaA = - new detail::AllocaCommand(detail::getSyclObjImpl(Q), MockReqA); + new detail::AllocaCommand(&QueueImpl, MockReqA); std::unique_ptr MockAllocaB{ - new detail::AllocaCommand(detail::getSyclObjImpl(Q), MockReqB)}; + new detail::AllocaCommand(&QueueImpl, MockReqB)}; RecA->MAllocaCommands.push_back(MockAllocaA); // Create a direct user of both allocas std::unique_ptr MockDirectUser{ - new MockCommand(detail::getSyclObjImpl(Q), MockReqA)}; + new MockCommand(&QueueImpl, MockReqA)}; addEdge(MockDirectUser.get(), MockAllocaA, MockAllocaA); addEdge(MockDirectUser.get(), MockAllocaB.get(), MockAllocaB.get()); // Create an indirect user of the soon-to-be deleted alloca bool IndirectUserDeleted = false; std::function Callback = [&]() { IndirectUserDeleted = true; }; - MockCommand *MockIndirectUser = new MockCommandWithCallback( - detail::getSyclObjImpl(Q), MockReqA, Callback); + MockCommand *MockIndirectUser = + new MockCommandWithCallback(&QueueImpl, MockReqA, Callback); addEdge(MockIndirectUser, MockDirectUser.get(), MockAllocaA); MS.cleanupCommandsForRecord(RecA); @@ -61,6 +62,7 @@ TEST_F(SchedulerTest, MemObjCommandCleanupAllocaUsers) { TEST_F(SchedulerTest, MemObjCommandCleanupAllocaDeps) { sycl::unittest::UrMock<> Mock; sycl::queue Q{sycl::platform().get_devices()[0], MAsyncHandler}; + sycl::detail::queue_impl &QueueImpl = *detail::getSyclObjImpl(Q); MockScheduler MS; buffer Buf(range<1>(1)); @@ -70,11 +72,11 @@ TEST_F(SchedulerTest, MemObjCommandCleanupAllocaDeps) { // Create a fake alloca. detail::AllocaCommand *MockAllocaCmd = - new detail::AllocaCommand(detail::getSyclObjImpl(Q), MockReq); + new detail::AllocaCommand(&QueueImpl, MockReq); MemObjRec->MAllocaCommands.push_back(MockAllocaCmd); // Add another mock command and add MockAllocaCmd as its user. - MockCommand DepCmd(detail::getSyclObjImpl(Q), MockReq); + MockCommand DepCmd(&QueueImpl, MockReq); addEdge(MockAllocaCmd, &DepCmd, nullptr); // Check that DepCmd.MUsers size reflect the dependency properly. diff --git a/sycl/unittests/scheduler/QueueFlushing.cpp b/sycl/unittests/scheduler/QueueFlushing.cpp index 4d12148a14eec..ea03cc8d61474 100644 --- a/sycl/unittests/scheduler/QueueFlushing.cpp +++ b/sycl/unittests/scheduler/QueueFlushing.cpp @@ -46,10 +46,9 @@ static void resetTestCtx() { EventStatusQueried = false; } -static void addDepAndEnqueue(detail::Command *Cmd, - detail::QueueImplPtr &DepQueue, +static void addDepAndEnqueue(detail::Command *Cmd, detail::queue_impl &DepQueue, detail::Requirement &MockReq) { - MockCommand DepCmd(DepQueue); + MockCommand DepCmd(&DepQueue); std::vector ToCleanUp; ur_event_handle_t UREvent = mock::createDummyHandle(); @@ -62,7 +61,7 @@ static void addDepAndEnqueue(detail::Command *Cmd, } static void testCommandEnqueue(detail::Command *Cmd, - detail::QueueImplPtr &DepQueue, + detail::queue_impl &DepQueue, detail::Requirement &MockReq, bool ExpectedFlush = true) { resetTestCtx(); @@ -71,7 +70,7 @@ static void testCommandEnqueue(detail::Command *Cmd, } static void testEventStatusCheck(detail::Command *Cmd, - detail::QueueImplPtr &DepQueue, + detail::queue_impl &DepQueue, detail::Requirement &MockReq, ur_event_status_t ReturnedEventStatus) { resetTestCtx(); @@ -90,10 +89,10 @@ TEST_F(SchedulerTest, QueueFlushing) { context Ctx{Plt}; queue QueueA{Ctx, default_selector_v}; - detail::QueueImplPtr QueueImplA = detail::getSyclObjImpl(QueueA); + detail::queue_impl &QueueImplA = *detail::getSyclObjImpl(QueueA); queue QueueB{Ctx, default_selector_v}; - detail::QueueImplPtr QueueImplB = detail::getSyclObjImpl(QueueB); - ExpectedDepQueue = QueueImplB->getHandleRef(); + detail::queue_impl &QueueImplB = *detail::getSyclObjImpl(QueueB); + ExpectedDepQueue = QueueImplB.getHandleRef(); int val; buffer Buf(&val, range<1>(1)); @@ -101,7 +100,7 @@ TEST_F(SchedulerTest, QueueFlushing) { ur_mem_handle_t URBuf = mock::createDummyHandle(); - detail::AllocaCommand AllocaCmd = detail::AllocaCommand(QueueImplA, MockReq); + detail::AllocaCommand AllocaCmd = detail::AllocaCommand(&QueueImplA, MockReq); AllocaCmd.MMemAllocation = URBuf; void *MockHostPtr; detail::EnqueueResultT Res; @@ -109,23 +108,23 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that each of the non-blocking commands flush the dependency queue { - detail::MapMemObject MapCmd{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject MapCmd{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; testCommandEnqueue(&MapCmd, QueueImplB, MockReq); detail::UnMapMemObject UnmapCmd{&AllocaCmd, MockReq, &MockHostPtr, - QueueImplA}; + &QueueImplA}; testCommandEnqueue(&UnmapCmd, QueueImplB, MockReq); detail::AllocaCommand HostAllocaCmd = detail::AllocaCommand(nullptr, MockReq); - detail::MemCpyCommand MemCpyCmd{MockReq, &AllocaCmd, MockReq, - &HostAllocaCmd, QueueImplA, nullptr}; + detail::MemCpyCommand MemCpyCmd{MockReq, &AllocaCmd, MockReq, + &HostAllocaCmd, &QueueImplA, nullptr}; testCommandEnqueue(&MemCpyCmd, QueueImplB, MockReq); - detail::MemCpyCommandHost MemCpyCmdHost{MockReq, &AllocaCmd, MockReq, - &MockHostPtr, QueueImplA, nullptr}; + detail::MemCpyCommandHost MemCpyCmdHost{MockReq, &AllocaCmd, MockReq, + &MockHostPtr, &QueueImplA, nullptr}; testCommandEnqueue(&MemCpyCmdHost, QueueImplB, MockReq); std::unique_ptr CG{ @@ -136,7 +135,7 @@ TEST_F(SchedulerTest, QueueFlushing) { /*SharedPtrStorage*/ {}, /*Requirements*/ {}, /*Events*/ {}))}; - detail::ExecCGCommand ExecCGCmd{std::move(CG), QueueImplA, + detail::ExecCGCommand ExecCGCmd{std::move(CG), &QueueImplA, /*EventNeeded=*/true}; MockReq.MDims = 1; (void)ExecCGCmd.addDep(detail::DepDesc(&AllocaCmd, &MockReq, &AllocaCmd), @@ -147,11 +146,11 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check dependency event without a command { resetTestCtx(); - detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; std::shared_ptr DepEvent = - detail::event_impl::create_device_event(*QueueImplB); - DepEvent->setContextImpl(QueueImplB->getContextImplPtr()); + detail::event_impl::create_device_event(QueueImplB); + DepEvent->setContextImpl(QueueImplB.getContextImplPtr()); ur_event_handle_t UREvent = mock::createDummyHandle(); @@ -164,7 +163,7 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that flush isn't called for a released queue. { resetTestCtx(); - detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; std::shared_ptr DepEvent; { @@ -185,7 +184,7 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that same queue dependencies are not flushed { - detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; testCommandEnqueue(&Cmd, QueueImplA, MockReq, false); } @@ -193,15 +192,15 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that flush is not called twice for the same dependency queue { resetTestCtx(); - detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject Cmd = {&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; - MockCommand DepCmdA(QueueImplB); + MockCommand DepCmdA(&QueueImplB); ur_event_handle_t UREvent = mock::createDummyHandle(); DepCmdA.getEvent()->setHandle(UREvent); (void)Cmd.addDep(detail::DepDesc{&DepCmdA, &MockReq, nullptr}, ToCleanUp); - MockCommand DepCmdB(QueueImplB); + MockCommand DepCmdB(&QueueImplB); UREvent = mock::createDummyHandle(); @@ -214,9 +213,9 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that the event status isn't requested twice for the same event { resetTestCtx(); - detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; - MockCommand DepCmd(QueueImplB); + MockCommand DepCmd(&QueueImplB); ur_event_handle_t UREvent = mock::createDummyHandle(); @@ -225,7 +224,7 @@ TEST_F(SchedulerTest, QueueFlushing) { MockScheduler::enqueueCommand(&CmdA, Res, detail::NON_BLOCKING); EventStatusQueried = false; - detail::MapMemObject CmdB{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject CmdB{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; (void)CmdB.addDep(detail::DepDesc{&DepCmd, &MockReq, nullptr}, ToCleanUp); MockScheduler::enqueueCommand(&CmdB, Res, detail::NON_BLOCKING); @@ -234,13 +233,13 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that flush isn't called for submitted dependencies { - detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; testEventStatusCheck(&CmdA, QueueImplB, MockReq, UR_EVENT_STATUS_SUBMITTED); - detail::MapMemObject CmdB{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject CmdB{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; testEventStatusCheck(&CmdB, QueueImplB, MockReq, UR_EVENT_STATUS_RUNNING); - detail::MapMemObject CmdC{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject CmdC{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; testEventStatusCheck(&CmdC, QueueImplB, MockReq, UR_EVENT_STATUS_COMPLETE); } @@ -248,9 +247,9 @@ TEST_F(SchedulerTest, QueueFlushing) { // Check that nullptr UR event handles are handled correctly. { resetTestCtx(); - detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA, + detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, &QueueImplA, access::mode::read_write}; - MockCommand DepCmd(QueueImplB); + MockCommand DepCmd(&QueueImplB); (void)CmdA.addDep(detail::DepDesc{&DepCmd, &MockReq, nullptr}, ToCleanUp); MockScheduler::enqueueCommand(&CmdA, Res, detail::NON_BLOCKING); EXPECT_FALSE(EventStatusQueried); diff --git a/sycl/unittests/scheduler/SchedulerTestUtils.hpp b/sycl/unittests/scheduler/SchedulerTestUtils.hpp index e9f74ac6e83ab..0acbcc119e290 100644 --- a/sycl/unittests/scheduler/SchedulerTestUtils.hpp +++ b/sycl/unittests/scheduler/SchedulerTestUtils.hpp @@ -35,7 +35,7 @@ class Command; class MockCommand : public sycl::detail::Command { public: MockCommand( - sycl::detail::QueueImplPtr Queue, sycl::detail::Requirement Req, + sycl::detail::queue_impl *Queue, sycl::detail::Requirement Req, sycl::detail::Command::CommandType Type = sycl::detail::Command::RUN_CG) : Command{Type, Queue}, MRequirement{std::move(Req)} { using namespace testing; @@ -45,7 +45,7 @@ class MockCommand : public sycl::detail::Command { } MockCommand( - sycl::detail::QueueImplPtr Queue, + sycl::detail::queue_impl *Queue, sycl::detail::Command::CommandType Type = sycl::detail::Command::RUN_CG) : Command{Type, Queue}, MRequirement{std::move(getMockRequirement())} { using namespace testing; @@ -78,7 +78,7 @@ class MockCommand : public sycl::detail::Command { std::shared_ptr Queue, std::vector> &RawEvents, ur_event_handle_t &Event) { - Command::waitForEvents(Queue, RawEvents, Event); + Command::waitForEvents(Queue.get(), RawEvents, Event); } std::shared_ptr getEvent() { return MEvent; } @@ -89,7 +89,7 @@ class MockCommand : public sycl::detail::Command { class MockCommandWithCallback : public MockCommand { public: - MockCommandWithCallback(sycl::detail::QueueImplPtr Queue, + MockCommandWithCallback(sycl::detail::queue_impl *Queue, sycl::detail::Requirement Req, std::function Callback) : MockCommand(Queue, Req), MCallback(std::move(Callback)) {} @@ -313,8 +313,9 @@ class MockHandlerCustomFinalize : public MockHandler { } case sycl::detail::CGType::CodeplayHostTask: { CommandGroup.reset(new sycl::detail::CGHostTask( - std::move(getHostTask()), getQueue(), getQueue()->getContextImplPtr(), - getArgs(), std::move(CGData), getType(), getCodeLoc())); + std::move(getHostTask()), getQueue().get(), + getQueue()->getContextImplPtr(), getArgs(), std::move(CGData), + getType(), getCodeLoc())); break; } default: