Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 2 additions & 6 deletions SYCL/Basic/accessor/Inputs/host_task_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ int main() {

#if defined(accessor_new_api_test) || defined(buffer_new_api_test)
cgh.host_task([=]() {
#else
cgh.codeplay_host_task([=]() {
#endif
acc_7[6] = acc_1[0];
acc_8[7] = acc_2[1];
acc_9[7] = acc_3[1];
Expand All @@ -65,6 +62,7 @@ int main() {
acc_3[1] = acc_6[4];
});
});
#endif
Queue.wait();

#if defined(accessor_new_api_test)
Expand Down Expand Up @@ -115,16 +113,14 @@ int main() {

#if defined(accessor_new_api_test) || defined(buffer_new_api_test)
cgh.host_task([=]() {
#else
cgh.codeplay_host_task([=]() {
#endif
acc_7[6] = acc_1[0];
acc_8[7] = acc_2[1];
acc_9[7] = acc_3[1];
acc_1[0] = 4;
acc_2[1] = 5;
acc_3[1] = 6;
});
#endif
});
Queue.wait();

Expand Down
78 changes: 32 additions & 46 deletions SYCL/HostInteropTask/interop-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void checkBufferValues(BufferT Buffer, ValueT Value) {
}
}

template <bool UseSYCL2020HostTask, typename DataT>
template <typename DataT>
void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
Q.submit([&](handler &CGH) {
auto SrcA = Src.template get_access<mode::read>(CGH);
Expand Down Expand Up @@ -61,10 +61,7 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
"interop_handle::get_backend() returned a wrong value",
CL_INVALID_VALUE);
};
if constexpr (UseSYCL2020HostTask)
CGH.host_task(Func);
else
CGH.codeplay_host_task(Func);
CGH.host_task(Func);
});
}

