Skip to content

[SYCL] Fix case when host-task is used for queue with reused context #2829

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 4 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep) {

// 1. Async work is not supported for host device.
// 2. The event handle can be null in case of, for example, alloca command,
// which is currently synchrounious, so don't generate OpenCL event.
// which is currently synchronous, so don't generate OpenCL event.
// Though, this event isn't host one as it's context isn't host one.
if (DepEvent->is_host() || DepEvent->getHandleRef() == nullptr) {
// call to waitInternal() is in waitForPreparedHostEvents() as it's called
Expand Down Expand Up @@ -2039,7 +2039,8 @@ cl_int ExecCGCommand::enqueueImp() {
Req->MSYCLMemObj->MRecord->MAllocaCommands;

for (AllocaCommandBase *AllocaCmd : AllocaCmds)
if (HostTask->MQueue == AllocaCmd->getQueue()) {
if (HostTask->MQueue->getContextImplPtr() ==
AllocaCmd->getQueue()->getContextImplPtr()) {
auto MemArg =
reinterpret_cast<pi_mem>(AllocaCmd->getMemAllocation());
ReqToMem.emplace_back(std::make_pair(Req, MemArg));
Expand Down
41 changes: 41 additions & 0 deletions sycl/test/on-device/host-interop-task/interop-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,46 @@ void test2() {
}
}

// Same as above but with queue constructed out of context
void test2_1() {
static constexpr int COUNT = 4;
buffer<int, 1> Buffer1{BUFFER_SIZE};
buffer<int, 1> Buffer2{BUFFER_SIZE};

auto Device = default_selector().select_device();
auto Context = context(Device);
// init the buffer with a'priori invalid data
{
queue Q(Context, Device);
init<int, -1, -2>(Buffer1, Buffer2, Q);
}

// Repeat a couple of times
for (size_t Idx = 0; Idx < COUNT; ++Idx) {
queue Q(Context, Device);
copy(Buffer1, Buffer2, Q);
modify(Buffer2, Q);
copy(Buffer2, Buffer1, Q);
}

{
auto Acc = Buffer1.get_access<mode::read>();

for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) {
std::cout << "First buffer [" << Idx << "] = " << Acc[Idx] << std::endl;
assert((Acc[Idx] == COUNT - 1) && "Invalid data in the first buffer");
}
}
{
auto Acc = Buffer2.get_access<mode::read>();

for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) {
std::cout << "Second buffer [" << Idx << "] = " << Acc[Idx] << std::endl;
assert((Acc[Idx] == COUNT - 1) && "Invalid data in the second buffer");
}
}
}

// A test that does a clEnqueueWait inside the interop scope, for an event
// captured outside the command group. The OpenCL event can be set after the
// command group finishes. Must not deadlock according to implementation and
Expand Down Expand Up @@ -251,6 +291,7 @@ void test6() {
int main() {
test1();
test2();
test2_1();
test3();
test4();
test5();
Expand Down