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(urMemBufferCreateWithNativeHandle, MemObject,
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(urMemImageCreateWithNativeHandle, MemObject,
107 sizeof(Context), &Context,
nullptr);
111 "Input context must be the same as the context of cl_mem");
123 const id<3> Offset{0, 0, 0};
129 const int ElemSize = 1;
132 Dims, ElemSize,
size_t(0));
148 std::ignore = Result;
151 "removeMemoryObject should not return false in mem object destructor");
162 "Trying to get Plugin from SYCLMemObjT with nullptr ContextImpl.");
167 ur_native_handle_t MemObject) {
169 const PluginPtr &Plugin = Context->getPlugin();
171 Plugin->call(urMemGetInfo, detail::ur::cast<ur_mem_handle_t>(MemObject),
172 UR_MEM_INFO_SIZE,
sizeof(
size_t), &BufSize,
nullptr);
179 bool &HostPtrReadOnly) {
190 if (InitFromUserData) {
191 assert(!HostPtr &&
"Cannot init from user data and reuse host ptr provided "
196 HostPtrReadOnly =
false;
200 const std::shared_ptr<SYCLMemObjT> &Self)
const {
212 bool InteropObjectsUsed =
217 (!
MRecord->MCurContext ||
MRecord->MCurContext->isOwnedByRuntime()) &&
226 const auto InitialUserPtr =
MUserPtr;
230 for (
auto &it :
MRecord->MAllocaCommands) {
231 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
void determineHostPtr(bool InitFromUserData, void *&HostPtr, bool &HostPtrReadOnly)
ContextImplPtr MInteropContext
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::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()