Skip to content

Commit acbca47

Browse files
[SYCL] Simplify secondary queue usage (#18642)
Following KhronosGroup/SYCL-Docs#811, the SYCL 2020 specification will not mandate the use nor exception checking of secondary queues. This allows us to relax the interfaces taking a secondary queue to fully ignore it. This commit drops the passing of the secondary queue throughout the pipeline. --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent cbea600 commit acbca47

File tree

12 files changed

+65
-274
lines changed

12 files changed

+65
-274
lines changed

sycl/include/sycl/ext/oneapi/experimental/enqueue_functions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ event submit_with_event_impl(const queue &Q, PropertiesT Props,
109109
CommandGroupFunc &&CGF,
110110
const sycl::detail::code_location &CodeLoc) {
111111
return Q.submit_with_event<__SYCL_USE_FALLBACK_ASSERT>(
112-
Props, detail::type_erased_cgfo_ty{CGF}, nullptr, CodeLoc);
112+
Props, detail::type_erased_cgfo_ty{CGF}, CodeLoc);
113113
}
114114
} // namespace detail
115115

sycl/include/sycl/queue.hpp

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ auto get_native(const SyclObjectT &Obj)
6666
namespace detail {
6767
class queue_impl;
6868

69-
inline event submitAssertCapture(const queue &, event &, queue *,
69+
inline event submitAssertCapture(const queue &, event &,
7070
const detail::code_location &);
7171

7272
// Function to postprocess submitted command
@@ -87,8 +87,10 @@ class __SYCL_EXPORT SubmissionInfo {
8787
sycl::detail::optional<SubmitPostProcessF> &PostProcessorFunc();
8888
const sycl::detail::optional<SubmitPostProcessF> &PostProcessorFunc() const;
8989

90+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
9091
std::shared_ptr<detail::queue_impl> &SecondaryQueue();
9192
const std::shared_ptr<detail::queue_impl> &SecondaryQueue() const;
93+
#endif
9294

9395
ext::oneapi::experimental::event_mode_enum &EventMode();
9496
const ext::oneapi::experimental::event_mode_enum &EventMode() const;
@@ -434,21 +436,18 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
434436
/// Submits a command group function object to the queue, in order to be
435437
/// scheduled for execution on the device.
436438
///
437-
/// On a kernel error, this command group function object is then scheduled
438-
/// for execution on a secondary queue.
439-
///
440439
/// \param CGF is a function object containing command group.
441-
/// \param SecondaryQueue is a fallback SYCL queue.
440+
/// \param SecondaryQueue is a fallback SYCL queue. (unused)
442441
/// \param CodeLoc is the code location of the submit call (default argument)
443442
/// \return a SYCL event object, which corresponds to the queue the command
444443
/// group is being enqueued on.
445444
template <typename T>
446445
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit(
447-
T CGF, queue &SecondaryQueue,
446+
T CGF, [[maybe_unused]] queue &SecondaryQueue,
448447
const detail::code_location &CodeLoc = detail::code_location::current()) {
449448
return submit_with_event<__SYCL_USE_FALLBACK_ASSERT>(
450449
sycl::ext::oneapi::experimental::empty_properties_t{},
451-
detail::type_erased_cgfo_ty{CGF}, &SecondaryQueue, CodeLoc);
450+
detail::type_erased_cgfo_ty{CGF}, CodeLoc);
452451
}
453452

454453
/// Prevents any commands submitted afterward to this queue from executing
@@ -3582,7 +3581,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
35823581
-> backend_return_t<BackendName, SyclObjectT>;
35833582

35843583
#if __SYCL_USE_FALLBACK_ASSERT
3585-
friend event detail::submitAssertCapture(const queue &, event &, queue *,
3584+
friend event detail::submitAssertCapture(const queue &, event &,
35863585
const detail::code_location &);
35873586
#endif
35883587

@@ -3686,47 +3685,6 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
36863685
const detail::code_location &CodeLoc,
36873686
bool IsTopCodeLoc) const;
36883687

3689-
/// Submits a command group function object to the queue, in order to be
3690-
/// scheduled for execution on the device.
3691-
///
3692-
/// \param Props is a property list with submission properties.
3693-
/// \param CGF is a function object containing command group.
3694-
/// \param SecondaryQueuePtr is a pointer to the secondary queue.
3695-
/// \param CodeLoc is the code location of the submit call (default argument)
3696-
/// \return a SYCL event object for the submitted command group.
3697-
//
3698-
// UseFallBackAssert as template param vs `#if` in function body is necessary
3699-
// to prevent ODR-violation between TUs built with different fallback assert
3700-
// modes.
3701-
template <bool UseFallbackAssert, typename PropertiesT>
3702-
event submit_with_event(PropertiesT Props,
3703-
const detail::type_erased_cgfo_ty &CGF,
3704-
queue *SecondaryQueuePtr,
3705-
const detail::code_location &CodeLoc =
3706-
detail::code_location::current()) const {
3707-
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
3708-
detail::v1::SubmissionInfo SI{};
3709-
ProcessSubmitProperties(Props, SI);
3710-
if (SecondaryQueuePtr)
3711-
SI.SecondaryQueue() = detail::getSyclObjImpl(*SecondaryQueuePtr);
3712-
if constexpr (UseFallbackAssert)
3713-
SI.PostProcessorFunc() =
3714-
[this, &SecondaryQueuePtr,
3715-
&TlsCodeLocCapture](bool IsKernel, bool KernelUsesAssert, event &E) {
3716-
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
3717-
KernelUsesAssert && !device_has(aspect::accelerator)) {
3718-
// __devicelib_assert_fail isn't supported by Device-side Runtime
3719-
// Linking against fallback impl of __devicelib_assert_fail is
3720-
// performed by program manager class
3721-
// Fallback assert isn't supported for FPGA
3722-
submitAssertCapture(*this, E, SecondaryQueuePtr,
3723-
TlsCodeLocCapture.query());
3724-
}
3725-
};
3726-
return submit_with_event_impl(CGF, SI, TlsCodeLocCapture.query(),
3727-
TlsCodeLocCapture.isToplevel());
3728-
}
3729-
37303688
/// Submits a command group function object to the queue, in order to be
37313689
/// scheduled for execution on the device.
37323690
///
@@ -3756,7 +3714,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
37563714
// Linking against fallback impl of __devicelib_assert_fail is
37573715
// performed by program manager class
37583716
// Fallback assert isn't supported for FPGA
3759-
submitAssertCapture(*this, E, nullptr, TlsCodeLocCapture.query());
3717+
submitAssertCapture(*this, E, TlsCodeLocCapture.query());
37603718
}
37613719
};
37623720
return submit_with_event_impl(CGF, SI, TlsCodeLocCapture.query(),
@@ -3955,15 +3913,13 @@ class AssertInfoCopier;
39553913
* Submit copy task for assert failure flag and host-task to check the flag
39563914
* \param Event kernel's event to depend on i.e. the event represents the
39573915
* kernel to check for assertion failure
3958-
* \param SecondaryQueue secondary queue for submit process, null if not used
39593916
* \returns host tasks event
39603917
*
39613918
* This method doesn't belong to queue class to overcome msvc behaviour due to
39623919
* which it gets compiled and exported without any integration header and, thus,
39633920
* with no proper KernelInfo instance.
39643921
*/
39653922
event submitAssertCapture(const queue &Self, event &Event,
3966-
queue *SecondaryQueue,
39673923
const detail::code_location &CodeLoc) {
39683924
buffer<detail::AssertHappened, 1> Buffer{1};
39693925

@@ -4019,10 +3975,10 @@ event submitAssertCapture(const queue &Self, event &Event,
40193975

40203976
CopierEv = Self.submit_with_event<true>(
40213977
sycl::ext::oneapi::experimental::empty_properties_t{}, CopierCGF,
4022-
SecondaryQueue, CodeLoc);
3978+
CodeLoc);
40233979
CheckerEv = Self.submit_with_event<true>(
40243980
sycl::ext::oneapi::experimental::empty_properties_t{}, CheckerCGF,
4025-
SecondaryQueue, CodeLoc);
3981+
CodeLoc);
40263982

40273983
return CheckerEv;
40283984
}

