Skip to content

[SYCL][NFC] Make sycl_mem_obj::getAdapter() return by reference #19312

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

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ void buffer_impl::addInteropObject(
if (std::find(Handles.begin(), Handles.end(),
ur::cast<ur_native_handle_t>(MInteropMemObject)) ==
Handles.end()) {
const AdapterPtr &Adapter = getAdapter();
Adapter->call<UrApiKind::urMemRetain>(
adapter_impl &Adapter = getAdapter();
Adapter.call<UrApiKind::urMemRetain>(
ur::cast<ur_mem_handle_t>(MInteropMemObject));
ur_native_handle_t NativeHandle = 0;
Adapter->call<UrApiKind::urMemGetNativeHandle>(MInteropMemObject, nullptr,
&NativeHandle);
Adapter.call<UrApiKind::urMemGetNativeHandle>(MInteropMemObject, nullptr,
&NativeHandle);
Handles.push_back(NativeHandle);
}
}
Expand Down
28 changes: 13 additions & 15 deletions sycl/source/detail/sycl_mem_obj_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@ SYCLMemObjT::SYCLMemObjT(ur_native_handle_t MemObject,
MSharedPtrStorage(nullptr), MHostPtrProvided(true),
MOwnNativeHandle(OwnNativeHandle) {
ur_context_handle_t Context = nullptr;
const AdapterPtr &Adapter = getAdapter();
adapter_impl &Adapter = getAdapter();

ur_mem_native_properties_t MemProperties = {
UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, nullptr, OwnNativeHandle};
Adapter->call<UrApiKind::urMemBufferCreateWithNativeHandle>(
Adapter.call<UrApiKind::urMemBufferCreateWithNativeHandle>(
MemObject, MInteropContext->getHandleRef(), &MemProperties,
&MInteropMemObject);

// Get the size of the buffer in bytes
Adapter->call<UrApiKind::urMemGetInfo>(MInteropMemObject, UR_MEM_INFO_SIZE,
sizeof(size_t), &MSizeInBytes,
nullptr);
Adapter.call<UrApiKind::urMemGetInfo>(MInteropMemObject, UR_MEM_INFO_SIZE,
sizeof(size_t), &MSizeInBytes, nullptr);

Adapter->call<UrApiKind::urMemGetInfo>(MInteropMemObject, UR_MEM_INFO_CONTEXT,
sizeof(Context), &Context, nullptr);
Adapter.call<UrApiKind::urMemGetInfo>(MInteropMemObject, UR_MEM_INFO_CONTEXT,
sizeof(Context), &Context, nullptr);

if (MInteropContext->getHandleRef() != Context)
throw sycl::exception(
Expand Down Expand Up @@ -84,7 +83,7 @@ SYCLMemObjT::SYCLMemObjT(ur_native_handle_t MemObject,
MSharedPtrStorage(nullptr), MHostPtrProvided(true),
MOwnNativeHandle(OwnNativeHandle) {
ur_context_handle_t Context = nullptr;
const AdapterPtr &Adapter = getAdapter();
adapter_impl &Adapter = getAdapter();

ur_image_desc_t Desc = {};
Desc.stype = UR_STRUCTURE_TYPE_IMAGE_DESC;
Expand All @@ -101,12 +100,12 @@ SYCLMemObjT::SYCLMemObjT(ur_native_handle_t MemObject,
ur_mem_native_properties_t NativeProperties = {
UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, nullptr, OwnNativeHandle};

Adapter->call<UrApiKind::urMemImageCreateWithNativeHandle>(
Adapter.call<UrApiKind::urMemImageCreateWithNativeHandle>(
MemObject, MInteropContext->getHandleRef(), &Format, &Desc,
&NativeProperties, &MInteropMemObject);

Adapter->call<UrApiKind::urMemGetInfo>(MInteropMemObject, UR_MEM_INFO_CONTEXT,
sizeof(Context), &Context, nullptr);
Adapter.call<UrApiKind::urMemGetInfo>(MInteropMemObject, UR_MEM_INFO_CONTEXT,
sizeof(Context), &Context, nullptr);

if (MInteropContext->getHandleRef() != Context)
throw sycl::exception(
Expand Down Expand Up @@ -157,14 +156,13 @@ void SYCLMemObjT::updateHostMemory() {
releaseHostMem(MShadowCopy);

if (MOpenCLInterop) {
const AdapterPtr &Adapter = getAdapter();
Adapter->call<UrApiKind::urMemRelease>(MInteropMemObject);
getAdapter().call<UrApiKind::urMemRelease>(MInteropMemObject);
}
}
const AdapterPtr &SYCLMemObjT::getAdapter() const {
adapter_impl &SYCLMemObjT::getAdapter() const {
assert((MInteropContext != nullptr) &&
"Trying to get Adapter from SYCLMemObjT with nullptr ContextImpl.");
return (MInteropContext->getAdapter());
return *(MInteropContext->getAdapter());
}

bool SYCLMemObjT::isInterop() const { return MOpenCLInterop; }
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SYCLMemObjT : public SYCLMemObjI {

virtual ~SYCLMemObjT() = default;

const AdapterPtr &getAdapter() const;
adapter_impl &getAdapter() const;

size_t getSizeInBytes() const noexcept override { return MSizeInBytes; }
__SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead")
Expand Down