Skip to content

Commit 9cff6c9

Browse files
authored
[SYCL] Fix case when host-task is used for queue with reused context (#2829)
1 parent 930710e commit 9cff6c9

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

sycl/source/detail/scheduler/commands.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep) {
485485

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

20412041
for (AllocaCommandBase *AllocaCmd : AllocaCmds)
2042-
if (HostTask->MQueue == AllocaCmd->getQueue()) {
2042+
if (HostTask->MQueue->getContextImplPtr() ==
2043+
AllocaCmd->getQueue()->getContextImplPtr()) {
20432044
auto MemArg =
20442045
reinterpret_cast<pi_mem>(AllocaCmd->getMemAllocation());
20452046
ReqToMem.emplace_back(std::make_pair(Req, MemArg));

sycl/test/on-device/host-interop-task/interop-task.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,46 @@ void test2() {
150150
}
151151
}
152152

153+
// Same as above but with queue constructed out of context
154+
void test2_1() {
155+
static constexpr int COUNT = 4;
156+
buffer<int, 1> Buffer1{BUFFER_SIZE};
157+
buffer<int, 1> Buffer2{BUFFER_SIZE};
158+
159+
auto Device = default_selector().select_device();
160+
auto Context = context(Device);
161+
// init the buffer with a'priori invalid data
162+
{
163+
queue Q(Context, Device);
164+
init<int, -1, -2>(Buffer1, Buffer2, Q);
165+
}
166+
167+
// Repeat a couple of times
168+
for (size_t Idx = 0; Idx < COUNT; ++Idx) {
169+
queue Q(Context, Device);
170+
copy(Buffer1, Buffer2, Q);
171+
modify(Buffer2, Q);
172+
copy(Buffer2, Buffer1, Q);
173+
}
174+
175+
{
176+
auto Acc = Buffer1.get_access<mode::read>();
177+
178+
for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) {
179+
std::cout << "First buffer [" << Idx << "] = " << Acc[Idx] << std::endl;
180+
assert((Acc[Idx] == COUNT - 1) && "Invalid data in the first buffer");
181+
}
182+
}
183+
{
184+
auto Acc = Buffer2.get_access<mode::read>();
185+
186+
for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) {
187+
std::cout << "Second buffer [" << Idx << "] = " << Acc[Idx] << std::endl;
188+
assert((Acc[Idx] == COUNT - 1) && "Invalid data in the second buffer");
189+
}
190+
}
191+
}
192+
153193
// A test that does a clEnqueueWait inside the interop scope, for an event
154194
// captured outside the command group. The OpenCL event can be set after the
155195
// command group finishes. Must not deadlock according to implementation and
@@ -251,6 +291,7 @@ void test6() {
251291
int main() {
252292
test1();
253293
test2();
294+
test2_1();
254295
test3();
255296
test4();
256297
test5();

0 commit comments

Comments
 (0)