Skip to content

[SYCL] Split read/write lockings #2292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class DispatchHostTask {
// Thus we employ read-lock of graph.
{
Scheduler &Sched = Scheduler::getInstance();
std::shared_lock<std::shared_timed_mutex> Lock(Sched.MGraphLock);
Scheduler::ReadLockT Lock(Sched.MGraphLock);

std::vector<DepDesc> Deps = MThisCmd->MDeps;

Expand Down Expand Up @@ -481,7 +481,7 @@ void Command::makeTraceEventEpilog() {
#endif
}

void Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep) {
Command *Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep) {
const QueueImplPtr &WorkerQueue = getWorkerQueue();
const ContextImplPtr &WorkerContext = WorkerQueue->getContextImplPtr();

Expand All @@ -493,21 +493,25 @@ void Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep) {
// call to waitInternal() is in waitForPreparedHostEvents() as it's called
// from enqueue process functions
MPreparedHostDepsEvents.push_back(DepEvent);
return;
return nullptr;
}

Command *ConnectionCmd = nullptr;

// Do not add redundant event dependencies for in-order queues.
if (Dep.MDepCommand && Dep.MDepCommand->getWorkerQueue() == WorkerQueue &&
WorkerQueue->has_property<property::queue::in_order>())
return;
return nullptr;

ContextImplPtr DepEventContext = DepEvent->getContextImpl();
// If contexts don't match we'll connect them using host task
if (DepEventContext != WorkerContext && !WorkerContext->is_host()) {
Scheduler::GraphBuilder &GB = Scheduler::getInstance().MGraphBuilder;
GB.connectDepEvent(this, DepEvent, Dep);
ConnectionCmd = GB.connectDepEvent(this, DepEvent, Dep);
} else
MPreparedDepsEvents.push_back(std::move(DepEvent));

return ConnectionCmd;
}

