Skip to content

[SYCL] Remove secondary submission queue from handler #17967

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 6 commits into from
Apr 15, 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
10 changes: 1 addition & 9 deletions sycl/source/detail/handler_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ enum class HandlerSubmissionState : std::uint8_t {

class handler_impl {
public:
handler_impl(queue_impl *SubmissionPrimaryQueue,
queue_impl *SubmissionSecondaryQueue, bool EventNeeded)
handler_impl(queue_impl *SubmissionPrimaryQueue, bool EventNeeded)
: MSubmissionPrimaryQueue(SubmissionPrimaryQueue),
MSubmissionSecondaryQueue(SubmissionSecondaryQueue),
MEventNeeded(EventNeeded) {};

handler_impl(
Expand Down Expand Up @@ -74,12 +72,6 @@ class handler_impl {
/// a fallback from a previous submission.
queue_impl *MSubmissionPrimaryQueue = nullptr;

/// Shared pointer to the secondary queue implementation. Nullptr if no
/// secondary queue fallback was given in the associated submission. This is
/// equal to the queue associated with the handler if the corresponding
/// submission is a fallback from a previous submission.
queue_impl *MSubmissionSecondaryQueue = nullptr;

/// Bool stores information about whether the event resulting from the
/// corresponding work is required.
bool MEventNeeded = true;
Expand Down
66 changes: 27 additions & 39 deletions sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,28 @@ fill_copy_args(detail::handler_impl *impl,

handler::handler(std::shared_ptr<detail::queue_impl> Queue,
bool CallerNeedsEvent)
: impl(std::make_shared<detail::handler_impl>(Queue.get(), nullptr,
: impl(std::make_shared<detail::handler_impl>(Queue.get(),
CallerNeedsEvent)),
MQueue(Queue) {}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
// TODO: This function is not used anymore, remove it in the next
// ABI-breaking window.
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
std::shared_ptr<detail::queue_impl> PrimaryQueue,
std::shared_ptr<detail::queue_impl> SecondaryQueue,
bool CallerNeedsEvent)
: impl(std::make_shared<detail::handler_impl>(
PrimaryQueue.get(), SecondaryQueue.get(), CallerNeedsEvent)),
handler::handler(
std::shared_ptr<detail::queue_impl> Queue,
std::shared_ptr<detail::queue_impl> PrimaryQueue,
[[maybe_unused]] std::shared_ptr<detail::queue_impl> SecondaryQueue,
bool CallerNeedsEvent)
: impl(std::make_shared<detail::handler_impl>(PrimaryQueue.get(),
CallerNeedsEvent)),
MQueue(Queue) {}
#endif

handler::handler(std::shared_ptr<detail::queue_impl> Queue,
detail::queue_impl *PrimaryQueue,
detail::queue_impl *SecondaryQueue, bool CallerNeedsEvent)
: impl(std::make_shared<detail::handler_impl>(PrimaryQueue, SecondaryQueue,
[[maybe_unused]] detail::queue_impl *SecondaryQueue,
bool CallerNeedsEvent)
: impl(std::make_shared<detail::handler_impl>(PrimaryQueue,
CallerNeedsEvent)),
MQueue(std::move(Queue)) {}

Expand Down Expand Up @@ -1775,14 +1777,6 @@ void handler::use_kernel_bundle(
"Context associated with the primary queue is different from the "
"context associated with the kernel bundle");

if (impl->MSubmissionSecondaryQueue &&
impl->MSubmissionSecondaryQueue->get_context() !=
ExecBundle.get_context())
throw sycl::exception(
make_error_code(errc::invalid),
"Context associated with the secondary queue is different from the "
"context associated with the kernel bundle");

setStateExplicitKernelBundle();
setHandlerKernelBundle(detail::getSyclObjImpl(ExecBundle));
}
Expand Down Expand Up @@ -1928,34 +1922,28 @@ void handler::verifyDeviceHasProgressGuarantee(
}

bool handler::supportsUSMMemcpy2D() {
for (detail::queue_impl *QueueImpl :
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
if (QueueImpl &&
!checkContextSupports(QueueImpl->getContextImplPtr(),
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT))
return false;
}
return true;
auto &PrimQueue = impl->MSubmissionPrimaryQueue;
if (PrimQueue)
return checkContextSupports(PrimQueue->getContextImplPtr(),
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
else
// Return true when handler_impl is constructed with a graph.
return true;
}

bool handler::supportsUSMFill2D() {
for (detail::queue_impl *QueueImpl :
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
if (QueueImpl && !checkContextSupports(QueueImpl->getContextImplPtr(),
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT))
return false;
}
return true;
auto &PrimQueue = impl->MSubmissionPrimaryQueue;
if (PrimQueue)
return checkContextSupports(PrimQueue->getContextImplPtr(),
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
else
// Return true when handler_impl is constructed with a graph.
return true;
}

bool handler::supportsUSMMemset2D() {
for (detail::queue_impl *QueueImpl :
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
if (QueueImpl && !checkContextSupports(QueueImpl->getContextImplPtr(),
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT))
return false;
}
return true;
// memset use the same UR check as fill2D.
return supportsUSMFill2D();
}

id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) {
Expand Down
46 changes: 0 additions & 46 deletions sycl/unittests/SYCL2020/KernelBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,52 +308,6 @@ TEST(KernelBundle, UseKernelBundleWrongContextPrimaryQueueValidSecondaryQueue) {
}
}

TEST(KernelBundle, UseKernelBundleValidPrimaryQueueWrongContextSecondaryQueue) {
sycl::unittest::UrMock<> Mock;

const sycl::device Dev = sycl::platform().get_devices()[0];
const sycl::context PrimaryCtx{Dev};
const sycl::context SecondaryCtx{Dev};

ASSERT_NE(PrimaryCtx, SecondaryCtx);

auto KernelBundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(
PrimaryCtx, {Dev});

sycl::queue PrimaryQueue{PrimaryCtx, Dev};
sycl::queue SecondaryQueue{SecondaryCtx, Dev};

class UnqiueException {};

try {
PrimaryQueue.submit(
[&](sycl::handler &CGH) {
try {
CGH.use_kernel_bundle(KernelBundle);
FAIL() << "No exception was thrown.";
CGH.single_task<TestKernel>([]() {});
} catch (const sycl::exception &e) {
ASSERT_EQ(e.code().value(), static_cast<int>(sycl::errc::invalid))
<< "sycl::exception code was not the expected "
"sycl::errc::invalid.";
// Throw uniquely identifiable exception to distinguish between that
// the sycl::exception originates from the correct level.
throw UnqiueException{};
} catch (...) {
FAIL() << "Unexpected exception was thrown in kernel invocation "
"function.";
}
},
SecondaryQueue);
} catch (const UnqiueException &) {
// Expected path
} catch (const sycl::exception &) {
FAIL() << "sycl::exception thrown at the wrong level.";
} catch (...) {
FAIL() << "Unexpected exception was thrown in submit.";
}
}

TEST(KernelBundle, UseKernelBundleWrongContextPrimaryQueueAndSecondaryQueue) {
sycl::unittest::UrMock<> Mock;

Expand Down