Expand Down Expand Up @@ -96,7 +93,7 @@ void init(buffer<DataT, 1> &B1, buffer<DataT, 1> &B2, queue &Q) {
// kernel that modifies the data in place for B, e.g. increment one, then copy
// back to buffer A. Run it on a loop, to ensure the dependencies and the
// reference counting of the objects is not leaked.
template <bool UseSYCL2020HostTask> void test1(queue &Q) {
void test1(queue &Q) {
static constexpr int COUNT = 4;
buffer<int, 1> Buffer1{BUFFER_SIZE};
buffer<int, 1> Buffer2{BUFFER_SIZE};
Expand All @@ -106,9 +103,9 @@ template <bool UseSYCL2020HostTask> void test1(queue &Q) {

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

checkBufferValues(Buffer1, COUNT - 1);
Expand All @@ -118,7 +115,7 @@ template <bool UseSYCL2020HostTask> void test1(queue &Q) {
// Same as above, but performing each command group on a separate SYCL queue
// (on the same or different devices). This ensures the dependency tracking
// works well but also there is no accidental side effects on other queues.
template <bool UseSYCL2020HostTask> void test2(queue &Q) {
void test2(queue &Q) {
static constexpr int COUNT = 4;
buffer<int, 1> Buffer1{BUFFER_SIZE};
buffer<int, 1> Buffer2{BUFFER_SIZE};
Expand All @@ -128,16 +125,16 @@ template <bool UseSYCL2020HostTask> void test2(queue &Q) {

// Repeat a couple of times
for (size_t Idx = 0; Idx < COUNT; ++Idx) {
copy<UseSYCL2020HostTask>(Buffer1, Buffer2, Q);
copy(Buffer1, Buffer2, Q);
modify(Buffer2, Q);
copy<UseSYCL2020HostTask>(Buffer2, Buffer1, Q);
copy(Buffer2, Buffer1, Q);
}
checkBufferValues(Buffer1, COUNT - 1);
checkBufferValues(Buffer2, COUNT - 1);
}

// Same as above but with queue constructed out of context
template <bool UseSYCL2020HostTask> void test2_1(queue &Q) {
void test2_1(queue &Q) {
static constexpr int COUNT = 4;
buffer<int, 1> Buffer1{BUFFER_SIZE};
buffer<int, 1> Buffer2{BUFFER_SIZE};
Expand All @@ -149,9 +146,9 @@ template <bool UseSYCL2020HostTask> void test2_1(queue &Q) {

// Repeat a couple of times
for (size_t Idx = 0; Idx < COUNT; ++Idx) {
copy<UseSYCL2020HostTask>(Buffer1, Buffer2, Q);
copy(Buffer1, Buffer2, Q);
modify(Buffer2, Q);
copy<UseSYCL2020HostTask>(Buffer2, Buffer1, Q);
copy(Buffer2, Buffer1, Q);
}
checkBufferValues(Buffer1, COUNT - 1);
checkBufferValues(Buffer2, COUNT - 1);
Expand All @@ -161,14 +158,14 @@ template <bool UseSYCL2020HostTask> void test2_1(queue &Q) {
// captured outside the command group. The OpenCL event can be set after the
// command group finishes. Must not deadlock according to implementation and
// proposal
template <bool UseSYCL2020HostTask> void test3(queue &Q) {
void test3(queue &Q) {
// Want some large buffer for operation to take long
buffer<int, 1> Buffer{BUFFER_SIZE * 128};

event Event = Q.submit([&](handler &CGH) {
auto Acc1 = Buffer.get_access<mode::write>(CGH);

CGH.parallel_for<NameGen<UseSYCL2020HostTask, class Init3>>(
CGH.parallel_for<NameGen<true, class Init3>>(
BUFFER_SIZE, [=](item<1> Id) { Acc1[Id] = 123; });
});

Expand All @@ -181,40 +178,33 @@ template <bool UseSYCL2020HostTask> void test3(queue &Q) {
if (RC != CL_SUCCESS)
throw runtime_error("Can't wait for events", RC);
};
if constexpr (UseSYCL2020HostTask)
CGH.host_task(Func);
else
CGH.codeplay_host_task(Func);
CGH.host_task(Func);
});
}

// Check that a single host-interop-task with a buffer will work
template <bool UseSYCL2020HostTask> void test4(queue &Q) {
void test4(queue &Q) {
buffer<int, 1> Buffer{BUFFER_SIZE};

Q.submit([&](handler &CGH) {
auto Acc = Buffer.get_access<mode::write>(CGH);
auto Func = [=](interop_handle IH) { /*A no-op */ };
if constexpr (UseSYCL2020HostTask)
CGH.host_task(Func);
else
CGH.codeplay_host_task(Func);
CGH.host_task(Func);
});
}

template <bool UseSYCL2020HostTask> void test5(queue &Q) {
void test5(queue &Q) {
buffer<int, 1> Buffer1{BUFFER_SIZE};
buffer<int, 1> Buffer2{BUFFER_SIZE};

Q.submit([&](handler &CGH) {
auto Acc = Buffer1.template get_access<mode::write>(CGH);

auto Kernel = [=](item<1> Id) { Acc[Id] = 123; };
CGH.parallel_for<NameGen<UseSYCL2020HostTask, class Test5Init>>(
Acc.get_count(), Kernel);
CGH.parallel_for<NameGen<true, class Test5Init>>(Acc.get_count(), Kernel);
});

copy<UseSYCL2020HostTask>(Buffer1, Buffer2, Q);
copy(Buffer1, Buffer2, Q);

checkBufferValues(Buffer2, static_cast<int>(123));
}
Expand All @@ -223,7 +213,7 @@ template <bool UseSYCL2020HostTask> void test5(queue &Q) {
// when properly registered in the command group.
// It also checks that an exception is thrown if the placeholder accessor
// is not registered.
template <bool UseSYCL2020HostTask> void test6(queue &Q) {
void test6(queue &Q) {
// Placeholder accessor that is properly registered in CGH.
try {
size_t size = 1;
Expand All @@ -233,8 +223,7 @@ template <bool UseSYCL2020HostTask> void test6(queue &Q) {
PHAcc(Buf);
Q.submit([&](sycl::handler &CGH) {
CGH.require(PHAcc);
CGH.codeplay_host_task(
[=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); });
CGH.host_task([=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); });
});
Q.wait_and_throw();
} catch (sycl::exception &E) {
Expand All @@ -251,10 +240,7 @@ template <bool UseSYCL2020HostTask> void test6(queue &Q) {
PHAcc(Buf);
Q.submit([&](sycl::handler &CGH) {
auto Func = [=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); };
if constexpr (UseSYCL2020HostTask)
CGH.host_task(Func);
else
CGH.codeplay_host_task(Func);
CGH.host_task(Func);
});
Q.wait_and_throw();
assert(!"Expected exception was not caught");
Expand All @@ -265,14 +251,14 @@ template <bool UseSYCL2020HostTask> void test6(queue &Q) {
}
}

template <bool UseSYCL2020HostTask> void tests(queue &Q) {
test1<UseSYCL2020HostTask>(Q);
test2<UseSYCL2020HostTask>(Q);
test2_1<UseSYCL2020HostTask>(Q);
test3<UseSYCL2020HostTask>(Q);
test4<UseSYCL2020HostTask>(Q);
test5<UseSYCL2020HostTask>(Q);
test6<UseSYCL2020HostTask>(Q);
void tests(queue &Q) {
test1(Q);
test2(Q);
test2_1(Q);
test3(Q);
test4(Q);
test5(Q);
test6(Q);
}

int main() {
Expand All @@ -283,8 +269,8 @@ int main() {
}
std::rethrow_exception(*ExceptionList.begin());
});
tests<true>(Q);
tests<false>(Q);
tests(Q);
tests(Q);
std::cout << "Test PASSED" << std::endl;
return 0;
}