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

Commit 6cf7cfd

Browse files
authored
[SYCL] Add LIT tests for handler::host_task() (#3837) (#299)
* [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 da719dc commit 6cf7cfd

File tree

9 files changed

+196
-136
lines changed

9 files changed

+196
-136
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: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
// TODO: Behaviour is unstable for level zero on Windows. Enable when fixed.
77
// UNSUPPORTED: windows && level_zero
88

9+
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS
10+
11+
#include <CL/sycl.hpp>
12+
913
#include <atomic>
1014
#include <condition_variable>
1115
#include <future>
1216
#include <mutex>
1317
#include <thread>
1418

15-
#include <CL/sycl.hpp>
16-
1719
namespace S = cl::sycl;
1820

21+
template <typename T, bool B> class NameGen;
22+
1923
struct Context {
2024
std::atomic_bool Flag;
2125
S::queue &Queue;
@@ -26,7 +30,37 @@ struct Context {
2630
std::condition_variable CV;
2731
};
2832

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

66-
CGH.single_task<class GeneratorTask>(GeneratorKernel);
100+
CGH.single_task<NameGen<class Gen, UseSYCL2020HostTask>>(GeneratorKernel);
67101
});
68102

69103
// 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-
});
104+
S::event HostTaskEvent = HostTask_CopyBuf1ToBuf2<UseSYCL2020HostTask>(Ctx);
92105

93106
// 3. submit simple task to move data between two buffers
94107
Ctx->Queue.submit([&](S::handler &CGH) {
@@ -105,7 +118,7 @@ void Thread1Fn(Context *Ctx) {
105118
DstAcc[Idx] = SrcAcc[Idx];
106119
};
107120

108-
CGH.single_task<class CopierTask>(CopierKernel);
121+
CGH.single_task<NameGen<class Copier, UseSYCL2020HostTask>>(CopierKernel);
109122
});
110123

111124
// 4. check data in buffer #3
@@ -134,7 +147,7 @@ void Thread2Fn(Context *Ctx) {
134147
assert(Ctx->Flag.load());
135148
}
136149

137-
void test() {
150+
template <bool UseSYCL2020HostTask> void test() {
138151
auto EH = [](S::exception_list EL) {
139152
for (const std::exception_ptr &E : EL) {
140153
throw E;
@@ -146,7 +159,8 @@ void test() {
146159
Context Ctx{{false}, Queue, {10}, {10}, {10}, {}, {}};
147160

148161
// 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);
162+
auto A1 =
163+
std::async(std::launch::async, Thread1Fn<UseSYCL2020HostTask>, &Ctx);
150164
auto A2 = std::async(std::launch::async, Thread2Fn, &Ctx);
151165

152166
A1.get();
@@ -171,21 +185,33 @@ void test() {
171185
}
172186

173187
int main() {
174-
test();
188+
test<true>();
189+
test<false>();
175190

176191
return 0;
177192
}
178193

179-
// launch of GeneratorTask kernel
194+
// launch of Gen kernel
180195
// CHECK:---> piKernelCreate(
181-
// CHECK: GeneratorTask
196+
// CHECK: NameGen
182197
// CHECK:---> piEnqueueKernelLaunch(
183198
// prepare for host task
184199
// CHECK:---> piEnqueueMemBuffer{{Map|Read}}(
185-
// launch of CopierTask kernel
200+
// launch of Copier kernel
186201
// CHECK:---> piKernelCreate(
187-
// CHECK: CopierTask
202+
// CHECK: Copier
188203
// CHECK:---> piEnqueueKernelLaunch(
204+
205+
// CHECK:---> piKernelCreate(
206+
// CHECK: NameGen
207+
// CHECK:---> piEnqueueKernelLaunch(
208+
// prepare for host task
209+
// CHECK:---> piEnqueueMemBuffer{{Map|Read}}(
210+
// launch of Copier kernel
211+
// CHECK:---> piKernelCreate(
212+
// CHECK: Copier
213+
// CHECK:---> piEnqueueKernelLaunch(
214+
189215
// TODO need to check for piEventsWait as "wait on dependencies of host task".
190216
// At the same time this piEventsWait may occur anywhere after
191217
// 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)