From 00147592d8d519e35f0bc873fac888c1d58110dd Mon Sep 17 00:00:00 2001 From: Kseniya Tikhomirova Date: Thu, 22 Aug 2024 01:50:48 +0200 Subject: [PATCH] [SYCL] Fix regression in update_host (#15153) Restores missed context analysis for host pointer update. Regression is caused by https://github.com/intel/llvm/commit/3dc75a75b624ae2d3fd2e2335a7c6ee054b75366 --------- Signed-off-by: Tikhomirova, Kseniya --- sycl/source/detail/buffer_impl.cpp | 2 +- sycl/source/detail/image_impl.cpp | 2 +- sycl/source/detail/sycl_mem_obj_t.cpp | 8 ++++++-- sycl/source/detail/sycl_mem_obj_t.hpp | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sycl/source/detail/buffer_impl.cpp b/sycl/source/detail/buffer_impl.cpp index cdde8d9ae7d38..1a7c7825a0417 100644 --- a/sycl/source/detail/buffer_impl.cpp +++ b/sycl/source/detail/buffer_impl.cpp @@ -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"); diff --git a/sycl/source/detail/image_impl.cpp b/sycl/source/detail/image_impl.cpp index 7b2e0b559feeb..c93b3d59ce751 100644 --- a/sycl/source/detail/image_impl.cpp +++ b/sycl/source/detail/image_impl.cpp @@ -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) && diff --git a/sycl/source/detail/sycl_mem_obj_t.cpp b/sycl/source/detail/sycl_mem_obj_t.cpp index 83353aff4b65e..457c1c6faada5 100644 --- a/sycl/source/detail/sycl_mem_obj_t.cpp +++ b/sycl/source/detail/sycl_mem_obj_t.cpp @@ -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) @@ -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 @@ -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 " diff --git a/sycl/source/detail/sycl_mem_obj_t.hpp b/sycl/source/detail/sycl_mem_obj_t.hpp index 93a95de976889..9a3e3e23af6c8 100644 --- a/sycl/source/detail/sycl_mem_obj_t.hpp +++ b/sycl/source/detail/sycl_mem_obj_t.hpp @@ -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 MAllocator;