Skip to content

Commit af7d882

Browse files
Eliminate std::shared_ptr<detail::queue_impl> from sycl::handler.
1 parent 8255f7c commit af7d882

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class __SYCL_EXPORT handler {
430430
/// \param Queue is a SYCL queue.
431431
/// \param CallerNeedsEvent indicates if the event resulting from this handler
432432
/// is needed by the caller.
433-
handler(std::shared_ptr<detail::queue_impl> Queue, bool CallerNeedsEvent);
433+
handler(std::shared_ptr<detail::queue_impl> &Queue, bool CallerNeedsEvent);
434434

435435
/// Constructs SYCL handler from the associated queue and the submission's
436436
/// primary and secondary queue.
@@ -443,7 +443,7 @@ class __SYCL_EXPORT handler {
443443
/// \param CallerNeedsEvent indicates if the event resulting from this handler
444444
/// is needed by the caller.
445445
handler(detail::handler_impl *HandlerImpl,
446-
std::shared_ptr<detail::queue_impl> Queue);
446+
std::shared_ptr<detail::queue_impl> &Queue);
447447

448448
/// Constructs SYCL handler from Graph.
449449
///
@@ -3425,7 +3425,7 @@ class __SYCL_EXPORT handler {
34253425
private:
34263426
std::unique_ptr<detail::handler_impl> MImplOwner;
34273427
detail::handler_impl *impl;
3428-
std::shared_ptr<detail::queue_impl> MQueue;
3428+
std::shared_ptr<detail::queue_impl> &MQueue;
34293429
std::vector<detail::LocalAccessorImplPtr> MLocalAccStorage;
34303430
std::vector<std::shared_ptr<detail::stream_impl>> MStreamStorage;
34313431
detail::string MKernelName;

sycl/source/detail/handler_impl.hpp

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

3232
class handler_impl {
3333
public:
34-
handler_impl(std::shared_ptr<queue_impl> SubmissionPrimaryQueue,
35-
std::shared_ptr<queue_impl> SubmissionSecondaryQueue,
34+
handler_impl(queue_impl *SubmissionPrimaryQueue,
35+
queue_impl *SubmissionSecondaryQueue,
3636
bool EventNeeded)
37-
: MSubmissionPrimaryQueue(std::move(SubmissionPrimaryQueue)),
38-
MSubmissionSecondaryQueue(std::move(SubmissionSecondaryQueue)),
37+
: MSubmissionPrimaryQueue(SubmissionPrimaryQueue),
38+
MSubmissionSecondaryQueue(SubmissionSecondaryQueue),
3939
MEventNeeded(EventNeeded) {};
4040

4141
handler_impl(
@@ -73,13 +73,13 @@ class handler_impl {
7373
/// Shared pointer to the primary queue implementation. This is different from
7474
/// the queue associated with the handler if the corresponding submission is
7575
/// a fallback from a previous submission.
76-
std::shared_ptr<queue_impl> MSubmissionPrimaryQueue;
76+
queue_impl *MSubmissionPrimaryQueue;
7777

7878
/// Shared pointer to the secondary queue implementation. Nullptr if no
7979
/// secondary queue fallback was given in the associated submission. This is
8080
/// equal to the queue associated with the handler if the corresponding
8181
/// submission is a fallback from a previous submission.
82-
std::shared_ptr<queue_impl> MSubmissionSecondaryQueue;
82+
queue_impl *MSubmissionSecondaryQueue;
8383

8484
/// Bool stores information about whether the event resulting from the
8585
/// corresponding work is required.

sycl/source/detail/queue_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ event queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
364364
bool IsTopCodeLoc,
365365
const SubmissionInfo &SubmitInfo) {
366366
detail::handler_impl HandlerImpl(
367-
std::move(PrimaryQueue), std::move(SecondaryQueue), CallerNeedsEvent);
368-
handler Handler(&HandlerImpl, Self);
367+
PrimaryQueue.get(), SecondaryQueue.get(), CallerNeedsEvent);
368+
handler Handler(&HandlerImpl, const_cast<std::shared_ptr<queue_impl> &>(Self));
369369
Handler.saveCodeLoc(Loc, IsTopCodeLoc);
370370

371371
{
@@ -387,7 +387,7 @@ event queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
387387

388388
addEvent(Event);
389389

390-
auto EventImpl = detail::getSyclObjImpl(Event);
390+
auto &EventImpl = detail::getSyclObjImpl(Event);
391391
for (auto &Stream : Streams) {
392392
// We don't want stream flushing to be blocking operation that is why submit
393393
// a host task to print stream buffer. It will fire up as soon as the kernel

sycl/source/handler.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,19 @@ fill_copy_args(detail::handler_impl *impl,
302302

303303
} // namespace detail
304304

305-
handler::handler(std::shared_ptr<detail::queue_impl> Queue,
305+
handler::handler(std::shared_ptr<detail::queue_impl> &Queue,
306306
bool CallerNeedsEvent)
307-
: MImplOwner(std::make_unique<detail::handler_impl>(Queue, nullptr,
307+
: MImplOwner(std::make_unique<detail::handler_impl>(Queue.get(), nullptr,
308308
CallerNeedsEvent)),
309-
impl(MImplOwner.get()), MQueue(std::move(Queue)) {}
309+
impl(MImplOwner.get()), MQueue(Queue) {}
310310

311311
handler::handler(detail::handler_impl *HandlerImpl,
312-
std::shared_ptr<detail::queue_impl> Queue)
313-
: impl(HandlerImpl), MQueue(std::move(Queue)) {}
312+
std::shared_ptr<detail::queue_impl> &Queue)
313+
: impl(HandlerImpl), MQueue(Queue) {}
314314

315-
handler::handler(detail::handler_impl *HandlerImpl) : impl(HandlerImpl) {}
315+
static std::shared_ptr<detail::queue_impl> DummyQueue;
316+
317+
handler::handler(detail::handler_impl *HandlerImpl) : impl(HandlerImpl), MQueue(DummyQueue) {}
316318

317319
// Sets the submission state to indicate that an explicit kernel bundle has been
318320
// set. Throws a sycl::exception with errc::invalid if the current state
@@ -1660,21 +1662,17 @@ void handler::ext_oneapi_signal_external_semaphore(
16601662

16611663
void handler::use_kernel_bundle(
16621664
const kernel_bundle<bundle_state::executable> &ExecBundle) {
1663-
std::shared_ptr<detail::queue_impl> PrimaryQueue =
1664-
impl->MSubmissionPrimaryQueue;
16651665
if ((!impl->MGraph &&
1666-
(PrimaryQueue->get_context() != ExecBundle.get_context())) ||
1666+
(impl->MSubmissionPrimaryQueue->get_context() != ExecBundle.get_context())) ||
16671667
(impl->MGraph &&
16681668
(impl->MGraph->getContext() != ExecBundle.get_context())))
16691669
throw sycl::exception(
16701670
make_error_code(errc::invalid),
16711671
"Context associated with the primary queue is different from the "
16721672
"context associated with the kernel bundle");
16731673

1674-
std::shared_ptr<detail::queue_impl> SecondaryQueue =
1675-
impl->MSubmissionSecondaryQueue;
1676-
if (SecondaryQueue &&
1677-
SecondaryQueue->get_context() != ExecBundle.get_context())
1674+
if (impl->MSubmissionSecondaryQueue &&
1675+
impl->MSubmissionSecondaryQueue->get_context() != ExecBundle.get_context())
16781676
throw sycl::exception(
16791677
make_error_code(errc::invalid),
16801678
"Context associated with the secondary queue is different from the "
@@ -1816,7 +1814,7 @@ void handler::verifyDeviceHasProgressGuarantee(
18161814
}
18171815

18181816
bool handler::supportsUSMMemcpy2D() {
1819-
for (const std::shared_ptr<detail::queue_impl> &QueueImpl :
1817+
for (detail::queue_impl *QueueImpl :
18201818
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
18211819
if (QueueImpl &&
18221820
!checkContextSupports(QueueImpl->getContextImplPtr(),
@@ -1827,7 +1825,7 @@ bool handler::supportsUSMMemcpy2D() {
18271825
}
18281826

18291827
bool handler::supportsUSMFill2D() {
1830-
for (const std::shared_ptr<detail::queue_impl> &QueueImpl :
1828+
for (detail::queue_impl *QueueImpl :
18311829
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
18321830
if (QueueImpl && !checkContextSupports(QueueImpl->getContextImplPtr(),
18331831
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT))
@@ -1837,7 +1835,7 @@ bool handler::supportsUSMFill2D() {
18371835
}
18381836

18391837
bool handler::supportsUSMMemset2D() {
1840-
for (const std::shared_ptr<detail::queue_impl> &QueueImpl :
1838+
for (detail::queue_impl *QueueImpl :
18411839
{impl->MSubmissionPrimaryQueue, impl->MSubmissionSecondaryQueue}) {
18421840
if (QueueImpl && !checkContextSupports(QueueImpl->getContextImplPtr(),
18431841
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT))

0 commit comments

Comments
 (0)