sycl/source/detail/handler_impl.hpp

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

3232
class handler_impl {
3333
public:
34-
handler_impl(queue_impl &Queue, queue_impl *SubmissionSecondaryQueue,
35-
bool EventNeeded)
36-
: MSubmissionSecondaryQueue(SubmissionSecondaryQueue),
37-
MEventNeeded(EventNeeded), MQueueOrGraph{Queue} {};
34+
handler_impl(queue_impl &Queue, bool EventNeeded)
35+
: MEventNeeded(EventNeeded), MQueueOrGraph{Queue} {};
3836

3937
handler_impl(ext::oneapi::experimental::detail::graph_impl &Graph)
4038
: MQueueOrGraph{Graph} {}
@@ -65,10 +63,6 @@ class handler_impl {
6563
/// Registers mutually exclusive submission states.
6664
HandlerSubmissionState MSubmissionState = HandlerSubmissionState::NO_STATE;
6765

68-
/// Pointer to the secondary queue implementation. Nullptr if no
69-
/// secondary queue fallback was given in the associated submission.
70-
queue_impl *MSubmissionSecondaryQueue = nullptr;
71-
7266
/// Bool stores information about whether the event resulting from the
7367
/// corresponding work is required.
7468
bool MEventNeeded = true;

sycl/source/detail/queue_impl.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ void queue_impl::addEvent(const detail::EventImplPtr &EventImpl) {
304304

305305
detail::EventImplPtr
306306
queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
307-
queue_impl *SecondaryQueue, bool CallerNeedsEvent,
308-
const detail::code_location &Loc, bool IsTopCodeLoc,
307+
bool CallerNeedsEvent, const detail::code_location &Loc,
308+
bool IsTopCodeLoc,
309309
const v1::SubmissionInfo &SubmitInfo) {
310310
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
311-
detail::handler_impl HandlerImplVal(*this, SecondaryQueue, CallerNeedsEvent);
311+
detail::handler_impl HandlerImplVal(*this, CallerNeedsEvent);
312312
handler Handler(HandlerImplVal);
313313
#else
314-
handler Handler(shared_from_this(), SecondaryQueue, CallerNeedsEvent);
314+
handler Handler(shared_from_this(), CallerNeedsEvent);
315315
#endif
316316
detail::handler_impl &HandlerImpl = *detail::getSyclObjImpl(Handler);
317317

@@ -390,8 +390,8 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
390390
Stream->generateFlushCommand(ServiceCGH);
391391
};
392392
detail::type_erased_cgfo_ty CGF{L};
393-
detail::EventImplPtr FlushEvent = submit_impl(
394-
CGF, SecondaryQueue, /*CallerNeedsEvent*/ true, Loc, IsTopCodeLoc, {});
393+
detail::EventImplPtr FlushEvent =
394+
submit_impl(CGF, /*CallerNeedsEvent*/ true, Loc, IsTopCodeLoc, {});
395395
if (EventImpl)
396396
EventImpl->attachEventToCompleteWeak(FlushEvent);
397397
if (!isInOrder()) {
@@ -403,18 +403,6 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
403403
return EventImpl;
404404
}
405405

406-
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
407-
detail::EventImplPtr
408-
queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
409-
const std::shared_ptr<queue_impl> & /*PrimaryQueue*/,
410-
const std::shared_ptr<queue_impl> &SecondaryQueue,
411-
bool CallerNeedsEvent, const detail::code_location &Loc,
412-
bool IsTopCodeLoc, const SubmissionInfo &SubmitInfo) {
413-
return submit_impl(CGF, SecondaryQueue.get(), CallerNeedsEvent, Loc,
414-
IsTopCodeLoc, SubmitInfo);
415-
}
416-
#endif
417-
418406
template <typename HandlerFuncT>
419407
event queue_impl::submitWithHandler(const std::vector<event> &DepEvents,
420408
bool CallerNeedsEvent,

sycl/source/detail/queue_impl.hpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ enum QueueOrder { Ordered, OOO };
6666
// Implementation of the submission information storage.
6767
struct SubmissionInfoImpl {
6868
optional<detail::SubmitPostProcessF> MPostProcessorFunc = std::nullopt;
69+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
6970
std::shared_ptr<detail::queue_impl> MSecondaryQueue = nullptr;
71+
#endif
7072
ext::oneapi::experimental::event_mode_enum MEventMode =
7173
ext::oneapi::experimental::event_mode_enum::none;
7274
};
@@ -331,22 +333,16 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
331333
/// Submits a command group function object to the queue, in order to be
332334
/// scheduled for execution on the device.
333335
///
334-
/// On a kernel error, this command group function object is then scheduled
335-
/// for execution on a secondary queue.
336-
///
337336
/// \param CGF is a function object containing command group.
338-
/// \param SecondQueue is a shared_ptr to the secondary queue.
339337
/// \param Loc is the code location of the submit call (default argument)
340338
/// \param StoreAdditionalInfo makes additional info be stored in event_impl
341339
/// \return a SYCL event object, which corresponds to the queue the command
342340
/// group is being enqueued on.
343341
event submit(const detail::type_erased_cgfo_ty &CGF,
344-
const std::shared_ptr<queue_impl> &SecondQueue,
345342
const detail::code_location &Loc, bool IsTopCodeLoc,
346343
const SubmitPostProcessF *PostProcess = nullptr) {
347344
event ResEvent;
348345
v1::SubmissionInfo SI{};
349-
SI.SecondaryQueue() = SecondQueue;
350346
if (PostProcess)
351347
SI.PostProcessorFunc() = *PostProcess;
352348
return submit_with_event(CGF, SI, Loc, IsTopCodeLoc);
@@ -364,18 +360,16 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
364360
const v1::SubmissionInfo &SubmitInfo,
365361
const detail::code_location &Loc, bool IsTopCodeLoc) {
366362

367-
detail::EventImplPtr ResEvent =
368-
submit_impl(CGF, SubmitInfo.SecondaryQueue().get(),
369-
/*CallerNeedsEvent=*/true, Loc, IsTopCodeLoc, SubmitInfo);
363+
detail::EventImplPtr ResEvent = submit_impl(CGF, /*CallerNeedsEvent=*/true,
364+
Loc, IsTopCodeLoc, SubmitInfo);
370365
return createSyclObjFromImpl<event>(ResEvent);
371366
}
372367

373368
void submit_without_event(const detail::type_erased_cgfo_ty &CGF,
374369
const v1::SubmissionInfo &SubmitInfo,
375370
const detail::code_location &Loc,
376371
bool IsTopCodeLoc) {
377-
submit_impl(CGF, SubmitInfo.SecondaryQueue().get(),
378-
/*CallerNeedsEvent=*/false, Loc, IsTopCodeLoc, SubmitInfo);
372+
submit_impl(CGF, /*CallerNeedsEvent=*/false, Loc, IsTopCodeLoc, SubmitInfo);
379373
}
380374

381375
/// Performs a blocking wait for the completion of all enqueued tasks in the
@@ -885,38 +879,15 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
885879
PostProcess(IsKernel, KernelUsesAssert, Event);
886880
}
887881

888-
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
889-
/// Performs command group submission to the queue.
890-
///
891-
/// \param CGF is a function object containing command group.
892-
/// \param PrimaryQueue is a pointer to the primary queue. This may be the
893-
/// same as this.
894-
/// \param SecondaryQueue is a pointer to the secondary queue. This may be the
895-
/// same as this.
896-
/// \param CallerNeedsEvent is a boolean indicating whether the event is
897-
/// required by the user after the call.
898-
/// \param Loc is the code location of the submit call (default argument)
899-
/// \param SubmitInfo is additional optional information for the submission.
900-
/// \return a SYCL event representing submitted command group.
901-
detail::EventImplPtr
902-
submit_impl(const detail::type_erased_cgfo_ty &CGF,
903-
const std::shared_ptr<queue_impl> &PrimaryQueue,
904-
const std::shared_ptr<queue_impl> &SecondaryQueue,
905-
bool CallerNeedsEvent, const detail::code_location &Loc,
906-
bool IsTopCodeLoc, const SubmissionInfo &SubmitInfo);
907-
#endif
908-
909882
/// Performs command group submission to the queue.
910883
///
911884
/// \param CGF is a function object containing command group.
912-
/// \param SecondaryQueue is a pointer to the secondary queue.
913885
/// \param CallerNeedsEvent is a boolean indicating whether the event is
914886
/// required by the user after the call.
915887
/// \param Loc is the code location of the submit call (default argument)
916888
/// \param SubmitInfo is additional optional information for the submission.
917889
/// \return a SYCL event representing submitted command group.
918890
detail::EventImplPtr submit_impl(const detail::type_erased_cgfo_ty &CGF,
919-
queue_impl *SecondaryQueue,
920891
bool CallerNeedsEvent,
921892
const detail::code_location &Loc,
922893
bool IsTopCodeLoc,

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,6 @@ class Scheduler {
587587

588588
void cleanupCommand(Command *Cmd, bool AllowUnsubmitted = false);
589589

590-
/// Reschedules the command passed using Queue provided.
591-
///
592-
/// This can lead to rescheduling of all dependent commands. This can be
593-
/// used when the user provides a "secondary" queue to the submit method
594-
/// which may be used when the command fails to enqueue/execute in the
595-
/// primary queue.
596-
void rescheduleCommand(Command *Cmd, queue_impl *Queue);
597-
598590
/// \return a pointer to the corresponding memory object record for the
599591
/// SYCL memory object provided, or nullptr if it does not exist.
600592
MemObjRecord *getMemObjRecord(SYCLMemObjI *MemObject);

sycl/source/handler.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,22 +353,21 @@ handler::handler(std::unique_ptr<detail::handler_impl> &&HandlerImpl)
353353

354354
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
355355
bool CallerNeedsEvent)
356-
: impl(std::make_shared<detail::handler_impl>(*Queue, nullptr,
357-
CallerNeedsEvent)),
356+
: impl(std::make_shared<detail::handler_impl>(*Queue, CallerNeedsEvent)),
358357
MQueueDoNotUse(std::move(Queue)) {}
359358

360359
handler::handler(
361360
std::shared_ptr<detail::queue_impl> Queue,
362361
[[maybe_unused]] std::shared_ptr<detail::queue_impl> PrimaryQueue,
363-
std::shared_ptr<detail::queue_impl> SecondaryQueue, bool CallerNeedsEvent)
364-
: impl(std::make_shared<detail::handler_impl>(*Queue, SecondaryQueue.get(),
365-
CallerNeedsEvent)),
362+
[[maybe_unused]] std::shared_ptr<detail::queue_impl> SecondaryQueue,
363+
bool CallerNeedsEvent)
364+
: impl(std::make_shared<detail::handler_impl>(*Queue, CallerNeedsEvent)),
366365
MQueueDoNotUse(Queue) {}
367366

368367
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
369-
detail::queue_impl *SecondaryQueue, bool CallerNeedsEvent)
370-
: impl(std::make_shared<detail::handler_impl>(*Queue, SecondaryQueue,
371-
CallerNeedsEvent)),
368+
[[maybe_unused]] detail::queue_impl *SecondaryQueue,
369+
bool CallerNeedsEvent)
370+
: impl(std::make_shared<detail::handler_impl>(*Queue, CallerNeedsEvent)),
372371
MQueueDoNotUse(std::move(Queue)) {}
373372

