@@ -190,9 +190,10 @@ MemObjRecord *Scheduler::GraphBuilder::getOrInsertMemObjRecord(
190
190
DepDesc Dep = findDepForRecord (Dependant, Record);
191
191
Dep.MDepCommand = Dependency;
192
192
std::vector<Command *> ToCleanUp;
193
- if (Command *ConnectionCmd = Dependant->addDep (Dep, ToCleanUp))
193
+ Command *ConnectionCmd = Dependant->addDep (Dep, ToCleanUp);
194
+ if (ConnectionCmd)
194
195
ToEnqueue.push_back (ConnectionCmd);
195
- Dependency-> addUser (Dependant);
196
+
196
197
--(Dependency->MLeafCounter );
197
198
if (Dependency->MLeafCounter == 0 &&
198
199
Dependency->isSuccessfullyEnqueued () &&
@@ -281,7 +282,6 @@ UpdateHostRequirementCommand *Scheduler::GraphBuilder::insertUpdateHostReqCmd(
281
282
UpdateCommand->addDep (DepDesc{Dep, StoredReq, AllocaCmd}, ToCleanUp);
282
283
if (ConnCmd)
283
284
ToEnqueue.push_back (ConnCmd);
284
- Dep->addUser (UpdateCommand);
285
285
}
286
286
updateLeaves (Deps, Record, Req->MAccessMode , ToCleanUp);
287
287
addNodeToLeaves (Record, UpdateCommand, Req->MAccessMode , ToEnqueue);
@@ -397,7 +397,6 @@ Command *Scheduler::GraphBuilder::insertMemoryMove(
397
397
DepDesc{Dep, NewCmd->getRequirement (), AllocaCmdDst}, ToCleanUp);
398
398
if (ConnCmd)
399
399
ToEnqueue.push_back (ConnCmd);
400
- Dep->addUser (NewCmd);
401
400
}
402
401
updateLeaves (Deps, Record, access::mode::read_write, ToCleanUp);
403
402
addNodeToLeaves (Record, NewCmd, access::mode::read_write, ToEnqueue);
@@ -437,14 +436,12 @@ Command *Scheduler::GraphBuilder::remapMemoryObject(
437
436
DepDesc{Dep, UnMapCmd->getRequirement (), LinkedAllocaCmd}, ToCleanUp);
438
437
if (ConnCmd)
439
438
ToEnqueue.push_back (ConnCmd);
440
- Dep->addUser (UnMapCmd);
441
439
}
442
440
443
441
Command *ConnCmd = MapCmd->addDep (
444
442
DepDesc{UnMapCmd, MapCmd->getRequirement (), HostAllocaCmd}, ToCleanUp);
445
443
if (ConnCmd)
446
444
ToEnqueue.push_back (ConnCmd);
447
- UnMapCmd->addUser (MapCmd);
448
445
449
446
updateLeaves (Deps, Record, access::mode::read_write, ToCleanUp);
450
447
addNodeToLeaves (Record, MapCmd, access::mode::read_write, ToEnqueue);
@@ -489,7 +486,6 @@ Scheduler::GraphBuilder::addCopyBack(Requirement *Req,
489
486
DepDesc{Dep, MemCpyCmd->getRequirement (), SrcAllocaCmd}, ToCleanUp);
490
487
if (ConnCmd)
491
488
ToEnqueue.push_back (ConnCmd);
492
- Dep->addUser (MemCpyCmd);
493
489
}
494
490
495
491
updateLeaves (Deps, Record, Req->MAccessMode , ToCleanUp);
@@ -780,7 +776,6 @@ AllocaCommandBase *Scheduler::GraphBuilder::getOrCreateAllocaForReq(
780
776
ToCleanUp);
781
777
if (ConnCmd)
782
778
ToEnqueue.push_back (ConnCmd);
783
- LinkedAllocaCmd->addUser (AllocaCmd);
784
779
LinkedAllocaCmd->MLinkedAllocaCmd = AllocaCmd;
785
780
786
781
// To ensure that the leader allocation is removed first
@@ -808,7 +803,6 @@ AllocaCommandBase *Scheduler::GraphBuilder::getOrCreateAllocaForReq(
808
803
DepDesc{Dep, Req, LinkedAllocaCmd}, ToCleanUp);
809
804
if (ConnCmd)
810
805
ToEnqueue.push_back (ConnCmd);
811
- Dep->addUser (AllocaCmd);
812
806
}
813
807
updateLeaves (Deps, Record, Req->MAccessMode , ToCleanUp);
814
808
addNodeToLeaves (Record, AllocaCmd, Req->MAccessMode , ToEnqueue);
@@ -848,7 +842,8 @@ typename detail::enable_if_t<
848
842
Scheduler::GraphBuilder::addEmptyCmd (Command *Cmd, const std::vector<T *> &Reqs,
849
843
const QueueImplPtr &Queue,
850
844
Command::BlockReason Reason,
851
- std::vector<Command *> &ToEnqueue) {
845
+ std::vector<Command *> &ToEnqueue,
846
+ const bool AddDepsToLeaves) {
852
847
EmptyCommand *EmptyCmd =
853
848
new EmptyCommand (Scheduler::getInstance ().getDefaultHostQueue ());
854
849
@@ -865,20 +860,24 @@ Scheduler::GraphBuilder::addEmptyCmd(Command *Cmd, const std::vector<T *> &Reqs,
865
860
getOrCreateAllocaForReq (Record, Req, Queue, ToEnqueue);
866
861
EmptyCmd->addRequirement (Cmd, AllocaCmd, Req);
867
862
}
863
+ // addRequirement above call addDep that already will add EmptyCmd as user for
864
+ // Cmd no Reqs size check here so assume it is possible to have no Reqs passed
865
+ if (!Reqs.size ())
866
+ Cmd->addUser (EmptyCmd);
868
867
869
- Cmd->addUser (EmptyCmd);
870
-
871
- const std::vector<DepDesc> &Deps = Cmd->MDeps ;
872
- std::vector<Command *> ToCleanUp;
873
- for (const DepDesc &Dep : Deps) {
874
- const Requirement *Req = Dep.MDepRequirement ;
875
- MemObjRecord *Record = getMemObjRecord (Req->MSYCLMemObj );
868
+ if (AddDepsToLeaves) {
869
+ const std::vector<DepDesc> &Deps = Cmd->MDeps ;
870
+ std::vector<Command *> ToCleanUp;
871
+ for (const DepDesc &Dep : Deps) {
872
+ const Requirement *Req = Dep.MDepRequirement ;
873
+ MemObjRecord *Record = getMemObjRecord (Req->MSYCLMemObj );
876
874
877
- updateLeaves ({Cmd}, Record, Req->MAccessMode , ToCleanUp);
878
- addNodeToLeaves (Record, EmptyCmd, Req->MAccessMode , ToEnqueue);
875
+ updateLeaves ({Cmd}, Record, Req->MAccessMode , ToCleanUp);
876
+ addNodeToLeaves (Record, EmptyCmd, Req->MAccessMode , ToEnqueue);
877
+ }
878
+ for (Command *Cmd : ToCleanUp)
879
+ cleanupCommand (Cmd);
879
880
}
880
- for (Command *Cmd : ToCleanUp)
881
- cleanupCommand (Cmd);
882
881
883
882
return EmptyCmd;
884
883
}
@@ -989,10 +988,12 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr<detail::CG> CommandGroup,
989
988
std::set<Command *> Deps =
990
989
findDepsForReq (Record, Req, Queue->getContextImplPtr ());
991
990
992
- for (Command *Dep : Deps)
993
- if (Command *ConnCmd =
994
- NewCmd->addDep (DepDesc{Dep, Req, AllocaCmd}, ToCleanUp))
991
+ for (Command *Dep : Deps) {
992
+ Command *ConnCmd =
993
+ NewCmd->addDep (DepDesc{Dep, Req, AllocaCmd}, ToCleanUp);
994
+ if (ConnCmd)
995
995
ToEnqueue.push_back (ConnCmd);
996
+ }
996
997
}
997
998
998
999
// Set new command as user for dependencies and update leaves.
@@ -1001,7 +1002,6 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr<detail::CG> CommandGroup,
1001
1002
// FIXME employ a reference here to eliminate copying of a vector
1002
1003
std::vector<DepDesc> Deps = NewCmd->MDeps ;
1003
1004
for (DepDesc &Dep : Deps) {
1004
- Dep.MDepCommand ->addUser (NewCmd.get ());
1005
1005
const Requirement *Req = Dep.MDepRequirement ;
1006
1006
MemObjRecord *Record = getMemObjRecord (Req->MSYCLMemObj );
1007
1007
updateLeaves ({Dep.MDepCommand }, Record, Req->MAccessMode , ToCleanUp);
@@ -1297,9 +1297,6 @@ Command *Scheduler::GraphBuilder::connectDepEvent(
1297
1297
throw runtime_error (" Out of host memory" , PI_OUT_OF_HOST_MEMORY);
1298
1298
}
1299
1299
1300
- if (Command *DepCmd = reinterpret_cast <Command *>(DepEvent->getCommand ()))
1301
- DepCmd->addUser (ConnectCmd);
1302
-
1303
1300
EmptyCommand *EmptyCmd = nullptr ;
1304
1301
1305
1302
if (Dep.MDepRequirement ) {
@@ -1311,21 +1308,17 @@ Command *Scheduler::GraphBuilder::connectDepEvent(
1311
1308
Dep.MDepCommand );
1312
1309
// add user to Dep.MDepCommand is already performed beyond this if branch
1313
1310
1314
- MemObjRecord *Record = getMemObjRecord (Dep.MDepRequirement ->MSYCLMemObj );
1315
- updateLeaves ({Dep.MDepCommand }, Record, Dep.MDepRequirement ->MAccessMode ,
1316
- ToCleanUp);
1311
+ // ConnectCmd is added as dependency to Cmd
1312
+ // We build the following structure Cmd->EmptyCmd/ConnectCmd->DepCmd
1313
+ // No need to add ConnectCmd to leaves buffer since it is a dependency
1314
+ // for command Cmd that will be added there
1317
1315
1318
1316
std::vector<Command *> ToEnqueue;
1319
- addNodeToLeaves (Record, ConnectCmd, Dep.MDepRequirement ->MAccessMode ,
1320
- ToEnqueue);
1321
- assert (ToEnqueue.size () == 0 );
1322
-
1323
1317
const std::vector<const Requirement *> Reqs (1 , Dep.MDepRequirement );
1324
1318
EmptyCmd = addEmptyCmd (ConnectCmd, Reqs,
1325
1319
Scheduler::getInstance ().getDefaultHostQueue (),
1326
- Command::BlockReason::HostTask, ToEnqueue);
1320
+ Command::BlockReason::HostTask, ToEnqueue, false );
1327
1321
assert (ToEnqueue.size () == 0 );
1328
- // Dependencies for EmptyCmd are set in addEmptyCmd for provided Reqs.
1329
1322
1330
1323
// Depend Cmd on empty command
1331
1324
{
@@ -1337,6 +1330,11 @@ Command *Scheduler::GraphBuilder::connectDepEvent(
1337
1330
(void )Cmd->addDep (CmdDep, ToCleanUp);
1338
1331
}
1339
1332
} else {
1333
+ // It is required condition in another a path and addUser will be set in
1334
+ // addDep
1335
+ if (Command *DepCmd = reinterpret_cast <Command *>(DepEvent->getCommand ()))
1336
+ DepCmd->addUser (ConnectCmd);
1337
+
1340
1338
std::vector<Command *> ToEnqueue;
1341
1339
EmptyCmd = addEmptyCmd<Requirement>(
1342
1340
ConnectCmd, {}, Scheduler::getInstance ().getDefaultHostQueue (),
@@ -1354,10 +1352,10 @@ Command *Scheduler::GraphBuilder::connectDepEvent(
1354
1352
// Dismiss the result here as it's not a connection now,
1355
1353
// 'cause EmptyCmd is host one
1356
1354
(void )Cmd->addDep (EmptyCmd->getEvent (), ToCleanUp);
1355
+ // Added by addDep in another path
1356
+ EmptyCmd->addUser (Cmd);
1357
1357
}
1358
1358
1359
- EmptyCmd->addUser (Cmd);
1360
-
1361
1359
ConnectCmd->MEmptyCmd = EmptyCmd;
1362
1360
1363
1361
return ConnectCmd;
0 commit comments