Skip to content

Commit 51aeea6

Browse files
[NFC][SYCL] Pass queue_impl by raw ptr/ref in misc files (#19006)
Continuation of the refactoring efforts in #18715 #18748 #18830 #18907 #18983
1 parent c023eb4 commit 51aeea6

File tree

6 files changed

+36
-44
lines changed

6 files changed

+36
-44
lines changed

sycl/source/detail/helpers.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class event;
2121
namespace detail {
2222
class CGExecKernel;
2323
class queue_impl;
24-
using QueueImplPtr = std::shared_ptr<sycl::detail::queue_impl>;
2524
class RTDeviceBinaryImage;
2625

2726
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES

sycl/source/detail/memory_manager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class queue_impl;
2828
class event_impl;
2929
class context_impl;
3030

31-
using QueueImplPtr = std::shared_ptr<detail::queue_impl>;
3231
using EventImplPtr = std::shared_ptr<detail::event_impl>;
3332

3433
// The class contains methods that work with memory. All operations with

sycl/source/enqueue_functions.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@ namespace ext::oneapi::experimental {
1515

1616
__SYCL_EXPORT void memcpy(queue Q, void *Dest, const void *Src, size_t NumBytes,
1717
const sycl::detail::code_location &CodeLoc) {
18-
sycl::detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
19-
auto QueueImplPtr = sycl::detail::getSyclObjImpl(Q);
20-
QueueImplPtr->memcpy(Dest, Src, NumBytes, {},
21-
/*CallerNeedsEvent=*/false, TlsCodeLocCapture.query());
18+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
19+
detail::getSyclObjImpl(Q)->memcpy(Dest, Src, NumBytes, {},
20+
/*CallerNeedsEvent=*/false,
21+
TlsCodeLocCapture.query());
2222
}
2323

2424
__SYCL_EXPORT void memset(queue Q, void *Ptr, int Value, size_t NumBytes,
2525
const sycl::detail::code_location &CodeLoc) {
26-
sycl::detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
27-
auto QueueImplPtr = sycl::detail::getSyclObjImpl(Q);
28-
QueueImplPtr->memset(Ptr, Value, NumBytes, {},
29-
/*CallerNeedsEvent=*/false);
26+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
27+
detail::getSyclObjImpl(Q)->memset(Ptr, Value, NumBytes, {},
28+
/*CallerNeedsEvent=*/false);
3029
}
3130

3231
__SYCL_EXPORT void mem_advise(queue Q, void *Ptr, size_t NumBytes, int Advice,
3332
const sycl::detail::code_location &CodeLoc) {
34-
sycl::detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
35-
auto QueueImplPtr = sycl::detail::getSyclObjImpl(Q);
36-
QueueImplPtr->mem_advise(Ptr, NumBytes, ur_usm_advice_flags_t(Advice), {},
37-
/*CallerNeedsEvent=*/false);
33+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
34+
detail::getSyclObjImpl(Q)->mem_advise(Ptr, NumBytes,
35+
ur_usm_advice_flags_t(Advice), {},
36+
/*CallerNeedsEvent=*/false);
3837
}
3938

4039
} // namespace ext::oneapi::experimental

sycl/source/queue.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ void queue::wait_and_throw_proxy(const detail::code_location &CodeLoc) {
328328
}
329329

330330
static event
331-
getBarrierEventForInorderQueueHelper(const detail::QueueImplPtr QueueImpl) {
331+
getBarrierEventForInorderQueueHelper(detail::queue_impl &QueueImpl) {
332332
// This function should not be called when a queue is recording to a graph,
333333
// as a graph can record from multiple queues and we cannot guarantee the
334334
// last node added by an in-order queue will be the last node added to the
335335
// graph.
336-
assert(!QueueImpl->hasCommandGraph() &&
336+
assert(!QueueImpl.hasCommandGraph() &&
337337
"Should not be called in on graph recording.");
338338

339-
sycl::detail::optional<event> LastEvent = QueueImpl->getLastEvent();
339+
sycl::detail::optional<event> LastEvent = QueueImpl.getLastEvent();
340340
if (LastEvent)
341341
return *LastEvent;
342342

@@ -353,11 +353,7 @@ getBarrierEventForInorderQueueHelper(const detail::QueueImplPtr QueueImpl) {
353353
/// \return a SYCL event object, which corresponds to the queue the command
354354
/// group is being enqueued on.
355355
event queue::ext_oneapi_submit_barrier(const detail::code_location &CodeLoc) {
356-
if (is_in_order() && !impl->hasCommandGraph() && !impl->MIsProfilingEnabled) {
357-
return getBarrierEventForInorderQueueHelper(impl);
358-
}
359-
360-
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
356+
return ext_oneapi_submit_barrier(std::vector<event>{}, CodeLoc);
361357
}
362358

363359
/// Prevents any commands submitted afterward to this queue from executing
@@ -379,11 +375,14 @@ event queue::ext_oneapi_submit_barrier(const std::vector<event> &WaitList,
379375
});
380376
if (is_in_order() && !impl->hasCommandGraph() && !impl->MIsProfilingEnabled &&
381377
AllEventsEmptyOrNop) {
382-
return getBarrierEventForInorderQueueHelper(impl);
378+
return getBarrierEventForInorderQueueHelper(*impl);
383379
}
384380

385-
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(WaitList); },
386-
CodeLoc);
381+
if (WaitList.empty())
382+
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
383+
else
384+
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(WaitList); },
385+
CodeLoc);
387386
}
388387

