Skip to content

Commit 5a606e4

Browse files
[NFC][SYCL] Prepare unittests/kernel-and-program for getSyclObjImpl to return raw ref (#19221)
I'm planning to change `getSyclObjImpl` to return a raw reference in a later patch, uploading a bunch of PRs in preparation to that to make the subsequent review easier.
1 parent 96caa74 commit 5a606e4

File tree

4 files changed

+79
-80
lines changed

4 files changed

+79
-80
lines changed

sycl/unittests/kernel-and-program/Cache.cpp

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramSourceNegativeBuild) {
105105
// program Prg{Ctx};
106106

107107
// Prg.build_with_source("");
108-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
108+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
109109
detail::KernelProgramCache::ProgramCache &Cache =
110-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
110+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
111111
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for source programs";
112112
}
113113

@@ -117,9 +117,9 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramSourceNegativeBuildWithOpts) {
117117
// program Prg{Ctx};
118118

119119
// Prg.build_with_source("", "-g");
120-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
120+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
121121
detail::KernelProgramCache::ProgramCache &Cache =
122-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
122+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
123123
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for source programs";
124124
}
125125

@@ -131,9 +131,9 @@ TEST_F(KernelAndProgramCacheTest,
131131

132132
// Prg.compile_with_source("");
133133
// Prg.link();
134-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
134+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
135135
detail::KernelProgramCache::ProgramCache &Cache =
136-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
136+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
137137
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for source programs";
138138
}
139139

@@ -146,9 +146,9 @@ TEST_F(KernelAndProgramCacheTest,
146146

147147
// Prg.compile_with_source("");
148148
// Prg.link();
149-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
149+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
150150
detail::KernelProgramCache::ProgramCache &Cache =
151-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
151+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
152152
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for source programs";
153153
}
154154

@@ -161,9 +161,9 @@ TEST_F(KernelAndProgramCacheTest, KernelBundleInputState) {
161161
sycl::kernel_bundle KernelBundle1 =
162162
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {KernelID1});
163163

164-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
164+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
165165
detail::KernelProgramCache::ProgramCache &Cache =
166-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
166+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
167167

168168
EXPECT_EQ(Cache.size(), 0U)
169169
<< "Expect empty cache for kernel_bundles build with input_state.";
@@ -178,9 +178,9 @@ TEST_F(KernelAndProgramCacheTest, KernelBundleObjectState) {
178178
sycl::kernel_bundle KernelBundle1 =
179179
sycl::get_kernel_bundle<sycl::bundle_state::object>(Ctx, {KernelID1});
180180

181-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
181+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
182182
detail::KernelProgramCache::ProgramCache &Cache =
183-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
183+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
184184

185185
EXPECT_EQ(Cache.size(), 0U)
186186
<< "Expect empty cache for kernel_bundles build with object_state.";
@@ -198,9 +198,9 @@ TEST_F(KernelAndProgramCacheTest, KernelBundleExecutableState) {
198198
sycl::kernel_bundle KernelBundle2 =
199199
sycl::get_kernel_bundle<sycl::bundle_state::executable>(Ctx, {KernelID2});
200200

201-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
201+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
202202
detail::KernelProgramCache::ProgramCache &Cache =
203-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
203+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
204204

205205
EXPECT_EQ(Cache.size(), 1U)
206206
<< "Expect non-empty cache for kernel_bundles with executable_state.";
@@ -228,9 +228,9 @@ TEST_F(KernelAndProgramCacheTest, SpecConstantCacheNegative) {
228228
EXPECT_EQ(KernelBundle2.get_specialization_constant<SpecConst1>(), 70)
229229
<< "Wrong specialization constant";
230230

231-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
231+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
232232
detail::KernelProgramCache::ProgramCache &Cache =
233-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
233+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
234234

235235
EXPECT_EQ(Cache.size(), 2U) << "Expect an entry for each build in the cache.";
236236
}
@@ -251,9 +251,9 @@ TEST_F(KernelAndProgramCacheTest, KernelBundleJoin) {
251251
KernelBundles {KernelBundle1, KernelBundle2};
252252
sycl::kernel_bundle KernelBundle3 = sycl::join(KernelBundles);
253253

254-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
254+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
255255
detail::KernelProgramCache::ProgramCache &Cache =
256-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
256+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
257257

258258
EXPECT_EQ(Cache.size(), 1U)
259259
<< "Expect no caching for kennel_bundle created via join.";
@@ -278,9 +278,9 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildPositiveBuildOpts) {
278278
// Prg4.build_with_kernel_type<CacheTestKernel>();
279279
// Prg5.build_with_kernel_type<CacheTestKernel2>("-a");
280280

281-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
281+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
282282
detail::KernelProgramCache::ProgramCache &Cache =
283-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
283+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
284284
EXPECT_EQ(Cache.size(), 3U) << "Expect non-empty cache for programs";
285285
}
286286

@@ -291,9 +291,9 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildNegativeCompileOpts) {
291291

292292
// Prg.compile_with_kernel_type<CacheTestKernel>("-g");
293293
// Prg.link();
294-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
294+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
295295
detail::KernelProgramCache::ProgramCache &Cache =
296-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
296+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
297297
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for programs";
298298
}
299299

@@ -304,93 +304,93 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildNegativeLinkOpts) {
304304

305305
// Prg.compile_with_kernel_type<CacheTestKernel>();
306306
// Prg.link("-g");
307-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
307+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
308308
detail::KernelProgramCache::ProgramCache &Cache =
309-
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
309+
CtxImpl.getKernelProgramCache().acquireCachedPrograms().get();
310310
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for programs";
311311
}
312312

