Skip to content

Commit 27f4252

Browse files
[NFC][SYCL] Prepare misc unittests for getSyclObjImpl to return raw ref (#19222)
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 67df4b9 commit 27f4252

File tree

7 files changed

+39
-43
lines changed

7 files changed

+39
-43
lines changed

sycl/unittests/Extensions/DeviceGlobal.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,10 @@ TEST_F(DeviceGlobalTest, DeviceGlobalImgScopeUseBeforeCopyTo) {
620620
Q.single_task<DeviceGlobalImgScopeTestKernel>([]() {}).wait();
621621

622622
// Register the cached program as expected for device global memory operation.
623-
auto CtxImpl = sycl::detail::getSyclObjImpl(Q.get_context());
624-
sycl::detail::KernelProgramCache::KernelCacheT &KernelCache =
625-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
623+
using namespace sycl::detail;
624+
context_impl &CtxImpl = *getSyclObjImpl(Q.get_context());
625+
KernelProgramCache::KernelCacheT &KernelCache =
626+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
626627
ASSERT_EQ(KernelCache.size(), (size_t)1)
627628
<< "Expect 1 program in kernel cache";
628629
ExpectedReadWriteURProgram = KernelCache.begin()->first;
@@ -649,9 +650,10 @@ TEST_F(DeviceGlobalTest, DeviceGlobalImgScopeUseBeforeMemcpyTo) {
649650
Q.single_task<DeviceGlobalImgScopeTestKernel>([]() {}).wait();
650651

651652
// Register the cached program as expected for device global memory operation.
652-
auto CtxImpl = sycl::detail::getSyclObjImpl(Q.get_context());
653-
sycl::detail::KernelProgramCache::KernelCacheT &KernelCache =
654-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
653+
using namespace sycl::detail;
654+
context_impl &CtxImpl = *getSyclObjImpl(Q.get_context());
655+
KernelProgramCache::KernelCacheT &KernelCache =
656+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
655657
ASSERT_EQ(KernelCache.size(), (size_t)1)
656658
<< "Expect 1 program in kernel cache";
657659
ExpectedReadWriteURProgram = KernelCache.begin()->first;
@@ -678,9 +680,10 @@ TEST_F(DeviceGlobalTest, DeviceGlobalImgScopeUseBeforeCopyFrom) {
678680
Q.single_task<DeviceGlobalImgScopeTestKernel>([]() {}).wait();
679681

680682
// Register the cached program as expected for device global memory operation.
681-
auto CtxImpl = sycl::detail::getSyclObjImpl(Q.get_context());
682-
sycl::detail::KernelProgramCache::KernelCacheT &KernelCache =
683-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
683+
using namespace sycl::detail;
684+
context_impl &CtxImpl = *getSyclObjImpl(Q.get_context());
685+
KernelProgramCache::KernelCacheT &KernelCache =
686+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
684687
ASSERT_EQ(KernelCache.size(), (size_t)1)
685688
<< "Expect 1 program in kernel cache";
686689
ExpectedReadWriteURProgram = KernelCache.begin()->first;
@@ -707,9 +710,10 @@ TEST_F(DeviceGlobalTest, DeviceGlobalImgScopeUseBeforeMemcpyFrom) {
707710
Q.single_task<DeviceGlobalImgScopeTestKernel>([]() {}).wait();
708711

709712
// Register the cached program as expected for device global memory operation.
710-
auto CtxImpl = sycl::detail::getSyclObjImpl(Q.get_context());
711-
sycl::detail::KernelProgramCache::KernelCacheT &KernelCache =
712-
CtxImpl->getKernelProgramCache().acquireKernelsPerProgramCache().get();
713+
using namespace sycl::detail;
714+
context_impl &CtxImpl = *getSyclObjImpl(Q.get_context());
715+
KernelProgramCache::KernelCacheT &KernelCache =
716+
CtxImpl.getKernelProgramCache().acquireKernelsPerProgramCache().get();
713717
ASSERT_EQ(KernelCache.size(), (size_t)1)
714718
<< "Expect 1 program in kernel cache";
715719
ExpectedReadWriteURProgram = KernelCache.begin()->first;

sycl/unittests/SYCL2020/KernelBundle.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,17 @@ TEST(KernelBundle, KernelBundleAndItsDevImageStateConsistency) {
107107
auto ObjBundle = sycl::compile(KernelBundle, KernelBundle.get_devices());
108108
EXPECT_FALSE(ObjBundle.empty()) << "Expect non-empty obj kernel bundle";
109109

110-
auto ObjBundleImpl = sycl::detail::getSyclObjImpl(ObjBundle);
111-
EXPECT_EQ(ObjBundleImpl->get_bundle_state(), sycl::bundle_state::object)
110+
sycl::detail::kernel_bundle_impl &ObjBundleImpl =
111+
*sycl::detail::getSyclObjImpl(ObjBundle);
112+
EXPECT_EQ(ObjBundleImpl.get_bundle_state(), sycl::bundle_state::object)
112113
<< "Expect object device image in bundle";
113114

114115
auto LinkBundle = sycl::link(ObjBundle, ObjBundle.get_devices());
115116
EXPECT_FALSE(LinkBundle.empty()) << "Expect non-empty exec kernel bundle";
116117

117-
auto LinkBundleImpl = sycl::detail::getSyclObjImpl(LinkBundle);
118-
EXPECT_EQ(LinkBundleImpl->get_bundle_state(), sycl::bundle_state::executable)
118+
sycl::detail::kernel_bundle_impl &LinkBundleImpl =
119+
*sycl::detail::getSyclObjImpl(LinkBundle);
120+
EXPECT_EQ(LinkBundleImpl.get_bundle_state(), sycl::bundle_state::executable)
119121
<< "Expect executable device image in bundle";
120122
}
121123

sycl/unittests/SYCL2020/SpecializationConstant.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ TEST(SpecializationConstant, DefaultValuesAreSet) {
7474
[&](auto Image) { return Image.has_kernel(TestKernelID); });
7575
EXPECT_NE(DevImage, KernelBundle.end());
7676

77-
auto DevImageImpl = sycl::detail::getSyclObjImpl(*DevImage);
78-
const auto &Blob = DevImageImpl->get_spec_const_blob_ref();
77+
sycl::detail::device_image_impl &DevImageImpl =
78+
*sycl::detail::getSyclObjImpl(*DevImage);
79+
const auto &Blob = DevImageImpl.get_spec_const_blob_ref();
7980

8081
int SpecConstVal1 = *reinterpret_cast<const int *>(Blob.data());
8182
int SpecConstVal2 = *(reinterpret_cast<const int *>(Blob.data()) + 1);
@@ -103,8 +104,9 @@ TEST(SpecializationConstant, DefaultValuesAreOverriden) {
103104
[&](auto Image) { return Image.has_kernel(TestKernelID); });
104105
EXPECT_NE(DevImage, KernelBundle.end());
105106

106-
auto DevImageImpl = sycl::detail::getSyclObjImpl(*DevImage);
107-
auto &Blob = DevImageImpl->get_spec_const_blob_ref();
107+
sycl::detail::device_image_impl &DevImageImpl =
108+
*sycl::detail::getSyclObjImpl(*DevImage);
109+
auto &Blob = DevImageImpl.get_spec_const_blob_ref();
108110
int SpecConstVal1 = *reinterpret_cast<int *>(Blob.data());
109111
int SpecConstVal2 = *(reinterpret_cast<int *>(Blob.data()) + 1);
110112

sycl/unittests/buffer/BufferLocation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ TEST_F(BufferTest, BufferLocationWithAnotherProp) {
181181
Acc{Buf, cgh, sycl::write_only, PL};
182182
})
183183
.wait();
184-
std::shared_ptr<sycl::detail::buffer_impl> BufImpl =
185-
sycl::detail::getSyclObjImpl(Buf);
184+
sycl::detail::buffer_impl &BufImpl = *sycl::detail::getSyclObjImpl(Buf);
186185
EXPECT_EQ(
187-
BufImpl->get_property<sycl::property::buffer::detail::buffer_location>()
186+
BufImpl.get_property<sycl::property::buffer::detail::buffer_location>()
188187
.get_buffer_location(),
189188
(uint64_t)3);
190189

@@ -200,7 +199,7 @@ TEST_F(BufferTest, BufferLocationWithAnotherProp) {
200199
.wait();
201200

202201
EXPECT_EQ(
203-
BufImpl->has_property<sycl::property::buffer::detail::buffer_location>(),
202+
BufImpl.has_property<sycl::property::buffer::detail::buffer_location>(),
204203
0);
205204
}
206205

sycl/unittests/buffer/BufferReleaseBase.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ TEST_F(BufferDestructionCheck, BufferWithSizeOnlyDefault) {
2020
sycl::detail::buffer_impl *RawBufferImplPtr = NULL;
2121
{
2222
sycl::buffer<int, 1> Buf(1);
23-
std::shared_ptr<sycl::detail::buffer_impl> BufImpl =
24-
sycl::detail::getSyclObjImpl(Buf);
25-
RawBufferImplPtr = BufImpl.get();
23+
RawBufferImplPtr = &*sycl::detail::getSyclObjImpl(Buf);
2624
MockCmd = addCommandToBuffer(Buf, Q);
2725
}
2826
ASSERT_EQ(MockSchedulerPtr->MDeferredMemObjRelease.size(), 1u);
@@ -57,9 +55,7 @@ TEST_F(BufferDestructionCheck, BufferWithSizeOnlyNonDefaultAllocator) {
5755
sycl::usm_allocator<int, sycl::usm::alloc::shared>;
5856
AllocatorTypeTest allocator(Q);
5957
sycl::buffer<int, 1, AllocatorTypeTest> Buf(1, allocator);
60-
std::shared_ptr<sycl::detail::buffer_impl> BufImpl =
61-
sycl::detail::getSyclObjImpl(Buf);
62-
RawBufferImplPtr = BufImpl.get();
58+
RawBufferImplPtr = &*sycl::detail::getSyclObjImpl(Buf);
6359
MockCmd = addCommandToBuffer(Buf, Q);
6460
EXPECT_CALL(*MockCmd, Release).Times(1);
6561
}
@@ -78,9 +74,7 @@ TEST_F(BufferDestructionCheck, BufferWithSizeOnlyDefaultAllocator) {
7874
using AllocatorTypeTest = sycl::buffer_allocator<int>;
7975
AllocatorTypeTest allocator;
8076
sycl::buffer<int, 1, AllocatorTypeTest> Buf(1, allocator);
81-
std::shared_ptr<sycl::detail::buffer_impl> BufImpl =
82-
sycl::detail::getSyclObjImpl(Buf);
83-
RawBufferImplPtr = BufImpl.get();
77+
RawBufferImplPtr = &*sycl::detail::getSyclObjImpl(Buf);
8478
MockCmd = addCommandToBuffer(Buf, Q);
8579
EXPECT_CALL(*MockCmd, Release).Times(1);
8680
}
@@ -185,9 +179,7 @@ TEST_F(BufferDestructionCheck, BufferWithIterators) {
185179
{
186180
std::vector<int> data{3, 4};
187181
sycl::buffer<int, 1> Buf(data.begin(), data.end());
188-
std::shared_ptr<sycl::detail::buffer_impl> BufImpl =
189-
sycl::detail::getSyclObjImpl(Buf);
190-
RawBufferImplPtr = BufImpl.get();
182+
RawBufferImplPtr = &*sycl::detail::getSyclObjImpl(Buf);
191183
MockCmd = addCommandToBuffer(Buf, Q);
192184
EXPECT_CALL(*MockCmd, Release).Times(1);
193185
}
@@ -218,10 +210,8 @@ TEST_F(BufferDestructionCheck, ReadyToReleaseLogic) {
218210
sycl::buffer<int, 1> Buf(1);
219211
sycl::detail::Requirement MockReq = getMockRequirement(Buf);
220212
sycl::detail::MemObjRecord *Rec = MockSchedulerPtr->getOrInsertMemObjRecord(
221-
sycl::detail::getSyclObjImpl(Q).get(), &MockReq);
213+
&*sycl::detail::getSyclObjImpl(Q), &MockReq);
222214

223-
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
224-
sycl::detail::getSyclObjImpl(Context);
225215
MockCmdWithReleaseTracking *ReadCmd = nullptr;
226216
MockCmdWithReleaseTracking *WriteCmd = nullptr;
227217
ReadCmd =

sycl/unittests/buffer/BufferReleaseBase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BufferDestructionCheckCommon : public ::testing::Test {
5454
MockCmdWithReleaseTracking *addCommandToBuffer(Buffer &Buf, sycl::queue &Q) {
5555
sycl::detail::Requirement MockReq = getMockRequirement(Buf);
5656
sycl::detail::MemObjRecord *Rec = MockSchedulerPtr->getOrInsertMemObjRecord(
57-
sycl::detail::getSyclObjImpl(Q).get(), &MockReq);
57+
&*sycl::detail::getSyclObjImpl(Q), &MockReq);
5858
MockCmdWithReleaseTracking *MockCmd = new MockCmdWithReleaseTracking(
5959
*sycl::detail::getSyclObjImpl(Q), MockReq);
6060
std::vector<sycl::detail::Command *> ToEnqueue;

sycl/unittests/queue/Wait.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ TEST(QueueWait, QueueWaitTest) {
123123
event DepEvent = submitTask(Q, Buf);
124124

125125
// Manually block the next commands.
126-
std::shared_ptr<detail::event_impl> DepEventImpl =
127-
detail::getSyclObjImpl(DepEvent);
128-
auto *Cmd = static_cast<detail::Command *>(DepEventImpl->getCommand());
126+
detail::event_impl &DepEventImpl = *detail::getSyclObjImpl(DepEvent);
127+
auto *Cmd = static_cast<detail::Command *>(DepEventImpl.getCommand());
129128
Cmd->MIsBlockable = true;
130129
Cmd->MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked;
131130

0 commit comments

Comments
 (0)