389388
template <typename Param>

sycl/unittests/Extensions/USMMemcpy2D.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
280280
sycl::platform Plt = sycl::platform();
281281
sycl::queue Q{Plt.get_devices()[0]};
282282

283-
std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
284-
sycl::detail::getSyclObjImpl(Q);
283+
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);
285284

286285
mock::getCallbacks().set_after_callback(
287286
"urContextGetInfo", &after_urContextGetInfo<true, true, true>);
@@ -297,7 +296,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
297296

298297
Q.ext_oneapi_fill2d(Ptr1, 5, 42l, 4, 2);
299298
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
300-
EXPECT_EQ(LastFill2D.hQueue, (ur_queue_handle_t)QueueImpl->getHandleRef());
299+
EXPECT_EQ(LastFill2D.hQueue, (ur_queue_handle_t)QueueImpl.getHandleRef());
301300
EXPECT_EQ(LastFill2D.pMem, (void *)Ptr1);
302301
EXPECT_EQ(LastFill2D.pitch, (size_t)5);
303302
EXPECT_EQ(LastFill2D.patternSize, sizeof(long));
@@ -306,7 +305,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
306305

307306
Q.ext_oneapi_memset2d(Ptr1, 5 * sizeof(long), 123, 4 * sizeof(long), 2);
308307
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
309-
EXPECT_EQ(LastFill2D.hQueue, (ur_queue_handle_t)QueueImpl->getHandleRef());
308+
EXPECT_EQ(LastFill2D.hQueue, (ur_queue_handle_t)QueueImpl.getHandleRef());
310309
EXPECT_EQ(LastFill2D.pMem, (void *)Ptr1);
311310
EXPECT_EQ(LastFill2D.pitch, (size_t)5 * sizeof(long));
312311
EXPECT_EQ(LastFill2D.pattern[0], 123);
@@ -316,7 +315,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
316315
Q.ext_oneapi_memcpy2d(Ptr1, 5 * sizeof(long), Ptr2, 8 * sizeof(long),
317316
4 * sizeof(long), 2);
318317
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
319-
EXPECT_EQ(LastMemcpy2D.hQueue, (ur_queue_handle_t)QueueImpl->getHandleRef());
318+
EXPECT_EQ(LastMemcpy2D.hQueue, (ur_queue_handle_t)QueueImpl.getHandleRef());
320319
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr1);
321320
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)5 * sizeof(long));
322321
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr2);
@@ -326,7 +325,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
326325

327326
Q.ext_oneapi_copy2d(Ptr1, 5, Ptr2, 8, 4, 2);
328327
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
329-
EXPECT_EQ(LastMemcpy2D.hQueue, (ur_queue_handle_t)QueueImpl->getHandleRef());
328+
EXPECT_EQ(LastMemcpy2D.hQueue, (ur_queue_handle_t)QueueImpl.getHandleRef());
330329
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr2);
331330
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)8 * sizeof(long));
332331
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr1);
@@ -381,8 +380,7 @@ TEST(USMMemcpy2DTest, USMFillSupportedOnly) {
381380
sycl::platform Plt = sycl::platform();
382381
sycl::queue Q{Plt.get_devices()[0]};
383382

384-
std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
385-
sycl::detail::getSyclObjImpl(Q);
383+
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);
386384

