17 inline namespace _V1 {
21 const context &SyclContext,
const size_t,
23 std::unique_ptr<SYCLMemObjAllocator> Allocator)
24 :
SYCLMemObjT(MemObject, SyclContext, true, AvailableEvent,
25 std::move(Allocator)) {}
28 const context &SyclContext,
bool OwnNativeHandle,
30 std::unique_ptr<SYCLMemObjAllocator> Allocator)
31 : MAllocator(
std::move(Allocator)), MProps(),
34 MOpenCLInterop(true), MHostPtrReadOnly(false), MNeedWriteBack(true),
35 MUserPtr(nullptr), MShadowCopy(nullptr), MUploadDataFunctor(nullptr),
36 MSharedPtrStorage(nullptr), MHostPtrProvided(true),
37 MOwnNativeHandle(OwnNativeHandle) {
38 ur_context_handle_t Context =
nullptr;
41 ur_mem_native_properties_t MemProperties = {
42 UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
nullptr, OwnNativeHandle};
43 Plugin->call<UrApiKind::urMemBufferCreateWithNativeHandle>(
52 sizeof(Context), &Context,
nullptr);
57 "Input context must be the same as the context of cl_mem");
65 return UR_MEM_TYPE_IMAGE1D;
67 return UR_MEM_TYPE_IMAGE2D;
68 return UR_MEM_TYPE_IMAGE3D;
72 const context &SyclContext,
bool OwnNativeHandle,
74 std::unique_ptr<SYCLMemObjAllocator> Allocator,
75 ur_image_format_t Format,
range<3> Range3WithOnes,
77 : MAllocator(
std::move(Allocator)), MProps(),
80 MOpenCLInterop(true), MHostPtrReadOnly(false), MNeedWriteBack(true),
81 MUserPtr(nullptr), MShadowCopy(nullptr), MUploadDataFunctor(nullptr),
82 MSharedPtrStorage(nullptr), MHostPtrProvided(true),
83 MOwnNativeHandle(OwnNativeHandle) {
84 ur_context_handle_t Context =
nullptr;
87 ur_image_desc_t Desc = {};
88 Desc.stype = UR_STRUCTURE_TYPE_IMAGE_DESC;
90 Desc.width = Range3WithOnes[0];
91 Desc.height = Range3WithOnes[1];
92 Desc.depth = Range3WithOnes[2];
94 Desc.rowPitch = ElementSize * Desc.width;
95 Desc.slicePitch = Desc.rowPitch * Desc.height;
99 ur_mem_native_properties_t NativeProperties = {
100 UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
nullptr, OwnNativeHandle};
102 Plugin->call<UrApiKind::urMemImageCreateWithNativeHandle>(
107 sizeof(Context), &Context,
nullptr);
112 "Input context must be the same as the context of cl_mem");
124 const id<3> Offset{0, 0, 0};
130 const int ElemSize = 1;
133 Dims, ElemSize,
size_t(0));
149 std::ignore = Result;
152 "removeMemoryObject should not return false in mem object destructor");
163 "Trying to get Plugin from SYCLMemObjT with nullptr ContextImpl.");
168 ur_native_handle_t MemObject) {
170 const PluginPtr &Plugin = Context->getPlugin();
172 Plugin->call<UrApiKind::urMemGetInfo>(
173 detail::ur::cast<ur_mem_handle_t>(MemObject), UR_MEM_INFO_SIZE,
174 sizeof(size_t), &BufSize,
nullptr);
181 bool InitFromUserData,
void *&HostPtr,
182 bool &HostPtrReadOnly) {
193 InitFromUserData =
true;
195 if (InitFromUserData) {
196 assert(!HostPtr &&
"Cannot init from user data and reuse host ptr provided "
201 HostPtrReadOnly =
false;
205 const std::shared_ptr<SYCLMemObjT> &Self)
const {
217 bool InteropObjectsUsed =
222 (!
MRecord->MCurContext ||
MRecord->MCurContext->isOwnedByRuntime()) &&
231 const auto InitialUserPtr =
MUserPtr;
238 for (
auto &it :
MRecord->MAllocaCommands) {
239 if (it->MMemAllocation == InitialUserPtr) {
The context class represents a SYCL context on which kernel functions may be executed.
static GlobalHandler & instance()
static void releaseMemObj(ContextImplPtr TargetContext, SYCLMemObjI *MemObj, void *MemAllocation, void *UserPtr)
std::shared_ptr< MemObjRecord > MRecord
const PluginPtr & getPlugin() const
void detachMemoryObject(const std::shared_ptr< SYCLMemObjT > &Self) const
ContextImplPtr MInteropContext
void determineHostPtr(const ContextImplPtr &Context, bool InitFromUserData, void *&HostPtr, bool &HostPtrReadOnly)
void releaseHostMem(void *Ptr) override
ur_mem_handle_t MInteropMemObject
void releaseMem(ContextImplPtr Context, void *MemAllocation) override
void handleWriteAccessorCreation()
void * getUserPtr() const
SYCLMemObjT(const size_t SizeInBytes, const property_list &Props, std::unique_ptr< SYCLMemObjAllocator > Allocator)
std::function< void(void)> MUploadDataFunctor
std::mutex MCreateShadowCopyMtx
std::function< void(void)> MCreateShadowCopy
bool isInterop() const override
static size_t getBufSizeForContext(const ContextImplPtr &Context, ur_native_handle_t MemObject)
EventImplPtr addCopyBack(Requirement *Req)
Registers a command group, that copies most recent memory to the memory pointed by the requirement.
static Scheduler & getInstance()
bool removeMemoryObject(detail::SYCLMemObjI *MemObj, bool StrictLock=true)
Removes buffer from the graph.
void deferMemObjRelease(const std::shared_ptr< detail::SYCLMemObjI > &MemObj)
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
ur_mem_type_t getImageType(int Dimensions)
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
std::shared_ptr< event_impl > EventImplPtr
std::shared_ptr< plugin > PluginPtr
class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()