Skip to content

[NFC][SYCL] Raw context_impl in getInteropContext and queue_impl ctor #19126

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

Conversation

aelovikov-intel
Copy link
Contributor

Splitting into two PRs would result in unnecessary temporarily adjustments and merge conflicts later on between these changes, so perform in a single PR. They are both small enough anyway.

Continuation of the refactoring in
#18795
#18877
#18966
#18979
#18980
#18981
#19007
#19030
#19123

…` ctor

Splitting into two PRs would result in unnecessary temporarily
adjustments and merge conflicts later on between these changes, so
perform in a single PR. They are both small enough anyway.

Continuation of the refactoring in
intel#18795
intel#18877
intel#18966
intel#18979
intel#18980
intel#18981
intel#19007
intel#19030
intel#19123
@@ -156,7 +156,7 @@ __SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
ur_queue_handle_t UrQueue = nullptr;

Adapter->call<UrApiKind::urQueueCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), UrDevice, &NativeProperties,
NativeHandle, ContextImpl.getHandleRef(), UrDevice, &NativeProperties,
&UrQueue);
// Construct the SYCL queue from UR queue.
return detail::createSyclObjFromImpl<queue>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file because of this queue_impl creation.

@@ -117,11 +117,11 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
/// constructed.
/// \param AsyncHandler is a SYCL asynchronous exception handler.
/// \param PropList is a list of properties to use for queue construction.
queue_impl(device_impl &Device, const ContextImplPtr &Context,
queue_impl(device_impl &Device, std::shared_ptr<context_impl> &&Context,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need the rvalue-reference overload for the creation using getDefaultOrNew helper at line 108. Maybe this can be refactored further somehow, but that would be independent of passing SYCL RT objects by raw ptr/ref.

Copy link
Contributor

@uditagarwal97 uditagarwal97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@uditagarwal97 uditagarwal97 requested a review from Copilot June 24, 2025 22:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors context handling in interop constructs by switching from shared_ptr-based interfaces to raw context_impl* or references in getInteropContext and queue_impl constructors, and updates all call sites accordingly.

  • Change getInteropContext() to return a raw pointer instead of shared_ptr
  • Update queue_impl constructors to accept context_impl& and manage ownership internally
  • Adjust all instantiations and interop uses to dereference or call .get() on the existing smart pointer

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sycl/unittests/scheduler/LinkedAllocaDependencies.cpp Mock’s getInteropContext() signature updated
sycl/unittests/scheduler/HostTaskAndBarrier.cpp TestQueueImpl ctor uses context_impl&
sycl/source/queue.cpp Queue ctors now pass *getSyclObjImpl(SyclContext)
sycl/source/detail/sycl_mem_obj_t.hpp Base memobj returns raw pointer; member holds shared_ptr
sycl/source/detail/sycl_mem_obj_i.hpp Interface updated to raw pointer return type
sycl/source/detail/scheduler/graph_builder.cpp Use raw pointer from getInteropContext()
sycl/source/detail/queue_impl.hpp Ctor overloads changed to reference and moved ownership
sycl/source/detail/graph_impl.cpp exec_graph_impl uses raw context reference
sycl/source/backend.cpp make_queue now dereferences context_impl pointer
Comments suppressed due to low confidence (1)

sycl/source/backend.cpp:129

  • [nitpick] The variable name ContextImpl is identical to the type and uses uppercase; consider renaming it to ctxImpl or contextImpl to follow variable naming conventions and avoid confusion.
  context_impl &ContextImpl = *getSyclObjImpl(Context);

@aelovikov-intel aelovikov-intel merged commit c73c9d0 into intel:sycl Jun 25, 2025
25 checks passed
@aelovikov-intel aelovikov-intel deleted the context_impl-queue_impl-ctor branch June 25, 2025 13:47
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Jun 25, 2025
Subsequently, use `getContextImpl` instead of `getContextImplPtr` when
possible.

Continuation of the refactoring in
intel#18795
intel#18877
intel#18966
intel#18979
intel#18980
intel#18981
intel#19007
intel#19030
intel#19123
intel#19126
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Jun 25, 2025
Subsequently, use `getContextImpl` instead of `getContextImplPtr` when
possible.

Continuation of the refactoring in
intel#18795
intel#18877
intel#18966
intel#18979
intel#18980
intel#18981
intel#19007
intel#19030
intel#19123
intel#19126
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Jun 25, 2025
`SetArgBasedOnType` argument is only used to pass to the `sampler_impl`
ctor so update it.

`getCGKernelInfo` is only called in a function that also calls
`sampler_impl` ctor so updating its signuature allows to update that
caller's local `ContextImpl` variable, so makes sense to do as part of
this PR as well.

Continuation of the refactoring in
intel#18795
intel#18877
intel#18966
intel#18979
intel#18980
intel#18981
intel#19007
intel#19030
intel#19123
intel#19126
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Jun 25, 2025
`SetArgBasedOnType` argument is only used to pass to the `sampler_impl`
ctor so update it.

`getCGKernelInfo` is only called in a function that also calls
`sampler_impl` ctor so updating its signuature allows to update that
caller's local `ContextImpl` variable, so makes sense to do as part of
this PR as well.

Continuation of the refactoring in
intel#18795
intel#18877
intel#18966
intel#18979
intel#18980
intel#18981
intel#19007
intel#19030
intel#19123
intel#19126
againull pushed a commit that referenced this pull request Jun 25, 2025
…19153)

`SetArgBasedOnType` argument is only used to pass to the `sampler_impl`
ctor so update it.

`getCGKernelInfo` is only called in a function that also calls
`sampler_impl` ctor so updating its signuature allows to update that
caller's local `ContextImpl` variable, so makes sense to do as part of
this PR as well.

Continuation of the refactoring in
#18795
#18877
#18966
#18979
#18980
#18981
#19007
#19030
#19123
#19126
aelovikov-intel added a commit that referenced this pull request Jun 26, 2025
Subsequently, use `getContextImpl` instead of `getContextImplPtr` when
possible.

Continuation of the refactoring in
#18795
#18877
#18966
#18979
#18980
#18981
#19007
#19030
#19123
#19126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants