Skip to content

Commit 3a83efc

Browse files
[SYCL] Make kernel-and-program unittests use unique kernels (#7279)
Some tests in kernel-and-program unittests would use kernels with the same names as other tests, which could potentially cause multiple binaries with similar kernels to be found. Since the tests need consistency in their kernel_bundles this commit changes them to use unique kernels. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 1db0e81 commit 3a83efc

File tree

2 files changed

+140
-88
lines changed

2 files changed

+140
-88
lines changed

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

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
using namespace sycl;
2828

29-
class TestKernel {
29+
class CacheTestKernel {
3030
public:
3131
void operator()(sycl::item<1>){};
3232
};
3333

34-
class TestKernel2 {
34+
class CacheTestKernel2 {
3535
public:
3636
void operator()(sycl::item<1>){};
3737
};
@@ -51,11 +51,11 @@ struct MockKernelInfo {
5151
static constexpr int64_t getKernelSize() { return 1; }
5252
};
5353

54-
template <> struct KernelInfo<TestKernel> : public MockKernelInfo {
55-
static constexpr const char *getName() { return "TestKernel"; }
54+
template <> struct KernelInfo<CacheTestKernel> : public MockKernelInfo {
55+
static constexpr const char *getName() { return "CacheTestKernel"; }
5656
};
57-
template <> struct KernelInfo<TestKernel2> : public MockKernelInfo {
58-
static constexpr const char *getName() { return "TestKernel2"; }
57+
template <> struct KernelInfo<CacheTestKernel2> : public MockKernelInfo {
58+
static constexpr const char *getName() { return "CacheTestKernel2"; }
5959
};
6060
} // namespace detail
6161
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
@@ -69,7 +69,7 @@ static sycl::unittest::PiImage generateDefaultImage() {
6969
std::vector<unsigned char> Bin{0, 1, 2, 3, 4, 5}; // Random data
7070

7171
PiArray<PiOffloadEntry> Entries =
72-
makeEmptyKernels({"TestKernel", "TestKernel2"});
72+
makeEmptyKernels({"CacheTestKernel", "CacheTestKernel2"});
7373

7474
PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format
7575
__SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec
@@ -122,9 +122,9 @@ class KernelAndProgramCacheTest : public ::testing::Test {
122122
// Check that programs built from source are not cached.
123123
TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramSourceNegativeBuild) {
124124
context Ctx{Plt};
125-
// program Prg{Ctx};
125+
// program Prg{Ctx};
126126

127-
// Prg.build_with_source("");
127+
// Prg.build_with_source("");
128128
auto CtxImpl = detail::getSyclObjImpl(Ctx);
129129
detail::KernelProgramCache::ProgramCacheT &Cache =
130130
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -134,9 +134,9 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramSourceNegativeBuild) {
134134
// Check that programs built from source with options are not cached.
135135
TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramSourceNegativeBuildWithOpts) {
136136
context Ctx{Plt};
137-
// program Prg{Ctx};
137+
// program Prg{Ctx};
138138

139-
// Prg.build_with_source("", "-g");
139+
// Prg.build_with_source("", "-g");
140140
auto CtxImpl = detail::getSyclObjImpl(Ctx);
141141
detail::KernelProgramCache::ProgramCacheT &Cache =
142142
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -147,10 +147,10 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramSourceNegativeBuildWithOpts) {
147147
TEST_F(KernelAndProgramCacheTest,
148148
DISABLED_ProgramSourceNegativeCompileAndLink) {
149149
context Ctx{Plt};
150-
// program Prg{Ctx};
150+
// program Prg{Ctx};
151151

152-
// Prg.compile_with_source("");
153-
// Prg.link();
152+
// Prg.compile_with_source("");
153+
// Prg.link();
154154
auto CtxImpl = detail::getSyclObjImpl(Ctx);
155155
detail::KernelProgramCache::ProgramCacheT &Cache =
156156
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -162,10 +162,10 @@ TEST_F(KernelAndProgramCacheTest,
162162
TEST_F(KernelAndProgramCacheTest,
163163
DISABLED_ProgramSourceNegativeCompileAndLinkWithOpts) {
164164
context Ctx{Plt};
165-
// program Prg{Ctx};
165+
// program Prg{Ctx};
166166

167-
// Prg.compile_with_source("");
168-
// Prg.link();
167+
// Prg.compile_with_source("");
168+
// Prg.link();
169169
auto CtxImpl = detail::getSyclObjImpl(Ctx);
170170
detail::KernelProgramCache::ProgramCacheT &Cache =
171171
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -175,11 +175,11 @@ TEST_F(KernelAndProgramCacheTest,
175175
// Check that programs built without options are cached.
176176
TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildPositive) {
177177
context Ctx{Plt};
178-
// program Prg1{Ctx};
179-
// program Prg2{Ctx};
178+
// program Prg1{Ctx};
179+
// program Prg2{Ctx};
180180

181-
// Prg1.build_with_kernel_type<TestKernel>();
182-
// Prg2.build_with_kernel_type<TestKernel>();
181+
// Prg1.build_with_kernel_type<CacheTestKernel>();
182+
// Prg2.build_with_kernel_type<CacheTestKernel>();
183183
auto CtxImpl = detail::getSyclObjImpl(Ctx);
184184
detail::KernelProgramCache::ProgramCacheT &Cache =
185185
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -189,21 +189,21 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildPositive) {
189189
// Check that programs built with options are cached.
190190
TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildPositiveBuildOpts) {
191191
context Ctx{Plt};
192-
// program Prg1{Ctx};
193-
// program Prg2{Ctx};
194-
// program Prg3{Ctx};
195-
// program Prg4{Ctx};
196-
// program Prg5{Ctx};
192+
// program Prg1{Ctx};
193+
// program Prg2{Ctx};
194+
// program Prg3{Ctx};
195+
// program Prg4{Ctx};
196+
// program Prg5{Ctx};
197197

198198
/* Build 5 instances of the same program. It is expected that there will be 3
199199
* instances of the program in the cache because Build of Prg1 is equal to
200200
* build of Prg5 and build of Prg2 is equal to build of Prg3.
201201
* */
202-
// Prg1.build_with_kernel_type<TestKernel>("-a");
203-
// Prg2.build_with_kernel_type<TestKernel>("-b");
204-
// Prg3.build_with_kernel_type<TestKernel>("-b");
205-
// Prg4.build_with_kernel_type<TestKernel>();
206-
// Prg5.build_with_kernel_type<TestKernel2>("-a");
202+
// Prg1.build_with_kernel_type<CacheTestKernel>("-a");
203+
// Prg2.build_with_kernel_type<CacheTestKernel>("-b");
204+
// Prg3.build_with_kernel_type<CacheTestKernel>("-b");
205+
// Prg4.build_with_kernel_type<CacheTestKernel>();
206+
// Prg5.build_with_kernel_type<CacheTestKernel2>("-a");
207207

208208
auto CtxImpl = detail::getSyclObjImpl(Ctx);
209209
detail::KernelProgramCache::ProgramCacheT &Cache =
@@ -214,10 +214,10 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildPositiveBuildOpts) {
214214
// Check that programs built with compile options are not cached.
215215
TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildNegativeCompileOpts) {
216216
context Ctx{Plt};
217-
// program Prg{Ctx};
217+
// program Prg{Ctx};
218218

219-
// Prg.compile_with_kernel_type<TestKernel>("-g");
220-
// Prg.link();
219+
// Prg.compile_with_kernel_type<CacheTestKernel>("-g");
220+
// Prg.link();
221221
auto CtxImpl = detail::getSyclObjImpl(Ctx);
222222
detail::KernelProgramCache::ProgramCacheT &Cache =
223223
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -227,10 +227,10 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildNegativeCompileOpts) {
227227
// Check that programs built with link options are not cached.
228228
TEST_F(KernelAndProgramCacheTest, DISABLED_ProgramBuildNegativeLinkOpts) {
229229
context Ctx{Plt};
230-
// program Prg{Ctx};
230+
// program Prg{Ctx};
231231

232-
// Prg.compile_with_kernel_type<TestKernel>();
233-
// Prg.link("-g");
232+
// Prg.compile_with_kernel_type<CacheTestKernel>();
233+
// Prg.link("-g");
234234
auto CtxImpl = detail::getSyclObjImpl(Ctx);
235235
detail::KernelProgramCache::ProgramCacheT &Cache =
236236
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();
@@ -244,10 +244,10 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelPositive) {
244244

245245
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
246246

247-
// program Prg{Ctx};
247+
// program Prg{Ctx};
248248

249-
// Prg.build_with_kernel_type<TestKernel>();
250-
// kernel Ker = Prg.get_kernel<TestKernel>();
249+
// Prg.build_with_kernel_type<CacheTestKernel>();
250+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
251251
detail::KernelProgramCache::KernelCacheT &Cache =
252252
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
253253
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
@@ -260,11 +260,11 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelPositiveBuildOpts) {
260260

261261
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
262262

263-
// program Prg{Ctx};
263+
// program Prg{Ctx};
264264

265-
// Prg.build_with_kernel_type<TestKernel>("-g");
265+
// Prg.build_with_kernel_type<CacheTestKernel>("-g");
266266

267-
// kernel Ker = Prg.get_kernel<TestKernel>();
267+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
268268
detail::KernelProgramCache::KernelCacheT &Cache =
269269
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
270270
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
@@ -277,11 +277,11 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeCompileOpts) {
277277

278278
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
279279

280-
// program Prg{Ctx};
280+
// program Prg{Ctx};
281281

282-
// Prg.compile_with_kernel_type<TestKernel>("-g");
283-
// Prg.link();
284-
// kernel Ker = Prg.get_kernel<TestKernel>();
282+
// Prg.compile_with_kernel_type<CacheTestKernel>("-g");
283+
// Prg.link();
284+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
285285
detail::KernelProgramCache::KernelCacheT &Cache =
286286
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
287287
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
@@ -294,11 +294,11 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeLinkOpts) {
294294

295295
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
296296

297-
// program Prg{Ctx};
297+
// program Prg{Ctx};
298298

299-
// Prg.compile_with_kernel_type<TestKernel>();
300-
// Prg.link("-g");
301-
// kernel Ker = Prg.get_kernel<TestKernel>();
299+
// Prg.compile_with_kernel_type<CacheTestKernel>();
300+
// Prg.link("-g");
301+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
302302
detail::KernelProgramCache::KernelCacheT &Cache =
303303
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
304304
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
@@ -312,13 +312,13 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeLinkedProgs) {
312312

313313
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
314314

315-
// program Prg1{Ctx};
316-
// program Prg2{Ctx};
315+
// program Prg1{Ctx};
316+
// program Prg2{Ctx};
317317

318-
// Prg1.compile_with_kernel_type<TestKernel>();
319-
// Prg2.compile_with_kernel_type<TestKernel2>();
320-
// program Prg({Prg1, Prg2});
321-
// kernel Ker = Prg.get_kernel<TestKernel>();
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>();
322322

323323
detail::KernelProgramCache::KernelCacheT &Cache =
324324
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
@@ -332,10 +332,10 @@ TEST_F(KernelAndProgramCacheTest, DISABLED_KernelNegativeSource) {
332332

333333
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
334334

335-
// program Prg{Ctx};
335+
// program Prg{Ctx};
336336

337-
// Prg.build_with_source("");
338-
// kernel Ker = Prg.get_kernel("test");
337+
// Prg.build_with_source("");
338+
// kernel Ker = Prg.get_kernel("test");
339339

340340
detail::KernelProgramCache::KernelCacheT &Cache =
341341
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
@@ -363,10 +363,10 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelPositive) {
363363

364364
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
365365

366-
// program Prg{Ctx};
366+
// program Prg{Ctx};
367367

368-
// Prg.build_with_kernel_type<TestKernel>();
369-
// kernel Ker = Prg.get_kernel<TestKernel>();
368+
// Prg.build_with_kernel_type<CacheTestKernel>();
369+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
370370
detail::KernelProgramCache::KernelFastCacheT &Cache =
371371
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
372372
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
@@ -379,11 +379,11 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelPositiveBuildOpts) {
379379

380380
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
381381

382-
// program Prg{Ctx};
382+
// program Prg{Ctx};
383383

384-
// Prg.build_with_kernel_type<TestKernel>("-g");
384+
// Prg.build_with_kernel_type<CacheTestKernel>("-g");
385385

386-
// kernel Ker = Prg.get_kernel<TestKernel>();
386+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
387387
detail::KernelProgramCache::KernelFastCacheT &Cache =
388388
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
389389
EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache for kernels";
@@ -396,11 +396,11 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeCompileOpts) {
396396

397397
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
398398

399-
// program Prg{Ctx};
399+
// program Prg{Ctx};
400400

401-
// Prg.compile_with_kernel_type<TestKernel>("-g");
402-
// Prg.link();
403-
// kernel Ker = Prg.get_kernel<TestKernel>();
401+
// Prg.compile_with_kernel_type<CacheTestKernel>("-g");
402+
// Prg.link();
403+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
404404
detail::KernelProgramCache::KernelFastCacheT &Cache =
405405
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
406406
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
@@ -413,11 +413,11 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeLinkOpts) {
413413

414414
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
415415

416-
// program Prg{Ctx};
416+
// program Prg{Ctx};
417417

418-
// Prg.compile_with_kernel_type<TestKernel>();
419-
// Prg.link("-g");
420-
// kernel Ker = Prg.get_kernel<TestKernel>();
418+
// Prg.compile_with_kernel_type<CacheTestKernel>();
419+
// Prg.link("-g");
420+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
421421
detail::KernelProgramCache::KernelFastCacheT &Cache =
422422
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
423423
EXPECT_EQ(Cache.size(), 0U) << "Expect empty cache for kernels";
@@ -431,13 +431,13 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeLinkedProgs) {
431431

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

434-
// program Prg1{Ctx};
435-
// program Prg2{Ctx};
434+
// program Prg1{Ctx};
435+
// program Prg2{Ctx};
436436

437-
// Prg1.compile_with_kernel_type<TestKernel>();
438-
// Prg2.compile_with_kernel_type<TestKernel2>();
439-
// program Prg({Prg1, Prg2});
440-
// kernel Ker = Prg.get_kernel<TestKernel>();
437+
// Prg1.compile_with_kernel_type<CacheTestKernel>();
438+
// Prg2.compile_with_kernel_type<CacheTestKernel2>();
439+
// program Prg({Prg1, Prg2});
440+
// kernel Ker = Prg.get_kernel<CacheTestKernel>();
441441

442442
detail::KernelProgramCache::KernelFastCacheT &Cache =
443443
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());
@@ -451,10 +451,10 @@ TEST_F(KernelAndProgramFastCacheTest, DISABLED_KernelNegativeSource) {
451451

452452
globalCtx.reset(new TestCtx{CtxImpl->getHandleRef()});
453453

454-
// program Prg{Ctx};
454+
// program Prg{Ctx};
455455

456-
// Prg.build_with_source("");
457-
// kernel Ker = Prg.get_kernel("test");
456+
// Prg.build_with_source("");
457+
// kernel Ker = Prg.get_kernel("test");
458458

459459
detail::KernelProgramCache::KernelFastCacheT &Cache =
460460
MockKernelProgramCache::getFastCache(CtxImpl->getKernelProgramCache());

0 commit comments

Comments
 (0)