Skip to content

Commit 2fd74a7

Browse files
committed
[SYCL] Fix bug with not found alloca command.
Fix bug with not found alloca in case of two accessors are created for the same memory object. The problem is that during searching for dependencies for the first accessor list of leaf command is modified so it doesn't contain commands that are considered as dependencies. As a result search for dependencies for the second accessor fails. The fix is to update list of leafs after dependencies for all accessors are found. Signed-off-by: Vlad Romanov <[email protected]>
1 parent c368605 commit 2fd74a7

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,21 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr<detail::CG> CommandGroup,
379379
break;
380380
}
381381
AllocaCommand *AllocaCmd = findAllocaForReq(Record, Req, Queue);
382-
UpdateLeafs(Deps, Record, Req);
383382

384383
for (Command *Dep : Deps) {
385384
NewCmd->addDep(DepDesc{Dep, Req, AllocaCmd});
386-
Dep->addUser(NewCmd.get());
387385
}
388386
}
389387

390-
for (Requirement *Req : Reqs) {
388+
// Set new command as user for dependencies and update leafs.
389+
for (DepDesc &Dep : NewCmd->MDeps) {
390+
Dep.MDepCommand->addUser(NewCmd.get());
391+
Requirement *Req = Dep.MReq;
391392
MemObjRecord *Record = getMemObjRecord(Req->MSYCLMemObj);
393+
UpdateLeafs({Dep.MDepCommand}, Record, Req);
392394
AddNodeToLeafs(Record, NewCmd.get(), Req);
393395
}
396+
394397
return NewCmd.release();
395398
}
396399

sycl/test/basic_tests/accessor/accessor.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,30 @@ int main() {
329329
}
330330
}
331331
}
332+
333+
// Two accessors to the same buffer.
334+
{
335+
try {
336+
sycl::queue queue;
337+
int array[3] = {1, 1, 1};
338+
sycl::buffer<int, 1> buf(array, sycl::range<1>(3));
339+
340+
queue.submit([&](sycl::handler& cgh) {
341+
auto acc1 = buf.get_access<sycl::access::mode::read>(cgh);
342+
auto acc2 = buf.get_access<sycl::access::mode::read_write>(cgh);
343+
344+
cgh.parallel_for<class two_accessors_to_buf>(
345+
sycl::range<1>{3},
346+
[=](sycl::id<1> index) { acc2[index] = 41 + acc1[index]; });
347+
});
348+
349+
auto host_acc = buf.get_access<sycl::access::mode::read>();
350+
for (int i = 0; i != 3; ++i)
351+
assert(host_acc[i] == 42);
352+
353+
} catch (cl::sycl::exception e) {
354+
std::cout << "SYCL exception caught: " << e.what();
355+
return 1;
356+
}
357+
}
332358
}

0 commit comments

Comments
 (0)