Skip to content

Commit 08dceea

Browse files
[SYCL] Fix undefined behaviour during graph cleanup
With the switch to using the command member field to mark nodes as visited during graph traversal, deleting nodes during the traversal leads to invalid memory access whenever there's a node with multiple indirect dependencies on another node. This patch fixes the issue by moving the deletion of the nodes to take place post-traversal.
1 parent 2fb2468 commit 08dceea

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ void Scheduler::GraphBuilder::cleanupCommandsForRecord(MemObjRecord *Record) {
911911

912912
void Scheduler::GraphBuilder::cleanupFinishedCommands(Command *FinishedCmd) {
913913
std::queue<Command *> CmdsToVisit({FinishedCmd});
914+
std::vector<Command *> CmdsToDelete;
914915
std::vector<Command *> Visited;
915916

916917
// Traverse the graph using BFS
@@ -948,12 +949,16 @@ void Scheduler::GraphBuilder::cleanupFinishedCommands(Command *FinishedCmd) {
948949
Command *DepCmd = Dep.MDepCommand;
949950
DepCmd->MUsers.erase(Cmd);
950951
}
951-
Cmd->getEvent()->setCommand(nullptr);
952952

953+
CmdsToDelete.push_back(Cmd);
953954
Visited.pop_back();
954-
delete Cmd;
955955
}
956956
unmarkVisitedNodes(Visited);
957+
958+
for (Command *Cmd : CmdsToDelete) {
959+
Cmd->getEvent()->setCommand(nullptr);
960+
delete Cmd;
961+
}
957962
}
958963

959964
void Scheduler::GraphBuilder::removeRecordForMemObj(SYCLMemObjI *MemObject) {

0 commit comments

Comments
 (0)