313313
// Check that kernels built without options are cached.
314314
TEST_F(KernelAndProgramCacheTest, DISABLED_KernelPositive) {
315315
context Ctx{Plt};
316-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
316+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
317317

318-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
318+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
319319

320320
// program Prg{Ctx};
321321

322322
// Prg.build_with_kernel_type<CacheTestKernel>();
323323
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
324324
detail::KernelProgramCache::KernelCacheT &Cache =
325-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
325+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
326326
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
327327
}
328328

329329
// Check that kernels built with options are cached.
330330
TEST_F(KernelAndProgramCacheTest, DISABLED_KernelPositiveBuildOpts) {
331331
context Ctx{Plt};
332-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
332+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
333333

334-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
334+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
335335

336336
// program Prg{Ctx};
337337

338338
// Prg.build_with_kernel_type<CacheTestKernel>("-g");
339339

340340
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
341341
detail::KernelProgramCache::KernelCacheT &Cache =
342-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
342+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
343343
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
344344
}
345345

346346
// Check that kernels built with compile options are not cached.
347347
TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeCompileOpts) {
348348
context Ctx{Plt};
349-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
349+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
350350

351-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
351+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
352352

353353
// program Prg{Ctx};
354354

355355
// Prg.compile_with_kernel_type<CacheTestKernel>("-g");
356356
// Prg.link();
357357
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
358358
detail::KernelProgramCache::KernelCacheT &Cache =
359-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
359+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
360360
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
361361
}
362362

363363
// Check that kernels built with link options are not cached.
364364
TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeLinkOpts) {
365365
context Ctx{Plt};
366-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
366+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
367367

368-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
368+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
369369

370370
// program Prg{Ctx};
371371

372372
// Prg.compile_with_kernel_type<CacheTestKernel>();
373373
// Prg.link("-g");
374374
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
375375
detail::KernelProgramCache::KernelCacheT &Cache =
376-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
376+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
377377
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
378378
}
379379

