25 #include <type_traits>
32 typename PropertyListT>
34 template <
typename T,
int Dimensions,
typename AllocatorT,
typename Enable>
36 template <
typename DataT,
int Dimensions, access::mode AccessMode>
47 std::unique_ptr<SYCLMemObjAllocator> Allocator)
48 :
BaseT(SizeInBytes, Props,
std::move(Allocator)) {
50 if (Props.
has_property<sycl::property::buffer::use_host_ptr>())
51 throw sycl::invalid_object_error(
52 "The use_host_ptr property requires host pointer to be provided",
53 PI_ERROR_INVALID_OPERATION);
56 buffer_impl(
void *HostData,
size_t SizeInBytes,
size_t RequiredAlign,
58 std::unique_ptr<SYCLMemObjAllocator> Allocator)
59 :
BaseT(SizeInBytes, Props,
std::move(Allocator)) {
62 sycl::ext::oneapi::property::buffer::use_pinned_host_memory>())
63 throw sycl::invalid_object_error(
64 "The use_pinned_host_memory cannot be used with host pointer",
65 PI_ERROR_INVALID_OPERATION);
67 BaseT::handleHostData(HostData, RequiredAlign);
70 buffer_impl(
const void *HostData,
size_t SizeInBytes,
size_t RequiredAlign,
72 std::unique_ptr<SYCLMemObjAllocator> Allocator)
73 :
BaseT(SizeInBytes, Props,
std::move(Allocator)) {
76 sycl::ext::oneapi::property::buffer::use_pinned_host_memory>())
77 throw sycl::invalid_object_error(
78 "The use_pinned_host_memory cannot be used with host pointer",
79 PI_ERROR_INVALID_OPERATION);
81 BaseT::handleHostData(HostData, RequiredAlign);
85 const size_t SizeInBytes,
size_t RequiredAlign,
87 std::unique_ptr<SYCLMemObjAllocator> Allocator,
bool IsConstPtr)
88 :
BaseT(SizeInBytes, Props,
std::move(Allocator)) {
91 sycl::ext::oneapi::property::buffer::use_pinned_host_memory>())
92 throw sycl::invalid_object_error(
93 "The use_pinned_host_memory cannot be used with host pointer",
94 PI_ERROR_INVALID_OPERATION);
96 BaseT::handleHostData(std::const_pointer_cast<void>(HostData),
97 RequiredAlign, IsConstPtr);
101 const size_t SizeInBytes,
size_t RequiredAlign,
103 std::unique_ptr<detail::SYCLMemObjAllocator> Allocator,
105 :
BaseT(SizeInBytes, Props,
std::move(Allocator)) {
107 sycl::ext::oneapi::property::buffer::use_pinned_host_memory>())
108 throw sycl::invalid_object_error(
109 "The use_pinned_host_memory cannot be used with host pointer",
110 PI_ERROR_INVALID_OPERATION);
112 BaseT::handleHostData(CopyFromInput, RequiredAlign, IsConstPtr);
115 template <
typename T>
116 using EnableIfNotConstIterator =
120 std::unique_ptr<SYCLMemObjAllocator> Allocator,
121 event AvailableEvent)
123 std::move(Allocator), true,
124 std::move(AvailableEvent)) {}
127 std::unique_ptr<SYCLMemObjAllocator> Allocator,
128 bool OwnNativeHandle,
event AvailableEvent)
129 :
BaseT(MemObject, SyclContext, OwnNativeHandle,
130 std::move(AvailableEvent),
std::move(Allocator)) {}
134 const size_t SizeInBytes,
135 std::unique_ptr<SYCLMemObjAllocator> Allocator,
136 event AvailableEvent)
138 SizeInBytes,
std::move(Allocator),
139 std::move(AvailableEvent)) {}
142 const size_t SizeInBytes,
143 std::unique_ptr<SYCLMemObjAllocator> Allocator,
144 event AvailableEvent)
145 :
BaseT(MemObject, SyclContext, SizeInBytes,
std::move(AvailableEvent),
146 std::move(Allocator)) {}
149 void *HostPtr,
RT::PiEvent &OutEventToWait)
override;
151 void *UserObj,
const void *HostObj,
152 const void *Type, uint32_t Dim,
153 uint32_t ElemType,
size_t Range[3]);
154 void destructorNotification(
void *UserObj);
160 BaseT::updateHostMemory();
163 destructorNotification(
this);
166 void resize(
size_t size) { BaseT::MSizeInBytes = size; }
168 void addInteropObject(std::vector<pi_native_handle> &Handles)
const;
170 std::vector<pi_native_handle> getNativeVector(
backend BackendName)
const;