Skip to content

Commit 653efa8

Browse files
Use DPCTLQueue_CreateForDevice instead of wrapping sycl::queue pointer
1 parent ff104ad commit 653efa8

File tree

1 file changed

+87
-36
lines changed

1 file changed

+87
-36
lines changed

libsyclinterface/tests/test_sycl_usm_interface.cpp

Lines changed: 87 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,74 +94,125 @@ struct TestDPCTLSyclUSMInterface : public ::testing::Test
9494

9595
TEST_F(TestDPCTLSyclUSMInterface, MallocShared)
9696
{
97-
sycl::queue q;
98-
DPCTLSyclQueueRef Q = dpctl::syclinterface::wrap<sycl::queue>(&q);
99-
ASSERT_TRUE(Q);
97+
DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create();
98+
ASSERT_TRUE(DSRef);
99+
DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef);
100+
DPCTLDeviceSelector_Delete(DSRef);
101+
ASSERT_TRUE(DRef);
102+
DPCTLSyclQueueRef QRef =
103+
DPCTLQueue_CreateForDevice(DRef, NULL, DPCTL_DEFAULT_PROPERTY);
104+
DPCTLDevice_Delete(DRef);
105+
ASSERT_TRUE(QRef);
106+
100107
const size_t nbytes = SIZE;
101-
auto Ptr = DPCTLmalloc_shared(nbytes, Q);
108+
auto Ptr = DPCTLmalloc_shared(nbytes, QRef);
102109
EXPECT_TRUE(bool(Ptr));
103-
common_test_body(nbytes, Ptr, Q, DPCTLSyclUSMType::DPCTL_USM_SHARED);
104-
DPCTLfree_with_queue(Ptr, Q);
110+
common_test_body(nbytes, Ptr, QRef, DPCTLSyclUSMType::DPCTL_USM_SHARED);
111+
DPCTLfree_with_queue(Ptr, QRef);
112+
113+
DPCTLQueue_Delete(QRef);
105114
}
106115

107116
TEST_F(TestDPCTLSyclUSMInterface, MallocDevice)
108117
{
109-
sycl::queue q;
110-
DPCTLSyclQueueRef Q = dpctl::syclinterface::wrap<sycl::queue>(&q);
111-
ASSERT_TRUE(Q);
118+
DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create();
119+
ASSERT_TRUE(DSRef);
120+
DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef);
121+
DPCTLDeviceSelector_Delete(DSRef);
122+
ASSERT_TRUE(DRef);
123+
DPCTLSyclQueueRef QRef =
124+
DPCTLQueue_CreateForDevice(DRef, NULL, DPCTL_DEFAULT_PROPERTY);
125+
DPCTLDevice_Delete(DRef);
126+
ASSERT_TRUE(QRef);
127+
112128
const size_t nbytes = SIZE;
113-
auto Ptr = DPCTLmalloc_device(nbytes, Q);
129+
auto Ptr = DPCTLmalloc_device(nbytes, QRef);
114130
EXPECT_TRUE(bool(Ptr));
115-
common_test_body(nbytes, Ptr, Q, DPCTLSyclUSMType::DPCTL_USM_DEVICE);
116-
DPCTLfree_with_queue(Ptr, Q);
131+
common_test_body(nbytes, Ptr, QRef, DPCTLSyclUSMType::DPCTL_USM_DEVICE);
132+
DPCTLfree_with_queue(Ptr, QRef);
133+
134+
DPCTLQueue_Delete(QRef);
117135
}
118136

119137
TEST_F(TestDPCTLSyclUSMInterface, MallocHost)
120138
{
121-
sycl::queue q;
122-
DPCTLSyclQueueRef Q = dpctl::syclinterface::wrap<sycl::queue>(&q);
123-
ASSERT_TRUE(Q);
139+
DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create();
140+
ASSERT_TRUE(DSRef);
141+
DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef);
142+
DPCTLDeviceSelector_Delete(DSRef);
143+
ASSERT_TRUE(DRef);
144+
DPCTLSyclQueueRef QRef =
145+
DPCTLQueue_CreateForDevice(DRef, NULL, DPCTL_DEFAULT_PROPERTY);
146+
DPCTLDevice_Delete(DRef);
147+
ASSERT_TRUE(QRef);
148+
124149
const size_t nbytes = SIZE;
125-
auto Ptr = DPCTLmalloc_host(nbytes, Q);
150+
auto Ptr = DPCTLmalloc_host(nbytes, QRef);
126151
EXPECT_TRUE(bool(Ptr));
127-
common_test_body(nbytes, Ptr, Q, DPCTLSyclUSMType::DPCTL_USM_HOST);
128-
DPCTLfree_with_queue(Ptr, Q);
152+
common_test_body(nbytes, Ptr, QRef, DPCTLSyclUSMType::DPCTL_USM_HOST);
153+
DPCTLfree_with_queue(Ptr, QRef);
154+
DPCTLQueue_Delete(QRef);
129155
}
130156