380380
// Check that kernels created from source are not cached.
381381
TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeSource) {
382382
context Ctx{Plt};
383-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
383+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
384384

385-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
385+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
386386

387387
// program Prg{Ctx};
388388

389389
// Prg.build_with_source("");
390390
// kernel Ker = Prg.get_kernel("test");
391391

392392
detail::KernelProgramCache::KernelCacheT &Cache =
393-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
393+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
394394
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
395395
}
396396

@@ -411,77 +411,77 @@ class MockKernelProgramCache : public detail::KernelProgramCache {
411411
// Check that kernels built without options are cached.
412412
TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelPositive) {
413413
context Ctx{Plt};
414-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
414+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
415415

416-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
416+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
417417

418418
// program Prg{Ctx};
419419

420420
// Prg.build_with_kernel_type<CacheTestKernel>();
421421
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
422422
detail::KernelProgramCache::FastKernelCacheT &Cache =
423-
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
423+
MockKernelProgramCache::getFastCache(CtxImpl.getKernelProgramCache());
424424
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
425425
}
426426

427427
// Check that kernels built with options are cached.
428428
TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelPositiveBuildOpts) {
429429
context Ctx{Plt};
430-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
430+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
431431

432-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
432+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
433433

434434
// program Prg{Ctx};
435435

436436
// Prg.build_with_kernel_type<CacheTestKernel>("-g");
437437

438438
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
439439
detail::KernelProgramCache::FastKernelCacheT &Cache =
440-
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
440+
MockKernelProgramCache::getFastCache(CtxImpl.getKernelProgramCache());
441441
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
442442
}
443443

444444
// Check that kernels built with compile options are not cached.
445445
TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeCompileOpts) {
446446
context Ctx{Plt};
447-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
447+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
448448

449-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
449+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
450450

451451
// program Prg{Ctx};
452452

453453
// Prg.compile_with_kernel_type<CacheTestKernel>("-g");
454454
// Prg.link();
455455
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
456456
detail::KernelProgramCache::FastKernelCacheT &Cache =
457-
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
457+
MockKernelProgramCache::getFastCache(CtxImpl.getKernelProgramCache());
458458
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
459459
}
460460

461461
// Check that kernels built with link options are not cached.
462462
TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeLinkOpts) {
463463
context Ctx{Plt};
464-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
464+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
465465

466-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
466+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
467467

468468
// program Prg{Ctx};
469469

470470
// Prg.compile_with_kernel_type<CacheTestKernel>();
471471
// Prg.link("-g");
472472
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
473473
detail::KernelProgramCache::FastKernelCacheT &Cache =
474-
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
474+
MockKernelProgramCache::getFastCache(CtxImpl.getKernelProgramCache());
475475
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
476476
}
477477

478478
// Check that kernels are not cached if program is created from multiple
479479
// programs.
480480
TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeLinkedProgs) {
481481
context Ctx{Plt};
482-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
482+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
483483

484-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
484+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
485485

486486
// program Prg1{Ctx};
487487
// program Prg2{Ctx};
@@ -492,23 +492,23 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeLinkedProgs) {
492492
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
493493

494494
detail::KernelProgramCache::FastKernelCacheT &Cache =
495-
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
495+
MockKernelProgramCache::getFastCache(CtxImpl.getKernelProgramCache());
496496
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
497497
}
498498

499499
// Check that kernels created from source are not cached.
500500
TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeSource) {
501501
context Ctx{Plt};
502-
auto CtxImpl = detail::getSyclObjImpl(Ctx);
502+
detail::context_impl &CtxImpl = *detail::getSyclObjImpl(Ctx);
503503

504-
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
504+
globalCtx.reset(new TestCtx{CtxImpl.getHandleRef()});
505505

506506
// program Prg{Ctx};
507507

508508
// Prg.build_with_source("");
509509
// kernel Ker = Prg.get_kernel("test");
510510

511511
detail::KernelProgramCache::FastKernelCacheT &Cache =
512-
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
512+
MockKernelProgramCache::getFastCache(CtxImpl.getKernelProgramCache());
513513
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
514514
}

0 commit comments

Comments
 (0)