@@ -37,6 +37,7 @@ class CacheTestKernel2 {
37
37
};
38
38
39
39
namespace sycl {
40
+ const static specialization_id<int > SpecConst1{42 };
40
41
__SYCL_INLINE_VER_NAMESPACE (_V1) {
41
42
namespace detail {
42
43
struct MockKernelInfo {
@@ -57,6 +58,9 @@ template <> struct KernelInfo<CacheTestKernel> : public MockKernelInfo {
57
58
template <> struct KernelInfo <CacheTestKernel2> : public MockKernelInfo {
58
59
static constexpr const char *getName () { return " CacheTestKernel2" ; }
59
60
};
61
+ template <> const char *get_spec_constant_symbolic_ID<SpecConst1>() {
62
+ return " SC1" ;
63
+ }
60
64
} // namespace detail
61
65
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
62
66
} // namespace sycl
@@ -172,18 +176,111 @@ TEST_F(KernelAndProgramCacheTest,
172
176
EXPECT_EQ (Cache.size (), 0U ) << " Expect empty cache for source programs" ;
173
177
}
174
178
175
- // Check that programs built without options are cached.
176
- TEST_F (KernelAndProgramCacheTest, DISABLED_ProgramBuildPositive) {
177
- context Ctx{Plt};
178
- // program Prg1{Ctx};
179
- // program Prg2{Ctx};
179
+ // Check that kernel_bundles with input_state are not cached.
180
+ TEST_F (KernelAndProgramCacheTest, KernelBundleInputState) {
181
+ std::vector<sycl::device> Devices = Plt.get_devices ();
182
+ sycl::context Ctx (Devices[0 ]);
183
+
184
+ auto KernelID1 = sycl::get_kernel_id<CacheTestKernel>();
185
+ sycl::kernel_bundle KernelBundle1 =
186
+ sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {KernelID1});
187
+
188
+ auto CtxImpl = detail::getSyclObjImpl (Ctx);
189
+ detail::KernelProgramCache::ProgramCacheT &Cache =
190
+ CtxImpl->getKernelProgramCache ().acquireCachedPrograms ().get ();
191
+
192
+ EXPECT_EQ (Cache.size (), 0U )
193
+ << " Expect empty cache for kernel_bundles build with input_state." ;
194
+ }
195
+
196
+ // Check that kernel_bundles with object_state are not cached.
197
+ TEST_F (KernelAndProgramCacheTest, KernelBundleObjectState) {
198
+ std::vector<sycl::device> Devices = Plt.get_devices ();
199
+ sycl::context Ctx (Devices[0 ]);
200
+
201
+ auto KernelID1 = sycl::get_kernel_id<CacheTestKernel>();
202
+ sycl::kernel_bundle KernelBundle1 =
203
+ sycl::get_kernel_bundle<sycl::bundle_state::object>(Ctx, {KernelID1});
180
204
181
- // Prg1.build_with_kernel_type<CacheTestKernel>();
182
- // Prg2.build_with_kernel_type<CacheTestKernel>();
183
205
auto CtxImpl = detail::getSyclObjImpl (Ctx);
184
206
detail::KernelProgramCache::ProgramCacheT &Cache =
185
207
CtxImpl->getKernelProgramCache ().acquireCachedPrograms ().get ();
186
- EXPECT_EQ (Cache.size (), 1U ) << " Expect non-empty cache for programs" ;
208
+
209
+ EXPECT_EQ (Cache.size (), 0U )
210
+ << " Expect empty cache for kernel_bundles build with object_state." ;
211
+ }
212
+
213
+ // Check that kernel_bundles with executable_state are cached.
214
+ TEST_F (KernelAndProgramCacheTest, KernelBundleExecutableState) {
215
+ std::vector<sycl::device> Devices = Plt.get_devices ();
216
+ sycl::context Ctx (Devices[0 ]);
217
+
218
+ auto KernelID1 = sycl::get_kernel_id<CacheTestKernel>();
219
+ auto KernelID2 = sycl::get_kernel_id<CacheTestKernel2>();
220
+ sycl::kernel_bundle KernelBundle1 =
221
+ sycl::get_kernel_bundle<sycl::bundle_state::executable>(Ctx, {KernelID1});
222
+ sycl::kernel_bundle KernelBundle2 =
223
+ sycl::get_kernel_bundle<sycl::bundle_state::executable>(Ctx, {KernelID2});
224
+
225
+ auto CtxImpl = detail::getSyclObjImpl (Ctx);
226
+ detail::KernelProgramCache::ProgramCacheT &Cache =
227
+ CtxImpl->getKernelProgramCache ().acquireCachedPrograms ().get ();
228
+
229
+ EXPECT_EQ (Cache.size (), 1U )
230
+ << " Expect non-empty cache for kernel_bundles with executable_state." ;
231
+ }
232
+
233
+ // Check that kernel_bundle built with specialization constants are cached.
234
+ TEST_F (KernelAndProgramCacheTest, SpecConstantCacheNegative) {
235
+ std::vector<sycl::device> Devices = Plt.get_devices ();
236
+ sycl::context Ctx (Devices[0 ]);
237
+
238
+ auto KernelID1 = sycl::get_kernel_id<CacheTestKernel>();
239
+ auto KernelID2 = sycl::get_kernel_id<CacheTestKernel2>();
240
+
241
+ sycl::kernel_bundle KernelBundle1 =
242
+ sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {KernelID1});
243
+ KernelBundle1.set_specialization_constant <SpecConst1>(80 );
244
+ sycl::build (KernelBundle1);
245
+ EXPECT_EQ (KernelBundle1.get_specialization_constant <SpecConst1>(), 80 )
246
+ << " Wrong specialization constant" ;
247
+
248
+ sycl::kernel_bundle KernelBundle2 =
249
+ sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {KernelID2});
250
+ KernelBundle2.set_specialization_constant <SpecConst1>(70 );
251
+ sycl::build (KernelBundle2);
252
+ EXPECT_EQ (KernelBundle2.get_specialization_constant <SpecConst1>(), 70 )
253
+ << " Wrong specialization constant" ;
254
+
255
+ auto CtxImpl = detail::getSyclObjImpl (Ctx);
256
+ detail::KernelProgramCache::ProgramCacheT &Cache =
257
+ CtxImpl->getKernelProgramCache ().acquireCachedPrograms ().get ();
258
+
259
+ EXPECT_EQ (Cache.size (), 1U ) << " Expect non-empty cache" ;
260
+ }
261
+
262
+ // Check that kernel_bundle created through join() is not cached.
263
+ TEST_F (KernelAndProgramCacheTest, KernelBundleJoin) {
264
+ std::vector<sycl::device> Devices = Plt.get_devices ();
265
+ sycl::context Ctx (Devices[0 ]);
266
+
267
+ auto KernelID1 = sycl::get_kernel_id<CacheTestKernel>();
268
+ auto KernelID2 = sycl::get_kernel_id<CacheTestKernel2>();
269
+ sycl::kernel_bundle KernelBundle1 =
270
+ sycl::get_kernel_bundle<sycl::bundle_state::executable>(Ctx, {KernelID1});
271
+ sycl::kernel_bundle KernelBundle2 =
272
+ sycl::get_kernel_bundle<sycl::bundle_state::executable>(Ctx, {KernelID2});
273
+
274
+ std::vector<kernel_bundle<sycl::bundle_state::executable>>
275
+ KernelBundles {KernelBundle1, KernelBundle2};
276
+ sycl::kernel_bundle KernelBundle3 = sycl::join (KernelBundles);
277
+
278
+ auto CtxImpl = detail::getSyclObjImpl (Ctx);
279
+ detail::KernelProgramCache::ProgramCacheT &Cache =
280
+ CtxImpl->getKernelProgramCache ().acquireCachedPrograms ().get ();
281
+
282
+ EXPECT_EQ (Cache.size (), 1U )
283
+ << " Expect no caching for kennel_bundle created via join." ;
187
284
}
188
285
189
286
// Check that programs built with options are cached.
@@ -304,27 +401,6 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeLinkOpts) {
304
401
EXPECT_EQ (Cache.size (), 0U ) << " Expect empty cache for kernels" ;
305
402
}
306
403
307
- // Check that kernels are not cached if program is created from multiple
308
- // programs.
309
- TEST_F (KernelAndProgramCacheTest, DISABLED_KernelNegativeLinkedProgs) {
310
- context Ctx{Plt};
311
- auto CtxImpl = detail::getSyclObjImpl (Ctx);
312
-
313
- globalCtx.reset (new TestCtx{CtxImpl->getHandleRef ()});
314
-
315
- // program Prg1{Ctx};
316
- // program Prg2{Ctx};
317
-
318
- // Prg1.compile_with_kernel_type<CacheTestKernel>();
319
- // Prg2.compile_with_kernel_type<CacheTestKernel2>();
320
- // program Prg({Prg1, Prg2});
321
- // kernel Ker = Prg.get_kernel<CacheTestKernel>();
322
-
323
- detail::KernelProgramCache::KernelCacheT &Cache =
324
- CtxImpl->getKernelProgramCache ().acquireKernelsPerProgramCache ().get ();
325
- EXPECT_EQ (Cache.size (), 0U ) << " Expect empty cache for kernels" ;
326
- }
327
-
328
404
// Check that kernels created from source are not cached.
329
405
TEST_F (KernelAndProgramCacheTest, DISABLED_KernelNegativeSource) {
330
406
context Ctx{Plt};
0 commit comments