131157
TEST_F(TestDPCTLSyclUSMInterface, AlignedAllocShared)
132158
{
133-
sycl::queue q;
134-
DPCTLSyclQueueRef Q = dpctl::syclinterface::wrap<sycl::queue>(&q);
135-
ASSERT_TRUE(Q);
159+
DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create();
160+
ASSERT_TRUE(DSRef);
161+
DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef);
162+
DPCTLDeviceSelector_Delete(DSRef);
163+
ASSERT_TRUE(DRef);
164+
DPCTLSyclQueueRef QRef =
165+
DPCTLQueue_CreateForDevice(DRef, NULL, DPCTL_DEFAULT_PROPERTY);
166+
DPCTLDevice_Delete(DRef);
167+
ASSERT_TRUE(QRef);
168+
136169
const size_t nbytes = SIZE;
137-
auto Ptr = DPCTLaligned_alloc_shared(64, nbytes, Q);
170+
auto Ptr = DPCTLaligned_alloc_shared(64, nbytes, QRef);
138171
EXPECT_TRUE(bool(Ptr));
139-
common_test_body(nbytes, Ptr, Q, DPCTLSyclUSMType::DPCTL_USM_SHARED);
140-
DPCTLfree_with_queue(Ptr, Q);
172+
common_test_body(nbytes, Ptr, QRef, DPCTLSyclUSMType::DPCTL_USM_SHARED);
173+
DPCTLfree_with_queue(Ptr, QRef);
174+
DPCTLQueue_Delete(QRef);
141175
}
142176

143177
TEST_F(TestDPCTLSyclUSMInterface, AlignedAllocDevice)
144178
{
145-
sycl::queue q;
146-
DPCTLSyclQueueRef Q = dpctl::syclinterface::wrap<sycl::queue>(&q);
147-
ASSERT_TRUE(Q);
179+
DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create();
180+
ASSERT_TRUE(DSRef);
181+
DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef);
182+
DPCTLDeviceSelector_Delete(DSRef);
183+
ASSERT_TRUE(DRef);
184+
DPCTLSyclQueueRef QRef =
185+
DPCTLQueue_CreateForDevice(DRef, NULL, DPCTL_DEFAULT_PROPERTY);
186+
DPCTLDevice_Delete(DRef);
187+
ASSERT_TRUE(QRef);
188+
148189
const size_t nbytes = SIZE;
149-
auto Ptr = DPCTLaligned_alloc_device(64, nbytes, Q);
190+
auto Ptr = DPCTLaligned_alloc_device(64, nbytes, QRef);
150191
EXPECT_TRUE(bool(Ptr));
151-
common_test_body(nbytes, Ptr, Q, DPCTLSyclUSMType::DPCTL_USM_DEVICE);
152-
DPCTLfree_with_queue(Ptr, Q);
192+
common_test_body(nbytes, Ptr, QRef, DPCTLSyclUSMType::DPCTL_USM_DEVICE);
193+
DPCTLfree_with_queue(Ptr, QRef);
194+
DPCTLQueue_Delete(QRef);
153195
}
154196

155197
TEST_F(TestDPCTLSyclUSMInterface, AlignedAllocHost)
156198
{
157-
sycl::queue q;
158-
DPCTLSyclQueueRef Q = dpctl::syclinterface::wrap<sycl::queue>(&q);
159-
ASSERT_TRUE(Q);
199+
DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create();
200+
ASSERT_TRUE(DSRef);
201+
DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef);
202+
DPCTLDeviceSelector_Delete(DSRef);
203+
ASSERT_TRUE(DRef);
204+
DPCTLSyclQueueRef QRef =
205+
DPCTLQueue_CreateForDevice(DRef, NULL, DPCTL_DEFAULT_PROPERTY);
206+
DPCTLDevice_Delete(DRef);
207+
ASSERT_TRUE(QRef);
208+
160209
const size_t nbytes = SIZE;
161-
auto Ptr = DPCTLaligned_alloc_host(64, nbytes, Q);
210+
auto Ptr = DPCTLaligned_alloc_host(64, nbytes, QRef);
162211
EXPECT_TRUE(bool(Ptr));
163-
common_test_body(nbytes, Ptr, Q, DPCTLSyclUSMType::DPCTL_USM_HOST);
164-
DPCTLfree_with_queue(Ptr, Q);
212+
common_test_body(nbytes, Ptr, QRef, DPCTLSyclUSMType::DPCTL_USM_HOST);
213+
DPCTLfree_with_queue(Ptr, QRef);
214+
215+
DPCTLQueue_Delete(QRef);
165216
}
166217

167218
struct TestDPCTLSyclUSMNullArgs : public ::testing::Test

0 commit comments

Comments
 (0)