Skip to content

Commit 454234e

Browse files
committed
Pass secondary queue through the class too
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 7a143ff commit 454234e

File tree

4 files changed

+58
-29
lines changed

4 files changed

+58
-29
lines changed

sycl/include/sycl/queue.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ inline event submitAssertCapture(queue &, event &, queue *,
9090
// event &Event - event after which post processing should be executed
9191
using SubmitPostProcessF = std::function<void(bool, bool, event &)>;
9292

93-
class SubmissionInfoImpl;
93+
struct SubmissionInfoImpl;
9494

95-
class SubmissionInfo {
95+
class __SYCL_EXPORT SubmissionInfo {
9696
public:
9797
SubmissionInfo() = default;
9898

9999
void SetPostProcessing(const SubmitPostProcessF &PostProcessorFunc);
100+
void
101+
SetSecondaryQueue(const std::shared_ptr<detail::queue_impl> &SecondaryQueue);
100102

101103
std::shared_ptr<SubmissionInfoImpl> impl = nullptr;
102104
};
@@ -359,8 +361,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
359361
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit(
360362
T CGF,
361363
const detail::code_location &CodeLoc = detail::code_location::current()) {
362-
return submit_with_event(
363-
CGF, /*SecondaryQueuePtr=*/nullptr, CodeLoc);
364+
return submit_with_event(CGF, /*SecondaryQueuePtr=*/nullptr, CodeLoc);
364365
}
365366

366367
/// Submits a command group function object to the queue, in order to be
@@ -378,8 +379,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
378379
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit(
379380
T CGF, queue &SecondaryQueue,
380381
const detail::code_location &CodeLoc = detail::code_location::current()) {
381-
return submit_with_event(
382-
CGF, &SecondaryQueue, CodeLoc);
382+
return submit_with_event(CGF, &SecondaryQueue, CodeLoc);
383383
}
384384

385385
/// Prevents any commands submitted afterward to this queue from executing
@@ -2799,13 +2799,15 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
27992799
template <typename T>
28002800
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event>
28012801
submit_with_event(
2802-
T CGF, [[maybe_unused]] queue *SecondaryQueuePtr,
2802+
T CGF, queue *SecondaryQueuePtr,
28032803
const detail::code_location &CodeLoc = detail::code_location::current()) {
28042804
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
28052805
detail::SubmissionInfo SI{};
2806+
if (SecondaryQueuePtr)
2807+
SI.SetSecondaryQueue(detail::getSyclObjImpl(*SecondaryQueuePtr));
28062808
#if __SYCL_USE_FALLBACK_ASSERT
2807-
auto PostProcess = [this, &SecondaryQueuePtr, &TlsCodeLocCapture](
2808-
bool IsKernel, bool KernelUsesAssert, event &E) {
2809+
SI.SetPostProcessing([this, &SecondaryQueuePtr, &TlsCodeLocCapture](
2810+
bool IsKernel, bool KernelUsesAssert, event &E) {
28092811
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
28102812
KernelUsesAssert && !device_has(aspect::accelerator)) {
28112813
// __devicelib_assert_fail isn't supported by Device-side Runtime
@@ -2815,8 +2817,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
28152817
submitAssertCapture(*this, E, SecondaryQueuePtr,
28162818
TlsCodeLocCapture.query());
28172819
}
2818-
};
2819-
SI.SetPostProcessing(std::move(PostProcess));
2820+
});
28202821
#endif // __SYCL_USE_FALLBACK_ASSERT
28212822
return submit_with_event_impl(CGF, SI, TlsCodeLocCapture.query(),
28222823
TlsCodeLocCapture.isToplevel());
@@ -3063,10 +3064,8 @@ event submitAssertCapture(queue &Self, event &Event, queue *SecondaryQueue,
30633064
});
30643065
};
30653066

3066-
CopierEv = Self.submit_with_event(
3067-
CopierCGF, SecondaryQueue, CodeLoc);
3068-
CheckerEv = Self.submit_with_event(
3069-
CheckerCGF, SecondaryQueue, CodeLoc);
3067+
CopierEv = Self.submit_with_event(CopierCGF, SecondaryQueue, CodeLoc);
3068+
CheckerEv = Self.submit_with_event(CheckerCGF, SecondaryQueue, CodeLoc);
30703069

30713070
return CheckerEv;
30723071
}

sycl/source/detail/queue_impl.hpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ enum QueueOrder { Ordered, OOO };
6969

