diff --git a/sycl/source/detail/buffer_impl.cpp b/sycl/source/detail/buffer_impl.cpp index 150ed2c3d0476..676f49a63007d 100644 --- a/sycl/source/detail/buffer_impl.cpp +++ b/sycl/source/detail/buffer_impl.cpp @@ -21,7 +21,7 @@ namespace detail { #ifdef XPTI_ENABLE_INSTRUMENTATION uint8_t GBufferStreamID; #endif -void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData, +void *buffer_impl::allocateMem(context_impl *Context, bool InitFromUserData, void *HostPtr, ur_event_handle_t &OutEventToWait) { bool HostPtrReadOnly = false; @@ -30,9 +30,9 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData, "Internal error. Allocating memory on the host " "while having use_host_ptr property"); return MemoryManager::allocateMemBuffer( - std::move(Context), this, HostPtr, HostPtrReadOnly, - BaseT::getSizeInBytes(), BaseT::MInteropEvent, BaseT::MInteropContext, - MProps, OutEventToWait); + Context, this, HostPtr, HostPtrReadOnly, BaseT::getSizeInBytes(), + BaseT::MInteropEvent, BaseT::MInteropContext.get(), MProps, + OutEventToWait); } void buffer_impl::constructorNotification(const detail::code_location &CodeLoc, void *UserObj, const void *HostObj, diff --git a/sycl/source/detail/buffer_impl.hpp b/sycl/source/detail/buffer_impl.hpp index be3a529f17718..c28cfd4cca05c 100644 --- a/sycl/source/detail/buffer_impl.hpp +++ b/sycl/source/detail/buffer_impl.hpp @@ -129,8 +129,8 @@ class buffer_impl final : public SYCLMemObjT { : BaseT(MemObject, SyclContext, OwnNativeHandle, std::move(AvailableEvent), std::move(Allocator)) {} - void *allocateMem(ContextImplPtr Context, bool InitFromUserData, - void *HostPtr, ur_event_handle_t &OutEventToWait) override; + void *allocateMem(context_impl *Context, bool InitFromUserData, void *HostPtr, + ur_event_handle_t &OutEventToWait) override; void constructorNotification(const detail::code_location &CodeLoc, void *UserObj, const void *HostObj, const void *Type, uint32_t Dim, diff --git a/sycl/source/detail/device_global_map_entry.cpp b/sycl/source/detail/device_global_map_entry.cpp index 908ffbc0bd942..78bd59a9ef795 100644 --- a/sycl/source/detail/device_global_map_entry.cpp +++ b/sycl/source/detail/device_global_map_entry.cpp @@ -46,19 +46,19 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(queue_impl &QueueImpl) { assert(!MIsDeviceImageScopeDecorated && "USM allocations should not be acquired for device_global with " "device_image_scope property."); - const std::shared_ptr &CtxImpl = QueueImpl.getContextImplPtr(); + context_impl &CtxImpl = QueueImpl.getContextImpl(); const device_impl &DevImpl = QueueImpl.getDeviceImpl(); std::lock_guard Lock(MDeviceToUSMPtrMapMutex); - auto DGUSMPtr = MDeviceToUSMPtrMap.find({&DevImpl, CtxImpl.get()}); + auto DGUSMPtr = MDeviceToUSMPtrMap.find({&DevImpl, &CtxImpl}); if (DGUSMPtr != MDeviceToUSMPtrMap.end()) return DGUSMPtr->second; void *NewDGUSMPtr = detail::usm::alignedAllocInternal( - 0, MDeviceGlobalTSize, CtxImpl.get(), &DevImpl, sycl::usm::alloc::device); + 0, MDeviceGlobalTSize, &CtxImpl, &DevImpl, sycl::usm::alloc::device); auto NewAllocIt = MDeviceToUSMPtrMap.emplace( - std::piecewise_construct, std::forward_as_tuple(&DevImpl, CtxImpl.get()), + std::piecewise_construct, std::forward_as_tuple(&DevImpl, &CtxImpl), std::forward_as_tuple(NewDGUSMPtr)); assert(NewAllocIt.second && "USM allocation for device and context already happened."); @@ -83,7 +83,7 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(queue_impl &QueueImpl) { NewAlloc.MInitEvent = InitEvent; } - CtxImpl->addAssociatedDeviceGlobal(MDeviceGlobalPtr); + CtxImpl.addAssociatedDeviceGlobal(MDeviceGlobalPtr); return NewAlloc; } @@ -92,22 +92,20 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(const context &Context) { assert(!MIsDeviceImageScopeDecorated && "USM allocations should not be acquired for device_global with " "device_image_scope property."); - const std::shared_ptr &CtxImpl = getSyclObjImpl(Context); + context_impl &CtxImpl = *getSyclObjImpl(Context); const std::shared_ptr &DevImpl = - getSyclObjImpl(CtxImpl->getDevices().front()); + getSyclObjImpl(CtxImpl.getDevices().front()); std::lock_guard Lock(MDeviceToUSMPtrMapMutex); - auto DGUSMPtr = MDeviceToUSMPtrMap.find({DevImpl.get(), CtxImpl.get()}); + auto DGUSMPtr = MDeviceToUSMPtrMap.find({DevImpl.get(), &CtxImpl}); if (DGUSMPtr != MDeviceToUSMPtrMap.end()) return DGUSMPtr->second; void *NewDGUSMPtr = detail::usm::alignedAllocInternal( - 0, MDeviceGlobalTSize, CtxImpl.get(), DevImpl.get(), - sycl::usm::alloc::device); + 0, MDeviceGlobalTSize, &CtxImpl, DevImpl.get(), sycl::usm::alloc::device); auto NewAllocIt = MDeviceToUSMPtrMap.emplace( - std::piecewise_construct, - std::forward_as_tuple(DevImpl.get(), CtxImpl.get()), + std::piecewise_construct, std::forward_as_tuple(DevImpl.get(), &CtxImpl), std::forward_as_tuple(NewDGUSMPtr)); assert(NewAllocIt.second && "USM allocation for device and context already happened."); @@ -123,9 +121,9 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(const context &Context) { reinterpret_cast( reinterpret_cast(MDeviceGlobalPtr) + sizeof(MDeviceGlobalPtr)), - CtxImpl, MDeviceGlobalTSize, NewAlloc.MPtr); + &CtxImpl, MDeviceGlobalTSize, NewAlloc.MPtr); - CtxImpl->addAssociatedDeviceGlobal(MDeviceGlobalPtr); + CtxImpl.addAssociatedDeviceGlobal(MDeviceGlobalPtr); return NewAlloc; } diff --git a/sycl/source/detail/image_impl.cpp b/sycl/source/detail/image_impl.cpp index 2debdb280f009..47dce9d800dfd 100644 --- a/sycl/source/detail/image_impl.cpp +++ b/sycl/source/detail/image_impl.cpp @@ -259,9 +259,9 @@ image_channel_type convertChannelType(ur_image_channel_type_t Type) { } template -static void getImageInfo(const ContextImplPtr &Context, ur_image_info_t Info, - T &Dest, ur_mem_handle_t InteropMemObject) { - const AdapterPtr &Adapter = Context->getAdapter(); +static void getImageInfo(context_impl &Context, ur_image_info_t Info, T &Dest, + ur_mem_handle_t InteropMemObject) { + const AdapterPtr &Adapter = Context.getAdapter(); Adapter->call(InteropMemObject, Info, sizeof(T), &Dest, nullptr); } @@ -274,8 +274,8 @@ image_impl::image_impl(cl_mem MemObject, const context &SyclContext, std::move(Allocator)), MDimensions(Dimensions), MRange({0, 0, 0}) { ur_mem_handle_t Mem = ur::cast(BaseT::MInteropMemObject); - const ContextImplPtr &Context = getSyclObjImpl(SyclContext); - const AdapterPtr &Adapter = Context->getAdapter(); + detail::context_impl &Context = *getSyclObjImpl(SyclContext); + const AdapterPtr &Adapter = Context.getAdapter(); Adapter->call(Mem, UR_MEM_INFO_SIZE, sizeof(size_t), &(BaseT::MSizeInBytes), nullptr); @@ -323,7 +323,7 @@ image_impl::image_impl(ur_native_handle_t MemObject, const context &SyclContext, setPitches(); // sets MRowPitch, MSlice and BaseT::MSizeInBytes } -void *image_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData, +void *image_impl::allocateMem(context_impl *Context, bool InitFromUserData, void *HostPtr, ur_event_handle_t &OutEventToWait) { bool HostPtrReadOnly = false; @@ -338,13 +338,13 @@ void *image_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData, "The check an image format failed."); return MemoryManager::allocateMemImage( - std::move(Context), this, HostPtr, HostPtrReadOnly, - BaseT::getSizeInBytes(), Desc, Format, BaseT::MInteropEvent, - BaseT::MInteropContext, MProps, OutEventToWait); + Context, this, HostPtr, HostPtrReadOnly, BaseT::getSizeInBytes(), Desc, + Format, BaseT::MInteropEvent, BaseT::MInteropContext.get(), MProps, + OutEventToWait); } bool image_impl::checkImageDesc(const ur_image_desc_t &Desc, - ContextImplPtr Context, void *UserPtr) { + context_impl *Context, void *UserPtr) { if (checkAny(Desc.type, UR_MEM_TYPE_IMAGE1D, UR_MEM_TYPE_IMAGE1D_ARRAY, UR_MEM_TYPE_IMAGE2D_ARRAY, UR_MEM_TYPE_IMAGE2D) && !checkImageValueRange( @@ -409,7 +409,7 @@ bool image_impl::checkImageDesc(const ur_image_desc_t &Desc, } bool image_impl::checkImageFormat(const ur_image_format_t &Format, - ContextImplPtr Context) { + context_impl *Context) { (void)Context; if (checkAny(Format.channelOrder, UR_IMAGE_CHANNEL_ORDER_INTENSITY, UR_IMAGE_CHANNEL_ORDER_LUMINANCE) && @@ -451,7 +451,7 @@ bool image_impl::checkImageFormat(const ur_image_format_t &Format, return true; } -std::vector image_impl::getDevices(const ContextImplPtr Context) { +std::vector image_impl::getDevices(context_impl *Context) { if (!Context) return {}; return Context->get_info(); diff --git a/sycl/source/detail/image_impl.hpp b/sycl/source/detail/image_impl.hpp index 7b4c7508effaf..8eaefe61a48c8 100644 --- a/sycl/source/detail/image_impl.hpp +++ b/sycl/source/detail/image_impl.hpp @@ -254,8 +254,8 @@ class image_impl final : public SYCLMemObjT { std::abort(); } - void *allocateMem(ContextImplPtr Context, bool InitFromUserData, - void *HostPtr, ur_event_handle_t &OutEventToWait) override; + void *allocateMem(context_impl *Context, bool InitFromUserData, void *HostPtr, + ur_event_handle_t &OutEventToWait) override; MemObjType getType() const override { return MemObjType::Image; } @@ -298,7 +298,7 @@ class image_impl final : public SYCLMemObjT { void unsampledImageDestructorNotification(void *UserObj); private: - std::vector getDevices(const ContextImplPtr Context); + std::vector getDevices(context_impl *Context); ur_mem_type_t getImageType() { if (MDimensions == 1) @@ -330,7 +330,7 @@ class image_impl final : public SYCLMemObjT { return Desc; } - bool checkImageDesc(const ur_image_desc_t &Desc, ContextImplPtr Context, + bool checkImageDesc(const ur_image_desc_t &Desc, context_impl *Context, void *UserPtr); ur_image_format_t getImageFormat() { @@ -340,8 +340,7 @@ class image_impl final : public SYCLMemObjT { return Format; } - bool checkImageFormat(const ur_image_format_t &Format, - ContextImplPtr Context); + bool checkImageFormat(const ur_image_format_t &Format, context_impl *Context); uint8_t MDimensions = 0; bool MIsArrayImage = false; diff --git a/sycl/source/detail/memory_manager.cpp b/sycl/source/detail/memory_manager.cpp index 4f7d318e38cde..66fc3d153c1c3 100644 --- a/sycl/source/detail/memory_manager.cpp +++ b/sycl/source/detail/memory_manager.cpp @@ -250,7 +250,7 @@ void memUnmapHelper(const AdapterPtr &Adapter, ur_queue_handle_t Queue, } } -void MemoryManager::release(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, +void MemoryManager::release(context_impl *TargetContext, SYCLMemObjI *MemObj, void *MemAllocation, std::vector DepEvents, ur_event_handle_t &OutEvent) { @@ -262,7 +262,7 @@ void MemoryManager::release(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, MemObj->releaseMem(TargetContext, MemAllocation); } -void MemoryManager::releaseMemObj(ContextImplPtr TargetContext, +void MemoryManager::releaseMemObj(context_impl *TargetContext, SYCLMemObjI *MemObj, void *MemAllocation, void *UserPtr) { if (UserPtr == MemAllocation) { @@ -279,7 +279,7 @@ void MemoryManager::releaseMemObj(ContextImplPtr TargetContext, memReleaseHelper(Adapter, ur::cast(MemAllocation)); } -void *MemoryManager::allocate(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, +void *MemoryManager::allocate(context_impl *TargetContext, SYCLMemObjI *MemObj, bool InitFromUserData, void *HostPtr, std::vector DepEvents, ur_event_handle_t &OutEvent) { @@ -306,8 +306,8 @@ void *MemoryManager::allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr, } void *MemoryManager::allocateInteropMemObject( - ContextImplPtr TargetContext, void *UserPtr, - const EventImplPtr &InteropEvent, const ContextImplPtr &InteropContext, + context_impl *TargetContext, void *UserPtr, + const EventImplPtr &InteropEvent, context_impl *InteropContext, const sycl::property_list &, ur_event_handle_t &OutEventToWait) { (void)TargetContext; (void)InteropContext; @@ -334,7 +334,7 @@ static ur_mem_flags_t getMemObjCreationFlags(void *UserPtr, return Result; } -void *MemoryManager::allocateImageObject(ContextImplPtr TargetContext, +void *MemoryManager::allocateImageObject(context_impl *TargetContext, void *UserPtr, bool HostPtrReadOnly, const ur_image_desc_t &Desc, const ur_image_format_t &Format, @@ -351,7 +351,7 @@ void *MemoryManager::allocateImageObject(ContextImplPtr TargetContext, } void * -MemoryManager::allocateBufferObject(ContextImplPtr TargetContext, void *UserPtr, +MemoryManager::allocateBufferObject(context_impl *TargetContext, void *UserPtr, bool HostPtrReadOnly, const size_t Size, const sycl::property_list &PropsList) { ur_mem_flags_t CreationFlags = @@ -391,11 +391,11 @@ MemoryManager::allocateBufferObject(ContextImplPtr TargetContext, void *UserPtr, return NewMem; } -void *MemoryManager::allocateMemBuffer(ContextImplPtr TargetContext, +void *MemoryManager::allocateMemBuffer(context_impl *TargetContext, SYCLMemObjI *MemObj, void *UserPtr, bool HostPtrReadOnly, size_t Size, const EventImplPtr &InteropEvent, - const ContextImplPtr &InteropContext, + context_impl *InteropContext, const sycl::property_list &PropsList, ur_event_handle_t &OutEventToWait) { void *MemPtr; @@ -414,10 +414,10 @@ void *MemoryManager::allocateMemBuffer(ContextImplPtr TargetContext, } void *MemoryManager::allocateMemImage( - ContextImplPtr TargetContext, SYCLMemObjI *MemObj, void *UserPtr, + context_impl *TargetContext, SYCLMemObjI *MemObj, void *UserPtr, bool HostPtrReadOnly, size_t Size, const ur_image_desc_t &Desc, const ur_image_format_t &Format, const EventImplPtr &InteropEvent, - const ContextImplPtr &InteropContext, const sycl::property_list &PropsList, + context_impl *InteropContext, const sycl::property_list &PropsList, ur_event_handle_t &OutEventToWait) { if (!TargetContext) return allocateHostMemory(MemObj, UserPtr, HostPtrReadOnly, Size, @@ -429,7 +429,7 @@ void *MemoryManager::allocateMemImage( Format, PropsList); } -void *MemoryManager::allocateMemSubBuffer(ContextImplPtr TargetContext, +void *MemoryManager::allocateMemSubBuffer(context_impl *TargetContext, void *ParentMemObj, size_t ElemSize, size_t Offset, range<3> Range, std::vector DepEvents, @@ -891,7 +891,7 @@ void MemoryManager::copy_usm(const void *SrcMem, queue_impl &SrcQueue, DepEvents.data(), OutEvent); } -void MemoryManager::context_copy_usm(const void *SrcMem, ContextImplPtr Context, +void MemoryManager::context_copy_usm(const void *SrcMem, context_impl *Context, size_t Len, void *DstMem) { if (!SrcMem || !DstMem) throw exception(make_error_code(errc::invalid), @@ -962,7 +962,7 @@ void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, bool SupportsUSMMemcpy2D = false; Adapter->call( - Queue.getContextImplPtr()->getHandleRef(), + Queue.getContextImpl().getHandleRef(), UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT, sizeof(bool), &SupportsUSMMemcpy2D, nullptr); @@ -977,7 +977,7 @@ void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, // Otherwise we allow the special case where the copy is to or from host. #ifndef NDEBUG - context Ctx = createSyclObjFromImpl(Queue.getContextImplPtr()); + context Ctx = createSyclObjFromImpl(Queue.getContextImpl()); usm::alloc SrcAllocType = get_pointer_type(SrcMem, Ctx); usm::alloc DstAllocType = get_pointer_type(DstMem, Ctx); bool SrcIsHost = @@ -1136,9 +1136,9 @@ getOrBuildProgramForDeviceGlobal(queue_impl &Queue, // Look for cached programs with the device_global. device Device = Queue.get_device(); - ContextImplPtr ContextImpl = Queue.getContextImplPtr(); + context_impl &ContextImpl = Queue.getContextImpl(); std::optional CachedProgram = - ContextImpl->getProgramForDeviceGlobal(Device, DeviceGlobalEntry); + ContextImpl.getProgramForDeviceGlobal(Device, DeviceGlobalEntry); if (CachedProgram) return *CachedProgram; @@ -1146,7 +1146,7 @@ getOrBuildProgramForDeviceGlobal(queue_impl &Queue, auto Context = createSyclObjFromImpl(ContextImpl); ProgramManager &PM = ProgramManager::getInstance(); RTDeviceBinaryImage &Img = PM.getDeviceImage( - DeviceGlobalEntry->MImages, *ContextImpl, getSyclObjImpl(Device).get()); + DeviceGlobalEntry->MImages, ContextImpl, getSyclObjImpl(Device).get()); device_image_plain DeviceImage = PM.getDeviceImageFromBinaryImage(&Img, Context, Device); device_image_plain BuiltImage = @@ -1228,7 +1228,7 @@ void MemoryManager::copy_from_device_global( // Command buffer methods void MemoryManager::ext_oneapi_copyD2D_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, void *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize, sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset, @@ -1294,7 +1294,7 @@ void MemoryManager::ext_oneapi_copyD2D_cmd_buffer( } void MemoryManager::ext_oneapi_copyD2H_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, void *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize, sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset, @@ -1370,7 +1370,7 @@ void MemoryManager::ext_oneapi_copyD2H_cmd_buffer( } void MemoryManager::ext_oneapi_copyH2D_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, char *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize, sycl::id<3> SrcOffset, unsigned int SrcElemSize, void *DstMem, @@ -1448,7 +1448,7 @@ void MemoryManager::ext_oneapi_copyH2D_cmd_buffer( } void MemoryManager::ext_oneapi_copy_usm_cmd_buffer( - ContextImplPtr Context, const void *SrcMem, + context_impl *Context, const void *SrcMem, ur_exp_command_buffer_handle_t CommandBuffer, size_t Len, void *DstMem, std::vector Deps, ur_exp_command_buffer_sync_point_t *OutSyncPoint) { @@ -1471,7 +1471,7 @@ void MemoryManager::ext_oneapi_copy_usm_cmd_buffer( } void MemoryManager::ext_oneapi_fill_usm_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, void *DstMem, size_t Len, const std::vector &Pattern, std::vector Deps, @@ -1496,7 +1496,7 @@ void MemoryManager::ext_oneapi_fill_usm_cmd_buffer( } void MemoryManager::ext_oneapi_fill_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, void *Mem, size_t PatternSize, const unsigned char *Pattern, unsigned int Dim, sycl::range<3> Size, sycl::range<3> AccessRange, @@ -1533,7 +1533,7 @@ void MemoryManager::ext_oneapi_fill_cmd_buffer( } void MemoryManager::ext_oneapi_prefetch_usm_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, void *Mem, size_t Length, std::vector Deps, ur_exp_command_buffer_sync_point_t *OutSyncPoint) { @@ -1544,7 +1544,7 @@ void MemoryManager::ext_oneapi_prefetch_usm_cmd_buffer( } void MemoryManager::ext_oneapi_advise_usm_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, const void *Mem, size_t Length, ur_usm_advice_flags_t Advice, std::vector Deps, diff --git a/sycl/source/detail/memory_manager.hpp b/sycl/source/detail/memory_manager.hpp index 30d790189fad2..08da3bb25d482 100644 --- a/sycl/source/detail/memory_manager.hpp +++ b/sycl/source/detail/memory_manager.hpp @@ -30,7 +30,6 @@ class context_impl; using QueueImplPtr = std::shared_ptr; using EventImplPtr = std::shared_ptr; -using ContextImplPtr = std::shared_ptr; // The class contains methods that work with memory. All operations with // device memory should go through MemoryManager. @@ -39,20 +38,20 @@ class MemoryManager { public: // The following method releases memory allocation of memory object. // Depending on the context it releases memory on host or on device. - static void release(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, + static void release(context_impl *TargetContext, SYCLMemObjI *MemObj, void *MemAllocation, std::vector DepEvents, ur_event_handle_t &OutEvent); // The following method allocates memory allocation of memory object. // Depending on the context it allocates memory on host or on device. - static void *allocate(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, + static void *allocate(context_impl *TargetContext, SYCLMemObjI *MemObj, bool InitFromUserData, void *HostPtr, std::vector DepEvents, ur_event_handle_t &OutEvent); // The following method creates OpenCL sub buffer for specified // offset, range, and memory object. - static void *allocateMemSubBuffer(ContextImplPtr TargetContext, + static void *allocateMemSubBuffer(context_impl *TargetContext, void *ParentMemObj, size_t ElemSize, size_t Offset, range<3> Range, std::vector DepEvents, @@ -61,11 +60,11 @@ class MemoryManager { // Allocates buffer in specified context taking into account situations such // as host ptr or cl_mem provided by user. TargetContext should be device // one(not host). - static void *allocateMemBuffer(ContextImplPtr TargetContext, + static void *allocateMemBuffer(context_impl *TargetContext, SYCLMemObjI *MemObj, void *UserPtr, bool HostPtrReadOnly, size_t Size, const EventImplPtr &InteropEvent, - const ContextImplPtr &InteropContext, + context_impl *InteropContext, const sycl::property_list &PropsList, ur_event_handle_t &OutEventToWait); @@ -73,35 +72,35 @@ class MemoryManager { // as host ptr or cl_mem provided by user. TargetContext should be device // one(not host). static void *allocateMemImage( - ContextImplPtr TargetContext, SYCLMemObjI *MemObj, void *UserPtr, + context_impl *TargetContext, SYCLMemObjI *MemObj, void *UserPtr, bool HostPtrReadOnly, size_t Size, const ur_image_desc_t &Desc, const ur_image_format_t &Format, const EventImplPtr &InteropEvent, - const ContextImplPtr &InteropContext, - const sycl::property_list &PropsList, ur_event_handle_t &OutEventToWait); + context_impl *InteropContext, const sycl::property_list &PropsList, + ur_event_handle_t &OutEventToWait); // Releases memory object(buffer or image). TargetContext should be device // one(not host). - static void releaseMemObj(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, + static void releaseMemObj(context_impl *TargetContext, SYCLMemObjI *MemObj, void *MemAllocation, void *UserPtr); static void *allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr, bool HostPtrReadOnly, size_t Size, const sycl::property_list &PropsList); - static void *allocateInteropMemObject(ContextImplPtr TargetContext, + static void *allocateInteropMemObject(context_impl *TargetContext, void *UserPtr, const EventImplPtr &InteropEvent, - const ContextImplPtr &InteropContext, + context_impl *InteropContext, const sycl::property_list &PropsList, ur_event_handle_t &OutEventToWait); - static void *allocateImageObject(ContextImplPtr TargetContext, void *UserPtr, + static void *allocateImageObject(context_impl *TargetContext, void *UserPtr, bool HostPtrReadOnly, const ur_image_desc_t &Desc, const ur_image_format_t &Format, const sycl::property_list &PropsList); - static void *allocateBufferObject(ContextImplPtr TargetContext, void *UserPtr, + static void *allocateBufferObject(context_impl *TargetContext, void *UserPtr, bool HostPtrReadOnly, const size_t Size, const sycl::property_list &PropsList); @@ -140,7 +139,7 @@ class MemoryManager { void *DstMem, std::vector DepEvents, ur_event_handle_t *OutEvent); - static void context_copy_usm(const void *SrcMem, ContextImplPtr Context, + static void context_copy_usm(const void *SrcMem, context_impl *Context, size_t Len, void *DstMem); static void fill_usm(void *DstMem, queue_impl &Queue, size_t Len, @@ -190,7 +189,7 @@ class MemoryManager { // Command buffer extension methods static void ext_oneapi_copyD2D_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, void *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize, sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset, @@ -201,7 +200,7 @@ class MemoryManager { ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_copyD2H_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, void *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize, sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset, @@ -211,7 +210,7 @@ class MemoryManager { ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_copyH2D_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, char *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize, sycl::id<3> SrcOffset, unsigned int SrcElemSize, void *DstMem, @@ -222,20 +221,20 @@ class MemoryManager { ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_copy_usm_cmd_buffer( - ContextImplPtr Context, const void *SrcMem, + context_impl *Context, const void *SrcMem, ur_exp_command_buffer_handle_t CommandBuffer, size_t Len, void *DstMem, std::vector Deps, ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_fill_usm_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, void *DstMem, size_t Len, const std::vector &Pattern, std::vector Deps, ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_fill_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj, void *Mem, size_t PatternSize, const unsigned char *Pattern, unsigned int Dim, sycl::range<3> Size, sycl::range<3> AccessRange, @@ -244,13 +243,13 @@ class MemoryManager { ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_prefetch_usm_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, void *Mem, size_t Length, std::vector Deps, ur_exp_command_buffer_sync_point_t *OutSyncPoint); static void ext_oneapi_advise_usm_cmd_buffer( - sycl::detail::ContextImplPtr Context, + sycl::detail::context_impl *Context, ur_exp_command_buffer_handle_t CommandBuffer, const void *Mem, size_t Length, ur_usm_advice_flags_t Advice, std::vector Deps, diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index a79884f2c46d5..04d36259c2de9 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -295,6 +295,8 @@ class queue_impl : public std::enable_shared_from_this { const ContextImplPtr &getContextImplPtr() const { return MContext; } + context_impl &getContextImpl() const { return *MContext; } + device_impl &getDeviceImpl() const { return MDevice; } /// \return an associated SYCL device. diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index d376db2d398c8..1d0eef264d196 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -127,9 +127,9 @@ static unsigned long long getQueueID(const std::shared_ptr &Queue) { } #endif -static ContextImplPtr getContext(const QueueImplPtr &Queue) { +static context_impl *getContext(const QueueImplPtr &Queue) { if (Queue) - return Queue->getContextImplPtr(); + return &Queue->getContextImpl(); return nullptr; } @@ -1299,7 +1299,8 @@ ur_result_t ReleaseCommand::enqueueImp() { : MAllocaCmd->getQueue(); EventImplPtr UnmapEventImpl(new event_impl(Queue)); - UnmapEventImpl->setContextImpl(getContext(Queue)); + UnmapEventImpl->setContextImpl(Queue ? Queue->getContextImplPtr() + : nullptr); UnmapEventImpl->setStateIncomplete(); ur_event_handle_t UREvent = nullptr; @@ -2876,7 +2877,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { CGCopyUSM *Copy = (CGCopyUSM *)MCommandGroup.get(); if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_copy_usm_cmd_buffer, - MQueue->getContextImplPtr(), Copy->getSrc(), MCommandBuffer, + &MQueue->getContextImpl(), Copy->getSrc(), MCommandBuffer, Copy->getLength(), Copy->getDst(), MSyncPointDeps, &OutSyncPoint); Result != UR_RESULT_SUCCESS) return Result; @@ -2894,7 +2895,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_copyD2D_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, + &MQueue->getContextImpl(), MCommandBuffer, AllocaCmdSrc->getSYCLMemObj(), AllocaCmdSrc->getMemAllocation(), ReqSrc->MDims, ReqSrc->MMemoryRange, ReqSrc->MAccessRange, ReqSrc->MOffset, ReqSrc->MElemSize, @@ -2914,7 +2915,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_copyD2H_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, + &MQueue->getContextImpl(), MCommandBuffer, AllocaCmd->getSYCLMemObj(), AllocaCmd->getMemAllocation(), Req->MDims, Req->MMemoryRange, Req->MAccessRange, Req->MOffset, Req->MElemSize, (char *)Copy->getDst(), Req->MDims, @@ -2934,7 +2935,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_copyH2D_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, + &MQueue->getContextImpl(), MCommandBuffer, AllocaCmd->getSYCLMemObj(), (char *)Copy->getSrc(), Req->MDims, Req->MAccessRange, /*SrcOffset*/ sycl::id<3>{0, 0, 0}, Req->MElemSize, @@ -2954,7 +2955,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_fill_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, + &MQueue->getContextImpl(), MCommandBuffer, AllocaCmd->getSYCLMemObj(), AllocaCmd->getMemAllocation(), Fill->MPattern.size(), Fill->MPattern.data(), Req->MDims, Req->MMemoryRange, Req->MAccessRange, Req->MOffset, Req->MElemSize, @@ -2969,7 +2970,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { CGFillUSM *Fill = (CGFillUSM *)MCommandGroup.get(); if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_fill_usm_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, Fill->getDst(), + &MQueue->getContextImpl(), MCommandBuffer, Fill->getDst(), Fill->getLength(), Fill->getPattern(), std::move(MSyncPointDeps), &OutSyncPoint); Result != UR_RESULT_SUCCESS) @@ -2982,7 +2983,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { CGPrefetchUSM *Prefetch = (CGPrefetchUSM *)MCommandGroup.get(); if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_prefetch_usm_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, Prefetch->getDst(), + &MQueue->getContextImpl(), MCommandBuffer, Prefetch->getDst(), Prefetch->getLength(), std::move(MSyncPointDeps), &OutSyncPoint); Result != UR_RESULT_SUCCESS) return Result; @@ -2994,7 +2995,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { CGAdviseUSM *Advise = (CGAdviseUSM *)MCommandGroup.get(); if (auto Result = callMemOpHelper( MemoryManager::ext_oneapi_advise_usm_cmd_buffer, - MQueue->getContextImplPtr(), MCommandBuffer, Advise->getDst(), + &MQueue->getContextImpl(), MCommandBuffer, Advise->getDst(), Advise->getLength(), Advise->getAdvice(), std::move(MSyncPointDeps), &OutSyncPoint); Result != UR_RESULT_SUCCESS) @@ -3051,7 +3052,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { Req->MSYCLMemObj->MRecord->MAllocaCommands; for (AllocaCommandBase *AllocaCmd : AllocaCmds) - if (ContextImpl == getContext(AllocaCmd->getQueue())) { + if (ContextImpl.get() == getContext(AllocaCmd->getQueue())) { auto MemArg = reinterpret_cast(AllocaCmd->getMemAllocation()); ReqToMem.emplace_back(std::make_pair(Req, MemArg)); diff --git a/sycl/source/detail/sycl_mem_obj_i.hpp b/sycl/source/detail/sycl_mem_obj_i.hpp index 776b74a85e03a..68c8de30cfd21 100644 --- a/sycl/source/detail/sycl_mem_obj_i.hpp +++ b/sycl/source/detail/sycl_mem_obj_i.hpp @@ -44,7 +44,7 @@ class SYCLMemObjI { // Non null HostPtr requires allocation to be made with USE_HOST_PTR property. // Method returns a pointer to host allocation if Context is host one and // cl_mem obect if not. - virtual void *allocateMem(ContextImplPtr Context, bool InitFromUserData, + virtual void *allocateMem(context_impl *Context, bool InitFromUserData, void *HostPtr, ur_event_handle_t &InteropEvent) = 0; // Should be used for memory object created without use_host_ptr property. @@ -54,7 +54,7 @@ class SYCLMemObjI { // If Context is a device context and Ptr is a host pointer exception will be // thrown. And it's undefined behaviour if Context is a host context and Ptr // is a device pointer. - virtual void releaseMem(ContextImplPtr Context, void *Ptr) = 0; + virtual void releaseMem(context_impl *Context, void *Ptr) = 0; // Ptr must be a pointer returned by allocateHostMem. virtual void releaseHostMem(void *Ptr) = 0; diff --git a/sycl/source/detail/sycl_mem_obj_t.cpp b/sycl/source/detail/sycl_mem_obj_t.cpp index f289c1e62b371..1769d4092d79b 100644 --- a/sycl/source/detail/sycl_mem_obj_t.cpp +++ b/sycl/source/detail/sycl_mem_obj_t.cpp @@ -118,7 +118,7 @@ SYCLMemObjT::SYCLMemObjT(ur_native_handle_t MemObject, } } -void SYCLMemObjT::releaseMem(ContextImplPtr Context, void *MemAllocation) { +void SYCLMemObjT::releaseMem(context_impl *Context, void *MemAllocation) { void *Ptr = getUserPtr(); return MemoryManager::releaseMemObj(Context, this, MemAllocation, Ptr); } @@ -180,9 +180,8 @@ size_t SYCLMemObjT::getBufSizeForContext(const ContextImplPtr &Context, bool SYCLMemObjT::isInterop() const { return MOpenCLInterop; } -void SYCLMemObjT::determineHostPtr(const ContextImplPtr &Context, - bool InitFromUserData, void *&HostPtr, - bool &HostPtrReadOnly) { +void SYCLMemObjT::determineHostPtr(context_impl *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 // HostPtr. We can have one of these scenarios: diff --git a/sycl/source/detail/sycl_mem_obj_t.hpp b/sycl/source/detail/sycl_mem_obj_t.hpp index cd3a717fdb8cf..3077269d544b6 100644 --- a/sycl/source/detail/sycl_mem_obj_t.hpp +++ b/sycl/source/detail/sycl_mem_obj_t.hpp @@ -128,7 +128,7 @@ class SYCLMemObjT : public SYCLMemObjI { MAllocator->deallocate(Ptr, size()); } - void releaseMem(ContextImplPtr Context, void *MemAllocation) override; + void releaseMem(context_impl *Context, void *MemAllocation) override; void *getUserPtr() const { return MOpenCLInterop ? static_cast(MInteropMemObject) : MUserPtr; @@ -273,8 +273,8 @@ class SYCLMemObjT : public SYCLMemObjI { void handleWriteAccessorCreation(); - void *allocateMem(ContextImplPtr Context, bool InitFromUserData, - void *HostPtr, ur_event_handle_t &InteropEvent) override { + void *allocateMem(context_impl *Context, bool InitFromUserData, void *HostPtr, + ur_event_handle_t &InteropEvent) override { (void)Context; (void)InitFromUserData; (void)HostPtr; @@ -331,7 +331,7 @@ class SYCLMemObjT : public SYCLMemObjI { protected: // An allocateMem helper that determines which host ptr to use - void determineHostPtr(const ContextImplPtr &Context, bool InitFromUserData, + void determineHostPtr(context_impl *Context, bool InitFromUserData, void *&HostPtr, bool &HostPtrReadOnly); // Allocator used for allocation memory on host. diff --git a/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp b/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp index 1a5fa726170b8..96d688bfedd00 100644 --- a/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp +++ b/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp @@ -15,8 +15,6 @@ using namespace sycl; class MemObjMock : public sycl::detail::SYCLMemObjI { public: - using ContextImplPtr = std::shared_ptr; - MemObjMock(const std::shared_ptr &Record) : SYCLMemObjI() { MRecord = Record; @@ -26,12 +24,13 @@ class MemObjMock : public sycl::detail::SYCLMemObjI { MemObjType getType() const override { return MemObjType::Buffer; } - void *allocateMem(ContextImplPtr, bool, void *, ur_event_handle_t &) { + void *allocateMem(detail::context_impl *, bool, void *, + ur_event_handle_t &) override { return nullptr; } void *allocateHostMem() { return nullptr; } - void releaseMem(ContextImplPtr, void *) {} + void releaseMem(detail::context_impl *, void *) override {} void releaseHostMem(void *) {} size_t getSizeInBytes() const noexcept override { return 10; } bool isInterop() const override { return false; } @@ -39,7 +38,10 @@ class MemObjMock : public sycl::detail::SYCLMemObjI { bool isHostPointerReadOnly() const override { return false; } bool usesPinnedHostMemory() const override { return false; } - detail::ContextImplPtr getInteropContext() const override { return nullptr; } + std::shared_ptr + getInteropContext() const override { + return nullptr; + } }; static sycl::device getDeviceWithHostUnifiedMemory(sycl::platform &Plt) {