387385
mock::getCallbacks().set_after_callback(
388386
"urContextGetInfo", &after_urContextGetInfo<true, false, false>);
@@ -402,7 +400,7 @@ TEST(USMMemcpy2DTest, USMFillSupportedOnly) {
402400

403401
Q.ext_oneapi_fill2d(Ptr1, 5, 42l, 4, 2);
404402
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
405-
EXPECT_EQ(LastFill2D.hQueue, QueueImpl->getHandleRef());
403+
EXPECT_EQ(LastFill2D.hQueue, QueueImpl.getHandleRef());
406404
EXPECT_EQ(LastFill2D.pMem, (void *)Ptr1);
407405
EXPECT_EQ(LastFill2D.pitch, (size_t)5);
408406
EXPECT_EQ(LastFill2D.patternSize, sizeof(long));
@@ -427,8 +425,7 @@ TEST(USMMemcpy2DTest, USMMemsetSupportedOnly) {
427425
sycl::platform Plt = sycl::platform();
428426
sycl::queue Q{Plt.get_devices()[0]};
429427

430-
std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
431-
sycl::detail::getSyclObjImpl(Q);
428+
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);
432429

433430
// Enable fill + set, they are implemented with the same entry point in the
434431
// backend so supporting one means supporting both.
@@ -450,7 +447,7 @@ TEST(USMMemcpy2DTest, USMMemsetSupportedOnly) {
450447

451448
Q.ext_oneapi_memset2d(Ptr1, 5 * sizeof(long), 123, 4 * sizeof(long), 2);
452449
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
453-
EXPECT_EQ(LastFill2D.hQueue, QueueImpl->getHandleRef());
450+
EXPECT_EQ(LastFill2D.hQueue, QueueImpl.getHandleRef());
454451
EXPECT_EQ(LastFill2D.pMem, (void *)Ptr1);
455452
EXPECT_EQ(LastFill2D.pitch, (size_t)5 * sizeof(long));
456453
EXPECT_EQ(LastFill2D.pattern[0], 123);
@@ -475,8 +472,7 @@ TEST(USMMemcpy2DTest, USMMemcpySupportedOnly) {
475472
sycl::platform Plt = sycl::platform();
476473
sycl::queue Q{Plt.get_devices()[0]};
477474

478-
std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
479-
sycl::detail::getSyclObjImpl(Q);
475+
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);
480476

481477
mock::getCallbacks().set_after_callback(
482478
"urContextGetInfo", &after_urContextGetInfo<false, false, true>);
@@ -505,7 +501,7 @@ TEST(USMMemcpy2DTest, USMMemcpySupportedOnly) {
505501
Q.ext_oneapi_memcpy2d(Ptr1, 5 * sizeof(long), Ptr2, 8 * sizeof(long),
506502
4 * sizeof(long), 2);
507503
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
508-
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl->getHandleRef());
504+
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl.getHandleRef());
509505
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr1);
510506
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)5 * sizeof(long));
511507
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr2);
@@ -516,7 +512,7 @@ TEST(USMMemcpy2DTest, USMMemcpySupportedOnly) {
516512

517513
Q.ext_oneapi_copy2d(Ptr1, 5, Ptr2, 8, 4, 2);
518514
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
519-
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl->getHandleRef());
515+
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl.getHandleRef());
520516
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr2);
521517
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)8 * sizeof(long));
522518
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr1);

sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class MockHandler : public sycl::handler {
135135
public:
136136
using sycl::handler::impl;
137137

138-
MockHandler(std::shared_ptr<sycl::detail::queue_impl> Queue)
139-
: sycl::handler(Queue, /*CallerNeedsEvent*/ true) {}
138+
MockHandler(sycl::detail::queue_impl &Queue)
139+
: sycl::handler(Queue.shared_from_this(), /*CallerNeedsEvent*/ true) {}
140140

141141
std::unique_ptr<sycl::detail::CG> finalize() {
142142
auto CGH = static_cast<sycl::handler *>(this);
@@ -171,7 +171,7 @@ const sycl::detail::KernelArgMask *getKernelArgMaskFromBundle(
171171
EXPECT_FALSE(ExecBundle.empty()) << "Expect non-empty exec kernel bundle";
172172

173173
// Emulating processing of command group function
174-
MockHandler MockCGH(QueueImpl);
174+
MockHandler MockCGH(*QueueImpl);
175175
MockCGH.use_kernel_bundle(ExecBundle);
176176
MockCGH.single_task<EAMTestKernel>([] {}); // Actual kernel does not matter
177177

0 commit comments

Comments
 (0)