Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 33ad79c

Browse files
committed
[SYCL] Add LIT tests for handler::host_task() (#3837)
This patch tests intel/llvm#3837 Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent c9a62a2 commit 33ad79c

File tree

9 files changed

+183
-128
lines changed

9 files changed

+183
-128
lines changed

SYCL/Basic/accessor/Inputs/host_task_accessor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ int main() {
5252
sycl::id<1>(1), sycl::write_only);
5353
#endif
5454

55+
#if defined(accessor_new_api_test) || defined(buffer_new_api_test)
56+
cgh.host_task([=]() {
57+
#else
5558
cgh.codeplay_host_task([=]() {
59+
#endif
5660
acc_7[6] = acc_1[0];
5761
acc_8[7] = acc_2[1];
5862
acc_9[7] = acc_3[1];
@@ -109,7 +113,11 @@ int main() {
109113
sycl::write_only, sycl::noinit);
110114
#endif
111115

116+
#if defined(accessor_new_api_test) || defined(buffer_new_api_test)
117+
cgh.host_task([=]() {
118+
#else
112119
cgh.codeplay_host_task([=]() {
120+
#endif
113121
acc_7[6] = acc_1[0];
114122
acc_8[7] = acc_2[1];
115123
acc_9[7] = acc_3[1];

SYCL/Basic/host-task-dependency.cpp

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,37 @@ struct Context {
2626
std::condition_variable CV;
2727
};
2828

29-
void Thread1Fn(Context *Ctx) {
29+
template <bool UseSYCL2020HostTask>
30+
S::event HostTask_CopyBuf1ToBuf2(Context *Ctx) {
31+
S::event Event = Ctx->Queue.submit([&](S::handler &CGH) {
32+
S::accessor<int, 1, S::access::mode::read, S::access::target::host_buffer>
33+
CopierSrcAcc(Ctx->Buf1, CGH);
34+
S::accessor<int, 1, S::access::mode::write, S::access::target::host_buffer>
35+
CopierDstAcc(Ctx->Buf2, CGH);
36+
37+
auto CopierHostTask = [=] {
38+
for (size_t Idx = 0; Idx < CopierDstAcc.get_count(); ++Idx)
39+
CopierDstAcc[Idx] = CopierSrcAcc[Idx];
40+
41+
bool Expected = false;
42+
bool Desired = true;
43+
assert(Ctx->Flag.compare_exchange_strong(Expected, Desired));
44+
45+
{
46+
std::lock_guard<std::mutex> Lock(Ctx->Mutex);
47+
Ctx->CV.notify_all();
48+
}
49+
};
50+
51+
if constexpr (UseSYCL2020HostTask)
52+
CGH.host_task(CopierHostTask);
53+
else
54+
CGH.codeplay_host_task(CopierHostTask);
55+
});
56+
return Event;
57+
}
58+
59+
template <bool UseSYCL2020HostTask> void Thread1Fn(Context *Ctx) {
3060
// 0. initialize resulting buffer with apriori wrong result
3161
{
3262
S::accessor<int, 1, S::access::mode::write, S::access::target::host_buffer>
@@ -67,28 +97,7 @@ void Thread1Fn(Context *Ctx) {
6797
});
6898

6999
// 2. submit host task writing from buf 1 to buf 2
70-
auto HostTaskEvent = Ctx->Queue.submit([&](S::handler &CGH) {
71-
S::accessor<int, 1, S::access::mode::read, S::access::target::host_buffer>
72-
CopierSrcAcc(Ctx->Buf1, CGH);
73-
S::accessor<int, 1, S::access::mode::write, S::access::target::host_buffer>
74-
CopierDstAcc(Ctx->Buf2, CGH);
75-
76-
auto CopierHostTask = [CopierSrcAcc, CopierDstAcc, &Ctx] {
77-
for (size_t Idx = 0; Idx < CopierDstAcc.get_count(); ++Idx)
78-
CopierDstAcc[Idx] = CopierSrcAcc[Idx];
79-
80-
bool Expected = false;
81-
bool Desired = true;
82-
assert(Ctx->Flag.compare_exchange_strong(Expected, Desired));
83-
84-
{
85-
std::lock_guard<std::mutex> Lock(Ctx->Mutex);
86-
Ctx->CV.notify_all();
87-
}
88-
};
89-
90-
CGH.codeplay_host_task(CopierHostTask);
91-
});
100+
S::event HostTaskEvent = HostTask_CopyBuf1ToBuf2<UseSYCL2020HostTask>(Ctx);
92101

93102
// 3. submit simple task to move data between two buffers
94103
Ctx->Queue.submit([&](S::handler &CGH) {
@@ -134,7 +143,7 @@ void Thread2Fn(Context *Ctx) {
134143
assert(Ctx->Flag.load());
135144
}
136145

137-
void test() {
146+
template <bool UseSYCL2020HostTask> void test() {
138147
auto EH = [](S::exception_list EL) {
139148
for (const std::exception_ptr &E : EL) {
140149
throw E;
@@ -146,7 +155,7 @@ void test() {
146155
Context Ctx{{false}, Queue, {10}, {10}, {10}, {}, {}};
147156

148157
// 0. setup: thread 1 T1: exec smth; thread 2 T2: waits; init flag F = false
149-
auto A1 = std::async(std::launch::async, Thread1Fn, &Ctx);
158+
auto A1 = std::async(std::launch::async, Thread1Fn<true>, &Ctx);
150159
auto A2 = std::async(std::launch::async, Thread2Fn, &Ctx);
151160

152161
A1.get();
@@ -171,7 +180,8 @@ void test() {
171180
}
172181

173182
int main() {
174-
test();
183+
test<true>();
184+
test<false>();
175185

176186
return 0;
177187
}
@@ -186,6 +196,17 @@ int main() {
186196
// CHECK:---> piKernelCreate(
187197
// CHECK: CopierTask
188198
// CHECK:---> piEnqueueKernelLaunch(
199+
200+
// CHECK:---> piKernelCreate(
201+
// CHECK: GeneratorTask
202+
// CHECK:---> piEnqueueKernelLaunch(
203+
// prepare for host task
204+
// CHECK:---> piEnqueueMemBuffer{{Map|Read}}(
205+
// launch of CopierTask kernel
206+
// CHECK:---> piKernelCreate(
207+
// CHECK: CopierTask
208+
// CHECK:---> piEnqueueKernelLaunch(
209+
189210
// TODO need to check for piEventsWait as "wait on dependencies of host task".
190211
// At the same time this piEventsWait may occur anywhere after
191212
// piEnqueueMemBufferMap ("prepare for host task").

SYCL/HostInteropTask/host-task-dependency2.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ static auto EH = [](exception_list EL) {
2424

2525
// Host-task depending on another host-task via handler::depends_on() only
2626
// should not hang
27-
void test(size_t Count) {
28-
queue Q(EH);
29-
27+
template <bool UseSYCL2020HostTask> void test(queue &Q, size_t Count) {
3028
static constexpr size_t BufferSize = 10 * 1024;
3129

3230
buffer<int, 1> B0{range<1>{BufferSize}};
@@ -45,11 +43,15 @@ void test(size_t Count) {
4543
auto Acc1 = B1.get_access<mode::read_write, target::host_buffer>(CGH);
4644
auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);
4745

48-
CGH.codeplay_host_task([=] {
46+
auto Func = [=] {
4947
Acc0[0] = 1 * Idx;
5048
Acc1[0] = 2 * Idx;
5149
Acc2[0] = 3 * Idx;
52-
});
50+
};
51+
if constexpr (UseSYCL2020HostTask)
52+
CGH.host_task(Func);
53+
else
54+
CGH.codeplay_host_task(Func);
5355
});
5456

5557
// This host task is going to depend on blocked empty node of the first
@@ -60,10 +62,14 @@ void test(size_t Count) {
6062
auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);
6163
auto Acc3 = B3.get_access<mode::read_write, target::host_buffer>(CGH);
6264

63-
CGH.codeplay_host_task([=] {
65+
auto Func = [=] {
6466
Acc2[1] = 1 * Idx;
6567
Acc3[1] = 2 * Idx;
66-
});
68+
};
69+
if constexpr (UseSYCL2020HostTask)
70+
CGH.host_task(Func);
71+
else
72+
CGH.codeplay_host_task(Func);
6773
});
6874

6975
// This host-task only depends on the second host-task via
@@ -77,10 +83,14 @@ void test(size_t Count) {
7783
auto Acc4 = B4.get_access<mode::read_write, target::host_buffer>(CGH);
7884
auto Acc5 = B5.get_access<mode::read_write, target::host_buffer>(CGH);
7985

80-
CGH.codeplay_host_task([=] {
86+
auto Func = [=] {
8187
Acc4[2] = 1 * Idx;
8288
Acc5[2] = 2 * Idx;
83-
});
89+
};
90+
if constexpr (UseSYCL2020HostTask)
91+
CGH.host_task(Func);
92+
else
93+
CGH.codeplay_host_task(Func);
8494
});
8595
}
8696

@@ -92,6 +102,8 @@ int main(int Argc, const char *Argv[]) {
92102
if (Argc > 1)
93103
Count = std::stoi(Argv[1]);
94104

95-
test(Count);
105+
queue Q(EH);
106+
test<true>(Q, Count);
107+
test<false>(Q, Count);
96108
return 0;
97109
}

SYCL/HostInteropTask/host-task-dependency3.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void test(size_t Count) {
4949

5050
auto Acc0 = B0.get_access<mode::read_write, target::host_buffer>(CGH);
5151

52-
CGH.codeplay_host_task([=] {
52+
CGH.host_task([=] {
5353
std::this_thread::sleep_for(SleepFor);
5454
Acc0[0] = 1 * Idx;
5555
});
@@ -76,7 +76,7 @@ void test(size_t Count) {
7676

7777
auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);
7878

79-
CGH.codeplay_host_task([=] {
79+
CGH.host_task([=] {
8080
std::this_thread::sleep_for(SleepFor);
8181
Acc2[3] = 1 * Idx;
8282
});
@@ -91,7 +91,7 @@ void test(size_t Count) {
9191
auto Acc1 = B1.get_access<mode::read_write, target::host_buffer>(CGH);
9292
auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);
9393

94-
CGH.codeplay_host_task([=] {
94+
CGH.host_task([=] {
9595
std::this_thread::sleep_for(SleepFor);
9696
Acc0[4] = 1 * Idx;
9797
Acc1[4] = 2 * Idx;
@@ -109,7 +109,7 @@ void test(size_t Count) {
109109

110110
auto Acc5 = B5.get_access<mode::read_write, target::host_buffer>(CGH);
111111

112-
CGH.codeplay_host_task([=] { Acc5[5] = 1 * Idx; });
112+
CGH.host_task([=] { Acc5[5] = 1 * Idx; });
113113
});
114114
}
115115

SYCL/HostInteropTask/host-task-dependency4.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
cl::sycl::event submit(cl::sycl::queue &Q, cl::sycl::buffer<int> &B) {
1010
return Q.submit([&](cl::sycl::handler &CGH) {
1111
auto A = B.template get_access<cl::sycl::access::mode::read_write>(CGH);
12-
CGH.codeplay_host_task([=]() { (void)A; });
12+
CGH.host_task([=]() { (void)A; });
1313
});
1414
}
1515

@@ -23,7 +23,7 @@ int main() {
2323
Events.push_back(submit(Q, A));
2424
Q.submit([&](sycl::handler &CGH) {
2525
CGH.depends_on(Events);
26-
CGH.codeplay_host_task([&] { printf("all done\n"); });
26+
CGH.host_task([&] { printf("all done\n"); });
2727
}).wait_and_throw();
2828

2929
return 0;

SYCL/HostInteropTask/host-task-failure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
2020
auto SrcA = Src.template get_access<mode::read>(CGH);
2121
auto DstA = Dst.template get_access<mode::write>(CGH);
2222

23-
CGH.codeplay_host_task([=]() {
23+
CGH.host_task([=]() {
2424
for (size_t Idx = 0; Idx < SrcA.get_count(); ++Idx)
2525
DstA[Idx] = SrcA[Idx];
2626
});

SYCL/HostInteropTask/host-task-two-queues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void test() {
4949
auto AccB = BufB.get_access<sycl::access::mode::read>(CGH);
5050
auto AccC = BufC.get_access<sycl::access::mode::read_write>(CGH);
5151

52-
CGH.codeplay_host_task([=] {
52+
CGH.host_task([=] {
5353
for (size_t I = 0; I < WIDTH; ++I)
5454
for (size_t J = 0; J < HEIGHT; ++J) {
5555
std::cout << "C[" << I << "][" << J << "] = " << AccC[I][J]

0 commit comments

Comments
 (0)