Skip to content

Commit

Permalink
[SYCL] Fix regression in update_host (#15153)
Browse files Browse the repository at this point in the history
Restores missed context analysis for host pointer update.
Regression is caused by
3dc75a7

---------

Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
  • Loading branch information
KseniyaTikhomirova authored Aug 21, 2024
1 parent 399574e commit 0014759
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
void *HostPtr,
ur_event_handle_t &OutEventToWait) {
bool HostPtrReadOnly = false;
BaseT::determineHostPtr(InitFromUserData, HostPtr, HostPtrReadOnly);
BaseT::determineHostPtr(Context, InitFromUserData, HostPtr, HostPtrReadOnly);
assert(!(nullptr == HostPtr && BaseT::useHostPtr() && !Context) &&
"Internal error. Allocating memory on the host "
"while having use_host_ptr property");
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/image_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void *image_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
void *HostPtr,
ur_event_handle_t &OutEventToWait) {
bool HostPtrReadOnly = false;
BaseT::determineHostPtr(InitFromUserData, HostPtr, HostPtrReadOnly);
BaseT::determineHostPtr(Context, InitFromUserData, HostPtr, HostPtrReadOnly);

ur_image_desc_t Desc = getImageDesc(HostPtr != nullptr);
assert(checkImageDesc(Desc, Context, HostPtr) &&
Expand Down
8 changes: 6 additions & 2 deletions sycl/source/detail/sycl_mem_obj_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ SYCLMemObjT::SYCLMemObjT(ur_native_handle_t MemObject,
sizeof(Context), &Context, nullptr);

if (MInteropContext->getHandleRef() != Context)
throw sycl::exception(make_error_code(errc::invalid),
throw sycl::exception(
make_error_code(errc::invalid),
"Input context must be the same as the context of cl_mem");

if (MInteropContext->getBackend() == backend::opencl)
Expand Down Expand Up @@ -175,7 +176,8 @@ size_t SYCLMemObjT::getBufSizeForContext(const ContextImplPtr &Context,

bool SYCLMemObjT::isInterop() const { return MOpenCLInterop; }

void SYCLMemObjT::determineHostPtr(bool InitFromUserData, void *&HostPtr,
void SYCLMemObjT::determineHostPtr(const ContextImplPtr &Context,
bool InitFromUserData, void *&HostPtr,
bool &HostPtrReadOnly) {
// The data for the allocation can be provided via either the user pointer
// (InitFromUserData, can be read-only) or a runtime-allocated read-write
Expand All @@ -186,6 +188,8 @@ void SYCLMemObjT::determineHostPtr(bool InitFromUserData, void *&HostPtr,
// 2. The allocation is not the first one and not on host. InitFromUserData ==
// false, HostPtr is provided if the command is linked. The host pointer is
// guaranteed to be reused in this case.
if (!Context && !MOpenCLInterop && !MHostPtrReadOnly)
InitFromUserData = true;

if (InitFromUserData) {
assert(!HostPtr && "Cannot init from user data and reuse host ptr provided "
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ class SYCLMemObjT : public SYCLMemObjI {

protected:
// An allocateMem helper that determines which host ptr to use
void determineHostPtr(bool InitFromUserData, void *&HostPtr,
bool &HostPtrReadOnly);
void determineHostPtr(const ContextImplPtr &Context, bool InitFromUserData,
void *&HostPtr, bool &HostPtrReadOnly);

// Allocator used for allocation memory on host.
std::unique_ptr<SYCLMemObjAllocator> MAllocator;
Expand Down

0 comments on commit 0014759

Please sign in to comment.