7070
// Implementation of the submission information storage.
7171
struct SubmissionInfoImpl {
72-
std::optional<detail::SubmitPostProcessF> MPostProcessorFunc = nullptr;
72+
std::optional<detail::SubmitPostProcessF> MPostProcessorFunc = std::nullopt;
73+
std::shared_ptr<detail::queue_impl> MSecondaryQueue = nullptr;
7374
};
7475

7576
class queue_impl {
@@ -344,18 +345,10 @@ class queue_impl {
344345
const SubmitPostProcessF *PostProcess = nullptr) {
345346
event ResEvent;
346347
SubmissionInfo SI{};
348+
SI.SetSecondaryQueue(SecondQueue);
347349
if (PostProcess)
348350
SI.SetPostProcessing(*PostProcess);
349-
try {
350-
ResEvent = submit_impl(CGF, Self, Self, SecondQueue,
351-
/*CallerNeedsEvent=*/true, Loc, IsTopCodeLoc,
352-
SI);
353-
} catch (...) {
354-
ResEvent = SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue,
355-
/*CallerNeedsEvent=*/true, Loc,
356-
IsTopCodeLoc, SI);
357-
}
358-
return discard_or_return(ResEvent);
351+
return submit_with_event(CGF, Self, SI, Loc, IsTopCodeLoc);
359352
}
360353

361354
/// Submits a command group function object to the queue, in order to be
@@ -371,7 +364,22 @@ class queue_impl {
371364
const std::shared_ptr<queue_impl> &Self,
372365
const SubmissionInfo &SubmitInfo,
373366
const detail::code_location &Loc, bool IsTopCodeLoc) {
374-
auto ResEvent =
367+
if (SubmitInfo.impl && SubmitInfo.impl->MSecondaryQueue) {
368+
event ResEvent;
369+
const std::shared_ptr<queue_impl> SecondQueue =
370+
SubmitInfo.impl->MSecondaryQueue;
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+
}
382+
event ResEvent =
375383
submit_impl(CGF, Self, Self, nullptr,
376384
/*CallerNeedsEvent=*/true, Loc, IsTopCodeLoc, SubmitInfo);
377385
return discard_or_return(ResEvent);
@@ -382,8 +390,21 @@ class queue_impl {
382390
const SubmissionInfo &SubmitInfo,
383391
const detail::code_location &Loc,
384392
bool IsTopCodeLoc) {
385-
submit_impl(CGF, Self, Self, nullptr, /*CallerNeedsEvent=*/false, Loc,
386-
IsTopCodeLoc, SubmitInfo);
393+
if (SubmitInfo.impl && SubmitInfo.impl->MSecondaryQueue) {
394+
const std::shared_ptr<queue_impl> SecondQueue =
395+
SubmitInfo.impl->MSecondaryQueue;
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+
}
387408
}
388409

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

sycl/source/queue.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ void SubmissionInfo::SetPostProcessing(
2727
impl = std::make_shared<SubmissionInfoImpl>();
2828
impl->MPostProcessorFunc = std::move(PostProcessorFunc);
2929
}
30+
31+
void SubmissionInfo::SetSecondaryQueue(
32+
const std::shared_ptr<detail::queue_impl> &SecondaryQueue) {
33+
if (!impl)
34+
impl = std::make_shared<SubmissionInfoImpl>();
35+
impl->MSecondaryQueue = SecondaryQueue;
36+
}
3037
}
3138

3239
queue::queue(const context &SyclContext, const device_selector &DeviceSelector,

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,8 @@ _ZN4sycl3_V16detail13lgamma_r_implEfPi
32383238
_ZN4sycl3_V16detail13make_platformEmNS0_7backendE
32393239
_ZN4sycl3_V16detail13select_deviceERKSt8functionIFiRKNS0_6deviceEEE
32403240
_ZN4sycl3_V16detail13select_deviceERKSt8functionIFiRKNS0_6deviceEEERKNS0_7contextE
3241+
_ZN4sycl3_V16detail14SubmissionInfo17SetSecondaryQueueERKSt10shared_ptrINS1_10queue_implEE
3242+
_ZN4sycl3_V16detail14SubmissionInfo17SetPostProcessingERKSt8functionIFvbbRNS0_5eventEEE
32413243
_ZN4sycl3_V16detail14addCounterInitERNS0_7handlerERSt10shared_ptrINS1_10queue_implEERS4_IiE
32423244
_ZN4sycl3_V16detail14getBorderColorENS0_19image_channel_orderE
32433245
_ZN4sycl3_V16detail14tls_code_loc_t5queryEv

0 commit comments

Comments
 (0)