Skip to content

Commit 6b62029

Browse files
[SYCL] Reintroduce secondary queue by reverting #18045 and #17967 (#18187)
Reverts #18045 and #17967
1 parent 209560e commit 6b62029

File tree

6 files changed

+129
-38
lines changed

6 files changed

+129
-38
lines changed

sycl/include/sycl/queue.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ class __SYCL_EXPORT SubmissionInfo {
8686
sycl::detail::optional<SubmitPostProcessF> &PostProcessorFunc();
8787
const sycl::detail::optional<SubmitPostProcessF> &PostProcessorFunc() const;
8888

89-
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
9089
std::shared_ptr<detail::queue_impl> &SecondaryQueue();
9190
const std::shared_ptr<detail::queue_impl> &SecondaryQueue() const;
92-
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
9391

9492
ext::oneapi::experimental::event_mode_enum &EventMode();
9593
const ext::oneapi::experimental::event_mode_enum &EventMode() const;
@@ -3620,11 +3618,13 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
36203618
template <bool UseFallbackAssert, typename PropertiesT>
36213619
event submit_with_event(
36223620
PropertiesT Props, const detail::type_erased_cgfo_ty &CGF,
3623-
[[maybe_unused]] queue *SecondaryQueuePtr,
3621+
queue *SecondaryQueuePtr,
36243622
const detail::code_location &CodeLoc = detail::code_location::current()) {
36253623
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
36263624
detail::SubmissionInfo SI{};
36273625
ProcessSubmitProperties(Props, SI);
3626+
if (SecondaryQueuePtr)
3627+
SI.SecondaryQueue() = detail::getSyclObjImpl(*SecondaryQueuePtr);
36283628
if constexpr (UseFallbackAssert)
36293629
SI.PostProcessorFunc() =
36303630
[this, &SecondaryQueuePtr,

sycl/source/detail/handler_impl.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ enum class HandlerSubmissionState : std::uint8_t {
3131

3232
class handler_impl {
3333
public:
34-
handler_impl(queue_impl *SubmissionPrimaryQueue, bool EventNeeded)
34+
handler_impl(queue_impl *SubmissionPrimaryQueue,
35+
queue_impl *SubmissionSecondaryQueue, bool EventNeeded)
3536
: MSubmissionPrimaryQueue(SubmissionPrimaryQueue),
37+
MSubmissionSecondaryQueue(SubmissionSecondaryQueue),
3638
MEventNeeded(EventNeeded) {};
3739

3840
handler_impl(
@@ -72,6 +74,12 @@ class handler_impl {
7274
/// a fallback from a previous submission.
7375
queue_impl *MSubmissionPrimaryQueue = nullptr;
7476

77+
/// Shared pointer to the secondary queue implementation. Nullptr if no
78+
/// secondary queue fallback was given in the associated submission. This is
79+
/// equal to the queue associated with the handler if the corresponding
80+
/// submission is a fallback from a previous submission.
81+
queue_impl *MSubmissionSecondaryQueue = nullptr;
82+
7583
/// Bool stores information about whether the event resulting from the
7684
/// corresponding work is required.
7785
bool MEventNeeded = true;

sycl/source/detail/queue_impl.hpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ enum QueueOrder { Ordered, OOO };
7070
// Implementation of the submission information storage.
7171
struct SubmissionInfoImpl {
7272
optional<detail::SubmitPostProcessF> MPostProcessorFunc = std::nullopt;
73-
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
7473
std::shared_ptr<detail::queue_impl> MSecondaryQueue = nullptr;
75-
#endif
7674
ext::oneapi::experimental::event_mode_enum MEventMode =
7775
ext::oneapi::experimental::event_mode_enum::none;
7876
};
@@ -342,11 +340,12 @@ class queue_impl {
342340
/// group is being enqueued on.
343341
event submit(const detail::type_erased_cgfo_ty &CGF,
344342
const std::shared_ptr<queue_impl> &Self,
345-
[[maybe_unused]] const std::shared_ptr<queue_impl> &SecondQueue,
343+
const std::shared_ptr<queue_impl> &SecondQueue,
346344
const detail::code_location &Loc, bool IsTopCodeLoc,
347345
const SubmitPostProcessF *PostProcess = nullptr) {
348346
event ResEvent;
349347
SubmissionInfo SI{};
348+
SI.SecondaryQueue() = SecondQueue;
350349
if (PostProcess)
351350
SI.PostProcessorFunc() = *PostProcess;
352351
return submit_with_event(CGF, Self, SI, Loc, IsTopCodeLoc);
@@ -365,6 +364,21 @@ class queue_impl {
365364
const std::shared_ptr<queue_impl> &Self,
366365
const SubmissionInfo &SubmitInfo,
367366
const detail::code_location &Loc, bool IsTopCodeLoc) {
367+
if (SubmitInfo.SecondaryQueue()) {
368+
event ResEvent;
369+
const std::shared_ptr<queue_impl> &SecondQueue =
370+
SubmitInfo.SecondaryQueue();
371+
try {
372+
ResEvent = submit_impl(CGF, Self, Self, SecondQueue,
373+
/*CallerNeedsEvent=*/true, Loc, IsTopCodeLoc,
374+
SubmitInfo);
375+
} catch (...) {
376+
ResEvent = SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue,
377+
/*CallerNeedsEvent=*/true, Loc,
378+
IsTopCodeLoc, SubmitInfo);
379+
}
380+
return ResEvent;
381+
}
368382
event ResEvent =
369383
submit_impl(CGF, Self, Self, nullptr,
370384
/*CallerNeedsEvent=*/true, Loc, IsTopCodeLoc, SubmitInfo);
@@ -376,8 +390,21 @@ class queue_impl {
376390
const SubmissionInfo &SubmitInfo,
377391
const detail::code_location &Loc,
378392
bool IsTopCodeLoc) {
379-
submit_impl(CGF, Self, Self, nullptr, /*CallerNeedsEvent=*/false, Loc,
380-
IsTopCodeLoc, SubmitInfo);
393+
if (SubmitInfo.SecondaryQueue()) {
394+
const std::shared_ptr<queue_impl> SecondQueue =
395+
SubmitInfo.SecondaryQueue();
396+
try {
397+
submit_impl(CGF, Self, Self, SecondQueue,
398+
/*CallerNeedsEvent=*/false, Loc, IsTopCodeLoc, SubmitInfo);
399+
} catch (...) {
400+
SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue,
401+
/*CallerNeedsEvent=*/false, Loc, IsTopCodeLoc,
402+
SubmitInfo);
403+
}
404+
} else {
405+
submit_impl(CGF, Self, Self, nullptr, /*CallerNeedsEvent=*/false, Loc,
406+
IsTopCodeLoc, SubmitInfo);
407+
}
381408
}
382409

383410
/// Performs a blocking wait for the completion of all enqueued tasks in the

sycl/source/handler.cpp

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -314,28 +314,26 @@ fill_copy_args(detail::handler_impl *impl,
314314

315315
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
316316
bool CallerNeedsEvent)
317-
: impl(std::make_shared<detail::handler_impl>(Queue.get(),
317+
: impl(std::make_shared<detail::handler_impl>(Queue.get(), nullptr,
318318
CallerNeedsEvent)),
319319
MQueue(std::move(Queue)) {}
320320

321321
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
322322
// TODO: This function is not used anymore, remove it in the next
323323
// ABI-breaking window.
324-
handler::handler(
325-
std::shared_ptr<detail::queue_impl> Queue,
326-
std::shared_ptr<detail::queue_impl> PrimaryQueue,
327-
[[maybe_unused]] std::shared_ptr<detail::queue_impl> SecondaryQueue,
328-
bool CallerNeedsEvent)
329-
: impl(std::make_shared<detail::handler_impl>(PrimaryQueue.get(),
330-
CallerNeedsEvent)),
324+
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
325+
std::shared_ptr<detail::queue_impl> PrimaryQueue,
326+
std::shared_ptr<detail::queue_impl> SecondaryQueue,
327+
bool CallerNeedsEvent)
328+
: impl(std::make_shared<detail::handler_impl>(
329+
PrimaryQueue.get(), SecondaryQueue.get(), CallerNeedsEvent)),
331330
MQueue(Queue) {}
332331
#endif
333332

334333
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
335334
detail::queue_impl *PrimaryQueue,
336-
[[maybe_unused]] detail::queue_impl *SecondaryQueue,
337-
bool CallerNeedsEvent)
338-
: impl(std::make_shared<detail::handler_impl>(PrimaryQueue,
335+
detail::queue_impl *SecondaryQueue, bool CallerNeedsEvent)
336+
: impl(std::make_shared<detail::handler_impl>(PrimaryQueue, SecondaryQueue,
339337
CallerNeedsEvent)),
340338
MQueue(std::move(Queue)) {}
341339

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

1778+
if (impl->MSubmissionSecondaryQueue &&
1779+
impl->MSubmissionSecondaryQueue->get_context() !=
1780+
ExecBundle.get_context())
1781+
throw sycl::exception(
1782+
make_error_code(errc::invalid),
1783+
"Context associated with the secondary queue is different from the "
1784+
"context associated with the kernel bundle");
1785+
17801786
setStateExplicitKernelBundle();
17811787
setHandlerKernelBundle(detail::getSyclObjImpl(ExecBundle));
17821788
}
@@ -1922,28 +1928,34 @@ void handler::verifyDeviceHasProgressGuarantee(
19221928
}
19231929

19241930
bool handler::supportsUSMMemcpy2D() {
1925-
auto &PrimQueue = impl->MSubmissionPrimaryQueue;
1926-
if (PrimQueue)
1927-
return checkContextSupports(PrimQueue->getContextImplPtr(),
1928-
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT);
1929-
else
1930-
// Return true when handler_impl is constructed with a graph.
1931-
return true;
1931+
for (detail::queue_impl *QueueImpl :
1932+
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
1933+
if (QueueImpl &&
1934+
!checkContextSupports(QueueImpl->getContextImplPtr(),
1935+
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT))
1936+
return false;
1937+
}
1938+
return true;
19321939
}
19331940

19341941
bool handler::supportsUSMFill2D() {
1935-
auto &PrimQueue = impl->MSubmissionPrimaryQueue;
1936-
if (PrimQueue)
1937-
return checkContextSupports(PrimQueue->getContextImplPtr(),
1938-
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT);
1939-
else
1940-
// Return true when handler_impl is constructed with a graph.
1941-
return true;
1942+
for (detail::queue_impl *QueueImpl :
1943+
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
1944+
if (QueueImpl && !checkContextSupports(QueueImpl->getContextImplPtr(),
1945+
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT))
1946+
return false;
1947+
}
1948+
return true;
19421949
}
19431950

19441951
bool handler::supportsUSMMemset2D() {
1945-
// memset use the same UR check as fill2D.
1946-
return supportsUSMFill2D();
1952+
for (detail::queue_impl *QueueImpl :
1953+
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
1954+
if (QueueImpl && !checkContextSupports(QueueImpl->getContextImplPtr(),
1955+
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT))
1956+
return false;
1957+
}
1958+
return true;
19471959
}
19481960

19491961
id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) {

sycl/source/queue.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const optional<SubmitPostProcessF> &SubmissionInfo::PostProcessorFunc() const {
3232
return impl->MPostProcessorFunc;
3333
}
3434

35-
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
3635
std::shared_ptr<detail::queue_impl> &SubmissionInfo::SecondaryQueue() {
3736
return impl->MSecondaryQueue;
3837
}
@@ -41,7 +40,6 @@ const std::shared_ptr<detail::queue_impl> &
4140
SubmissionInfo::SecondaryQueue() const {
4241
return impl->MSecondaryQueue;
4342
}
44-
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
4543

4644
ext::oneapi::experimental::event_mode_enum &SubmissionInfo::EventMode() {
4745
return impl->MEventMode;

sycl/unittests/SYCL2020/KernelBundle.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,52 @@ TEST(KernelBundle, UseKernelBundleWrongContextPrimaryQueueValidSecondaryQueue) {
308308
}
309309
}
310310

311+
TEST(KernelBundle, UseKernelBundleValidPrimaryQueueWrongContextSecondaryQueue) {
312+
sycl::unittest::UrMock<> Mock;
313+
314+
const sycl::device Dev = sycl::platform().get_devices()[0];
315+
const sycl::context PrimaryCtx{Dev};
316+
const sycl::context SecondaryCtx{Dev};
317+
318+
ASSERT_NE(PrimaryCtx, SecondaryCtx);
319+
320+
auto KernelBundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(
321+
PrimaryCtx, {Dev});
322+
323+
sycl::queue PrimaryQueue{PrimaryCtx, Dev};
324+
sycl::queue SecondaryQueue{SecondaryCtx, Dev};
325+
326+
class UnqiueException {};
327+
328+
try {
329+
PrimaryQueue.submit(
330+
[&](sycl::handler &CGH) {
331+
try {
332+
CGH.use_kernel_bundle(KernelBundle);
333+
FAIL() << "No exception was thrown.";
334+
CGH.single_task<TestKernel>([]() {});
335+
} catch (const sycl::exception &e) {
336+
ASSERT_EQ(e.code().value(), static_cast<int>(sycl::errc::invalid))
337+
<< "sycl::exception code was not the expected "
338+
"sycl::errc::invalid.";
339+
// Throw uniquely identifiable exception to distinguish between that
340+
// the sycl::exception originates from the correct level.
341+
throw UnqiueException{};
342+
} catch (...) {
343+
FAIL() << "Unexpected exception was thrown in kernel invocation "
344+
"function.";
345+
}
346+
},
347+
SecondaryQueue);
348+
} catch (const UnqiueException &) {
349+
// Expected path
350+
} catch (const sycl::exception &) {
351+
FAIL() << "sycl::exception thrown at the wrong level.";
352+
} catch (...) {
353+
FAIL() << "Unexpected exception was thrown in submit.";
354+
}
355+
}
356+
311357
TEST(KernelBundle, UseKernelBundleWrongContextPrimaryQueueAndSecondaryQueue) {
312358
sycl::unittest::UrMock<> Mock;
313359

0 commit comments

Comments
 (0)