10
10
11
11
#include < CL/sycl.hpp>
12
12
13
+ namespace pi = cl::sycl::detail::pi;
14
+ namespace RT = cl::sycl::RT;
15
+
16
+ #define KERNEL_NAME_SRC " kernel_source"
17
+ #define TEST_SOURCE " kernel void " KERNEL_NAME_SRC " (global int* a) " \
18
+ " { a[get_global_id(0)] += 1; }\n "
19
+
13
20
class Functor {
14
21
public:
15
22
void operator ()(cl::sycl::item<1 > Item) { (void )Item; }
@@ -37,6 +44,21 @@ struct TestContext {
37
44
return std::move (Prog);
38
45
}
39
46
47
+ cl::sycl::program
48
+ getProgramWSource (const cl::sycl::string_class &BuildOptions = " " ) {
49
+ cl::sycl::program Prog (Queue.get_context ());
50
+
51
+ Prog.build_with_source (TEST_SOURCE, BuildOptions);
52
+
53
+ assert (Prog.get_state () == cl::sycl::program_state::linked &&
54
+ " Linked state was expected" );
55
+
56
+ assert (Prog.has_kernel <class SingleTask >() &&
57
+ " Expecting SingleTask kernel exists" );
58
+
59
+ return std::move (Prog);
60
+ }
61
+
40
62
cl::sycl::program getCompiledProgram () {
41
63
cl::sycl::program Prog (Queue.get_context ());
42
64
@@ -48,6 +70,43 @@ struct TestContext {
48
70
return std::move (Prog);
49
71
}
50
72
73
+ cl::sycl::program
74
+ getCompiledAndLinkedProgram (const cl::sycl::string_class &CompileOptions = " " ,
75
+ const cl::sycl::string_class &LinkOptions = " " ) {
76
+ cl::sycl::program Prog (Queue.get_context ());
77
+
78
+ Prog.compile_with_kernel_type <class SingleTask >(CompileOptions);
79
+
80
+ assert (Prog.get_state () == cl::sycl::program_state::compiled &&
81
+ " Compiled state was expected" );
82
+
83
+ Prog.link (LinkOptions);
84
+
85
+ assert (Prog.get_state () == cl::sycl::program_state::linked &&
86
+ " Linked state was expected" );
87
+
88
+ return std::move (Prog);
89
+ }
90
+
91
+ cl::sycl::program
92
+ getCompiledAndLinkedProgramWSource (
93
+ const cl::sycl::string_class &CompileOptions = " " ,
94
+ const cl::sycl::string_class &LinkOptions = " " ) {
95
+ cl::sycl::program Prog (Queue.get_context ());
96
+
97
+ Prog.compile_with_source (TEST_SOURCE, CompileOptions);
98
+
99
+ assert (Prog.get_state () == cl::sycl::program_state::compiled &&
100
+ " Compiled state was expected" );
101
+
102
+ Prog.link (LinkOptions);
103
+
104
+ assert (Prog.get_state () == cl::sycl::program_state::linked &&
105
+ " Linked state was expected" );
106
+
107
+ return std::move (Prog);
108
+ }
109
+
51
110
cl::sycl::kernel getKernel (cl::sycl::program &Prog) {
52
111
auto Kernel = Prog.get_kernel <class SingleTask >();
53
112
@@ -58,10 +117,13 @@ struct TestContext {
58
117
59
118
return std::move (Kernel);
60
119
}
61
- };
62
120
63
- namespace pi = cl::sycl::detail::pi;
64
- namespace RT = cl::sycl::RT;
121
+ cl::sycl::kernel getKernelWSource (cl::sycl::program &Prog) {
122
+ auto Kernel = Prog.get_kernel (KERNEL_NAME_SRC);
123
+
124
+ return std::move (Kernel);
125
+ }
126
+ };
65
127
66
128
static void testProgramCachePositive () {
67
129
TestContext TestCtx;
@@ -90,6 +152,86 @@ static void testProgramCacheNegativeCustomBuildOptions() {
90
152
" Expecting empty program cache" );
91
153
}
92
154
155
+ static void testProgramCacheNegativeCompileLinkCustomOpts () {
156
+ TestContext TestCtx;
157
+
158
+ {
159
+ auto Prog = TestCtx.getCompiledAndLinkedProgram ();
160
+
161
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
162
+
163
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
164
+ " Expecting empty program cache" );
165
+ }
166
+
167
+ {
168
+ auto Prog = TestCtx.getCompiledAndLinkedProgram (" -g" , " -cl-no-signed-zeroes" );
169
+
170
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
171
+
172
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
173
+ " Expecting empty program cache" );
174
+ }
175
+
176
+ {
177
+ auto Prog = TestCtx.getCompiledAndLinkedProgram (" " , " -cl-no-signed-zeroes" );
178
+
179
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
180
+
181
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
182
+ " Expecting empty program cache" );
183
+ }
184
+
185
+ {
186
+ auto Prog = TestCtx.getCompiledAndLinkedProgram (" -g" , " " );
187
+
188
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
189
+
190
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
191
+ " Expecting empty program cache" );
192
+ }
193
+ }
194
+
195
+ static void testProgramCacheNegativeCompileLinkSource () {
196
+ TestContext TestCtx;
197
+
198
+ {
199
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource ();
200
+
201
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
202
+
203
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
204
+ " Expecting empty program cache" );
205
+ }
206
+
207
+ {
208
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource (" -g" , " -cl-no-signed-zeroes" );
209
+
210
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
211
+
212
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
213
+ " Expecting empty program cache" );
214
+ }
215
+
216
+ {
217
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource (" " , " -cl-no-signed-zeroes" );
218
+
219
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
220
+
221
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
222
+ " Expecting empty program cache" );
223
+ }
224
+
225
+ {
226
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource (" -g" , " " );
227
+
228
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
229
+
230
+ assert (Ctx->getCachedPrograms ().size () == 0 &&
231
+ " Expecting empty program cache" );
232
+ }
233
+ }
234
+
93
235
static void testKernelCachePositive () {
94
236
TestContext TestCtx;
95
237
@@ -163,14 +305,115 @@ void testKernelCacheNegativeCustomBuildOptions() {
163
305
}
164
306
}
165
307
308
+ void testKernelCacheNegativeCompileLink () {
309
+ TestContext TestCtx;
310
+
311
+ {
312
+ auto Prog = TestCtx.getCompiledAndLinkedProgram ();
313
+ auto Kernel = TestCtx.getKernel (Prog);
314
+
315
+ if (!TestCtx.Queue .is_host ()) {
316
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
317
+ assert (Ctx->getCachedKernels ().size () == 0 &&
318
+ " Unexpected data in kernels cache" );
319
+ }
320
+ }
321
+
322
+ {
323
+ TestContext TestCtx1;
324
+ auto Prog = TestCtx1.getCompiledAndLinkedProgram (" -g" , " -cl-no-signed-zeroes" );
325
+ auto Kernel = TestCtx1.getKernel (Prog);
326
+
327
+ if (!TestCtx1.Queue .is_host ()) {
328
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
329
+ assert (Ctx->getCachedKernels ().size () == 0 &&
330
+ " Unexpected data in kernels cache" );
331
+ }
332
+ }
333
+
334
+ {
335
+ auto Prog = TestCtx.getCompiledAndLinkedProgram (" -g" , " " );
336
+ auto Kernel = TestCtx.getKernel (Prog);
337
+
338
+ if (!TestCtx.Queue .is_host ()) {
339
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
340
+ assert (Ctx->getCachedKernels ().size () == 0 &&
341
+ " Unexpected data in kernels cache" );
342
+ }
343
+ }
344
+
345
+ {
346
+ auto Prog = TestCtx.getCompiledAndLinkedProgram (" " , " -cl-no-signed-zeroes" );
347
+ auto Kernel = TestCtx.getKernel (Prog);
348
+
349
+ if (!TestCtx.Queue .is_host ()) {
350
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
351
+ assert (Ctx->getCachedKernels ().size () == 0 &&
352
+ " Unexpected data in kernels cache" );
353
+ }
354
+ }
355
+ }
356
+
357
+ void testKernelCacheNegativeCompileLinkSource () {
358
+ TestContext TestCtx;
359
+
360
+ {
361
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource ();
362
+ auto Kernel = TestCtx.getKernelWSource (Prog);
363
+
364
+ if (!TestCtx.Queue .is_host ()) {
365
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
366
+ assert (Ctx->getCachedKernels ().size () == 0 &&
367
+ " Unexpected data in kernels cache" );
368
+ }
369
+ }
370
+
371
+ {
372
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource (" -g" , " -cl-no-signed-zeroes" );
373
+ auto Kernel = TestCtx.getKernelWSource (Prog);
374
+
375
+ if (!TestCtx.Queue .is_host ()) {
376
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
377
+ assert (Ctx->getCachedKernels ().size () == 0 &&
378
+ " Unexpected data in kernels cache" );
379
+ }
380
+ }
381
+
382
+ {
383
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource (" -g" , " " );
384
+ auto Kernel = TestCtx.getKernelWSource (Prog);
385
+
386
+ if (!TestCtx.Queue .is_host ()) {
387
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
388
+ assert (Ctx->getCachedKernels ().size () == 0 &&
389
+ " Unexpected data in kernels cache" );
390
+ }
391
+ }
392
+
393
+ {
394
+ auto Prog = TestCtx.getCompiledAndLinkedProgramWSource (" " , " -cl-no-signed-zeroes" );
395
+ auto Kernel = TestCtx.getKernelWSource (Prog);
396
+
397
+ if (!TestCtx.Queue .is_host ()) {
398
+ auto *Ctx = cl::sycl::detail::getRawSyclObjImpl (Prog.get_context ());
399
+ assert (Ctx->getCachedKernels ().size () == 0 &&
400
+ " Unexpected data in kernels cache" );
401
+ }
402
+ }
403
+ }
404
+
166
405
int main () {
167
406
testProgramCachePositive ();
168
407
testProgramCacheNegativeCustomBuildOptions ();
408
+ testProgramCacheNegativeCompileLinkCustomOpts ();
409
+ testProgramCacheNegativeCompileLinkSource ();
169
410
170
411
testKernelCachePositive ();
171
412
testKernelCacheNegativeLinkedProgram ();
172
413
testKernelCacheNegativeOCLProgram ();
173
414
testKernelCacheNegativeCustomBuildOptions ();
415
+ testKernelCacheNegativeCompileLink ();
416
+ testKernelCacheNegativeCompileLinkSource ();
174
417
175
418
return 0 ;
176
419
}
0 commit comments