Skip to content

[NFC][SYCL] Pass queue_impl by raw ptr/ref in misc files #19006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sycl/source/detail/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class event;
namespace detail {
class CGExecKernel;
class queue_impl;
using QueueImplPtr = std::shared_ptr<sycl::detail::queue_impl>;
class RTDeviceBinaryImage;

#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
Expand Down
1 change: 0 additions & 1 deletion sycl/source/detail/memory_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class queue_impl;
class event_impl;
class context_impl;

using QueueImplPtr = std::shared_ptr<detail::queue_impl>;
using EventImplPtr = std::shared_ptr<detail::event_impl>;

// The class contains methods that work with memory. All operations with
Expand Down
23 changes: 11 additions & 12 deletions sycl/source/enqueue_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@ namespace ext::oneapi::experimental {

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

__SYCL_EXPORT void memset(queue Q, void *Ptr, int Value, size_t NumBytes,
const sycl::detail::code_location &CodeLoc) {
sycl::detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
auto QueueImplPtr = sycl::detail::getSyclObjImpl(Q);
QueueImplPtr->memset(Ptr, Value, NumBytes, {},
/*CallerNeedsEvent=*/false);
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
detail::getSyclObjImpl(Q)->memset(Ptr, Value, NumBytes, {},
/*CallerNeedsEvent=*/false);
}

__SYCL_EXPORT void mem_advise(queue Q, void *Ptr, size_t NumBytes, int Advice,
const sycl::detail::code_location &CodeLoc) {
sycl::detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
auto QueueImplPtr = sycl::detail::getSyclObjImpl(Q);
QueueImplPtr->mem_advise(Ptr, NumBytes, ur_usm_advice_flags_t(Advice), {},
/*CallerNeedsEvent=*/false);
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
detail::getSyclObjImpl(Q)->mem_advise(Ptr, NumBytes,
ur_usm_advice_flags_t(Advice), {},
/*CallerNeedsEvent=*/false);
}

} // namespace ext::oneapi::experimental
Expand Down
21 changes: 10 additions & 11 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ void queue::wait_and_throw_proxy(const detail::code_location &CodeLoc) {
}

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

sycl::detail::optional<event> LastEvent = QueueImpl->getLastEvent();
sycl::detail::optional<event> LastEvent = QueueImpl.getLastEvent();
if (LastEvent)
return *LastEvent;

Expand All @@ -353,11 +353,7 @@ getBarrierEventForInorderQueueHelper(const detail::QueueImplPtr QueueImpl) {
/// \return a SYCL event object, which corresponds to the queue the command
/// group is being enqueued on.
event queue::ext_oneapi_submit_barrier(const detail::code_location &CodeLoc) {
if (is_in_order() && !impl->hasCommandGraph() && !impl->MIsProfilingEnabled) {
return getBarrierEventForInorderQueueHelper(impl);
}

return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
return ext_oneapi_submit_barrier(std::vector<event>{}, CodeLoc);
}

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

return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(WaitList); },
CodeLoc);
if (WaitList.empty())
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
else
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(WaitList); },
CodeLoc);
}

template <typename Param>
Expand Down
28 changes: 12 additions & 16 deletions sycl/unittests/Extensions/USMMemcpy2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
sycl::platform Plt = sycl::platform();
sycl::queue Q{Plt.get_devices()[0]};

std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
sycl::detail::getSyclObjImpl(Q);
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);

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

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

Q.ext_oneapi_memset2d(Ptr1, 5 * sizeof(long), 123, 4 * sizeof(long), 2);
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
EXPECT_EQ(LastFill2D.hQueue, (ur_queue_handle_t)QueueImpl->getHandleRef());
EXPECT_EQ(LastFill2D.hQueue, (ur_queue_handle_t)QueueImpl.getHandleRef());
EXPECT_EQ(LastFill2D.pMem, (void *)Ptr1);
EXPECT_EQ(LastFill2D.pitch, (size_t)5 * sizeof(long));
EXPECT_EQ(LastFill2D.pattern[0], 123);
Expand All @@ -316,7 +315,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {
Q.ext_oneapi_memcpy2d(Ptr1, 5 * sizeof(long), Ptr2, 8 * sizeof(long),
4 * sizeof(long), 2);
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
EXPECT_EQ(LastMemcpy2D.hQueue, (ur_queue_handle_t)QueueImpl->getHandleRef());
EXPECT_EQ(LastMemcpy2D.hQueue, (ur_queue_handle_t)QueueImpl.getHandleRef());
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr1);
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)5 * sizeof(long));
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr2);
Expand All @@ -326,7 +325,7 @@ TEST(USMMemcpy2DTest, USMMemops2DSupported) {

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

std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
sycl::detail::getSyclObjImpl(Q);
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);

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

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

std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
sycl::detail::getSyclObjImpl(Q);
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);

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

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

std::shared_ptr<sycl::detail::queue_impl> QueueImpl =
sycl::detail::getSyclObjImpl(Q);
sycl::detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(Q);

mock::getCallbacks().set_after_callback(
"urContextGetInfo", &after_urContextGetInfo<false, false, true>);
Expand Down Expand Up @@ -505,7 +501,7 @@ TEST(USMMemcpy2DTest, USMMemcpySupportedOnly) {
Q.ext_oneapi_memcpy2d(Ptr1, 5 * sizeof(long), Ptr2, 8 * sizeof(long),
4 * sizeof(long), 2);
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl->getHandleRef());
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl.getHandleRef());
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr1);
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)5 * sizeof(long));
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr2);
Expand All @@ -516,7 +512,7 @@ TEST(USMMemcpy2DTest, USMMemcpySupportedOnly) {

Q.ext_oneapi_copy2d(Ptr1, 5, Ptr2, 8, 4, 2);
EXPECT_TRUE(LastMemopsQuery == UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl->getHandleRef());
EXPECT_EQ(LastMemcpy2D.hQueue, QueueImpl.getHandleRef());
EXPECT_EQ(LastMemcpy2D.pDst, (void *)Ptr2);
EXPECT_EQ(LastMemcpy2D.dstPitch, (size_t)8 * sizeof(long));
EXPECT_EQ(LastMemcpy2D.pSrc, (void *)Ptr1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class MockHandler : public sycl::handler {
public:
using sycl::handler::impl;

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

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

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

Expand Down