374373
handler::handler(
@@ -2021,14 +2020,6 @@ void handler::use_kernel_bundle(
20212020
"Context associated with the primary queue is different from the "
20222021
"context associated with the kernel bundle");
20232022

2024-
if (impl->MSubmissionSecondaryQueue &&
2025-
impl->MSubmissionSecondaryQueue->get_context() !=
2026-
ExecBundle.get_context())
2027-
throw sycl::exception(
2028-
make_error_code(errc::invalid),
2029-
"Context associated with the secondary queue is different from the "
2030-
"context associated with the kernel bundle");
2031-
20322023
setStateExplicitKernelBundle();
20332024
setHandlerKernelBundle(detail::getSyclObjImpl(ExecBundle));
20342025
}
@@ -2649,7 +2640,7 @@ __SYCL_EXPORT void HandlerAccess::preProcess(handler &CGH,
26492640
queue_impl &Q = CGH.impl->get_queue();
26502641
bool EventNeeded = !Q.isInOrder();
26512642
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
2652-
handler_impl HandlerImpl{Q, nullptr, EventNeeded};
2643+
handler_impl HandlerImpl{Q, EventNeeded};
26532644
handler AuxHandler{HandlerImpl};
26542645
#else
26552646
handler AuxHandler{Q.shared_from_this(), EventNeeded};
@@ -2668,8 +2659,7 @@ __SYCL_EXPORT void HandlerAccess::postProcess(handler &CGH,
26682659
if (!InOrder)
26692660
CGH.impl->MEventNeeded = true;
26702661

2671-
handler PostProcessHandler{
2672-
std::make_unique<handler_impl>(Q, nullptr, EventNeeded)};
2662+
handler PostProcessHandler{std::make_unique<handler_impl>(Q, EventNeeded)};
26732663
PostProcessHandler.copyCodeLoc(CGH);
26742664
// Extend lifetimes of auxiliary resources till the last kernel in the chain
26752665
// finishes:

0 commit comments

Comments
 (0)