const ContextImplPtr &Command::getWorkerContext() const {
Expand All @@ -516,19 +520,23 @@ const ContextImplPtr &Command::getWorkerContext() const {

const QueueImplPtr &Command::getWorkerQueue() const { return MQueue; }

void Command::addDep(DepDesc NewDep) {
Command *Command::addDep(DepDesc NewDep) {
Command *ConnectionCmd = nullptr;

if (NewDep.MDepCommand) {
processDepEvent(NewDep.MDepCommand->getEvent(), NewDep);
ConnectionCmd = processDepEvent(NewDep.MDepCommand->getEvent(), NewDep);
}
MDeps.push_back(NewDep);
#ifdef XPTI_ENABLE_INSTRUMENTATION
emitEdgeEventForCommandDependence(
NewDep.MDepCommand, (void *)NewDep.MDepRequirement->MSYCLMemObj,
accessModeToString(NewDep.MDepRequirement->MAccessMode), true);
#endif

return ConnectionCmd;
}

void Command::addDep(EventImplPtr Event) {
Command *Command::addDep(EventImplPtr Event) {
#ifdef XPTI_ENABLE_INSTRUMENTATION
// We need this for just the instrumentation, so guarding it will prevent
// unused variable warnings when instrumentation is turned off
Expand All @@ -538,7 +546,7 @@ void Command::addDep(EventImplPtr Event) {
emitEdgeEventForEventDependence(Cmd, PiEventAddr);
#endif

processDepEvent(std::move(Event), DepDesc{nullptr, nullptr, nullptr});
return processDepEvent(std::move(Event), DepDesc{nullptr, nullptr, nullptr});
}

void Command::emitEnqueuedEventSignal(RT::PiEvent &PiEventAddr) {
Expand Down Expand Up @@ -732,7 +740,10 @@ AllocaCommand::AllocaCommand(QueueImplPtr Queue, Requirement Req,
// Node event must be created before the dependent edge is added to this node,
// so this call must be before the addDep() call.
emitInstrumentationDataProxy();
addDep(DepDesc(nullptr, getRequirement(), this));
// "Nothing to depend on"
Command *ConnectionCmd = addDep(DepDesc(nullptr, getRequirement(), this));
assert(ConnectionCmd == nullptr);
(void)ConnectionCmd;
}

void AllocaCommand::emitInstrumentationData() {
Expand Down Expand Up @@ -795,7 +806,8 @@ void AllocaCommand::printDot(std::ostream &Stream) const {
}

AllocaSubBufCommand::AllocaSubBufCommand(QueueImplPtr Queue, Requirement Req,
AllocaCommandBase *ParentAlloca)
AllocaCommandBase *ParentAlloca,
std::vector<Command *> &ToEnqueue)
: AllocaCommandBase(CommandType::ALLOCA_SUB_BUF, std::move(Queue),
std::move(Req),
/*LinkedAllocaCmd*/ nullptr),
Expand All @@ -804,7 +816,10 @@ AllocaSubBufCommand::AllocaSubBufCommand(QueueImplPtr Queue, Requirement Req,
// is added to this node, so this call must be before
// the addDep() call.
emitInstrumentationDataProxy();
addDep(DepDesc(MParentAlloca, getRequirement(), MParentAlloca));
Command *ConnectionCmd =
addDep(DepDesc(MParentAlloca, getRequirement(), MParentAlloca));
if (ConnectionCmd)
ToEnqueue.push_back(ConnectionCmd);
}

void AllocaSubBufCommand::emitInstrumentationData() {
Expand Down Expand Up @@ -1329,7 +1344,10 @@ void EmptyCommand::addRequirement(Command *DepCmd, AllocaCommandBase *AllocaCmd,
MRequirements.emplace_back(ReqRef);
const Requirement *const StoredReq = &MRequirements.back();

addDep(DepDesc{DepCmd, StoredReq, AllocaCmd});
// EmptyCommand is always host one, so we believe that result of addDep is nil
Command *Cmd = addDep(DepDesc{DepCmd, StoredReq, AllocaCmd});
assert(Cmd == nullptr && "Conection command should be null for EmptyCommand");
(void)Cmd;
}

void EmptyCommand::emitInstrumentationData() {
Expand Down
13 changes: 9 additions & 4 deletions sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ class Command {

Command(CommandType Type, QueueImplPtr Queue);

void addDep(DepDesc NewDep);
/// \return an optional connection cmd to enqueue
[[nodiscard]] Command *addDep(DepDesc NewDep);

void addDep(EventImplPtr Event);
/// \return an optional connection cmd to enqueue
[[nodiscard]] Command *addDep(EventImplPtr Event);

void addUser(Command *NewUser) { MUsers.insert(NewUser); }

Expand Down Expand Up @@ -204,13 +206,15 @@ class Command {
/// Perform glueing of events from different contexts
/// \param DepEvent event this commands should depend on
/// \param Dep optional DepDesc to perform connection of events properly
/// \return returns an optional connection command to enqueue
///
/// Glueing (i.e. connecting) will be performed if and only if DepEvent is
/// not from host context and its context doesn't match to context of this
/// command. Context of this command is fetched via getWorkerContext().
///
/// Optionality of Dep is set by Dep.MDepCommand not equal to nullptr.
void processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep);
[[nodiscard]] Command *processDepEvent(EventImplPtr DepEvent,
const DepDesc &Dep);

/// Private interface. Derived classes should implement this method.
virtual cl_int enqueueImp() = 0;
Expand Down Expand Up @@ -387,7 +391,8 @@ class AllocaCommand : public AllocaCommandBase {
class AllocaSubBufCommand : public AllocaCommandBase {
public:
AllocaSubBufCommand(QueueImplPtr Queue, Requirement Req,
AllocaCommandBase *ParentAlloca);
AllocaCommandBase *ParentAlloca,
std::vector<Command *> &ToEnqueue);

void *getMemAllocation() const final;
void printDot(std::ostream &Stream) const final;
Expand Down
Loading