Skip to content

[SYCL] Adding support for buffer::use_pinned_host_memory property #2080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,

return MemoryManager::allocateMemBuffer(
std::move(Context), this, UserPtr, BaseT::MHostPtrReadOnly,
BaseT::getSize(), BaseT::MInteropEvent, BaseT::MInteropContext,
BaseT::getSize(), BaseT::MInteropEvent, BaseT::MInteropContext, MProps,
OutEventToWait);
}
} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/image_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void *image_impl<Dimensions>::allocateMem(ContextImplPtr Context,
return MemoryManager::allocateMemImage(
std::move(Context), this, UserPtr, BaseT::MHostPtrReadOnly,
BaseT::getSize(), Desc, Format, BaseT::MInteropEvent,
BaseT::MInteropContext, OutEventToWait);
BaseT::MInteropContext, MProps, OutEventToWait);
}

template <int Dimensions>
Expand Down
39 changes: 25 additions & 14 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void *MemoryManager::wrapIntoImageBuffer(ContextImplPtr TargetContext,
}

void *MemoryManager::allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr,
bool HostPtrReadOnly, size_t Size) {
bool HostPtrReadOnly, size_t Size,
const sycl::property_list &) {
// Can return user pointer directly if it points to writable memory.
if (UserPtr && HostPtrReadOnly == false)
return UserPtr;
Expand All @@ -123,7 +124,7 @@ void *MemoryManager::allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr,
void *MemoryManager::allocateInteropMemObject(
ContextImplPtr TargetContext, void *UserPtr,
const EventImplPtr &InteropEvent, const ContextImplPtr &InteropContext,
RT::PiEvent &OutEventToWait) {
const sycl::property_list &, RT::PiEvent &OutEventToWait) {
// If memory object is created with interop c'tor.
// Return cl_mem as is if contexts match.
if (TargetContext == InteropContext) {
Expand All @@ -144,7 +145,8 @@ void *MemoryManager::allocateInteropMemObject(
void *MemoryManager::allocateImageObject(ContextImplPtr TargetContext,
void *UserPtr, bool HostPtrReadOnly,
const RT::PiMemImageDesc &Desc,
const RT::PiMemImageFormat &Format) {
const RT::PiMemImageFormat &Format,
const sycl::property_list &) {
// Create read_write mem object by default to handle arbitrary uses.
RT::PiMemFlags CreationFlags = PI_MEM_FLAGS_ACCESS_RW;
if (UserPtr)
Expand All @@ -159,16 +161,20 @@ void *MemoryManager::allocateImageObject(ContextImplPtr TargetContext,
return NewMem;
}

void *MemoryManager::allocateBufferObject(ContextImplPtr TargetContext,
void *UserPtr, bool HostPtrReadOnly,
const size_t Size) {
void *
MemoryManager::allocateBufferObject(ContextImplPtr TargetContext, void *UserPtr,
bool HostPtrReadOnly, const size_t Size,
const sycl::property_list &PropsList) {
// Create read_write mem object by default to handle arbitrary uses.
RT::PiMemFlags CreationFlags = PI_MEM_FLAGS_ACCESS_RW;
if (UserPtr)
CreationFlags |= HostPtrReadOnly ? PI_MEM_FLAGS_HOST_PTR_COPY
: PI_MEM_FLAGS_HOST_PTR_USE;
else if (PropsList.has_property<
sycl::ext::oneapi::property::buffer::use_pinned_host_memory>())
CreationFlags |= PI_MEM_FLAGS_HOST_PTR_ALLOC;

RT::PiMem NewMem;
RT::PiMem NewMem = nullptr;
const detail::plugin &Plugin = TargetContext->getPlugin();
Plugin.call<PiApiKind::piMemBufferCreate>(
TargetContext->getHandleRef(), CreationFlags, Size, UserPtr, &NewMem);
Expand All @@ -180,27 +186,32 @@ void *MemoryManager::allocateMemBuffer(ContextImplPtr TargetContext,
bool HostPtrReadOnly, size_t Size,
const EventImplPtr &InteropEvent,
const ContextImplPtr &InteropContext,
const sycl::property_list &PropsList,
RT::PiEvent &OutEventToWait) {
if (TargetContext->is_host())
return allocateHostMemory(MemObj, UserPtr, HostPtrReadOnly, Size);
return allocateHostMemory(MemObj, UserPtr, HostPtrReadOnly, Size,
PropsList);
if (UserPtr && InteropContext)
return allocateInteropMemObject(TargetContext, UserPtr, InteropEvent,
InteropContext, OutEventToWait);
return allocateBufferObject(TargetContext, UserPtr, HostPtrReadOnly, Size);
InteropContext, PropsList, OutEventToWait);
return allocateBufferObject(TargetContext, UserPtr, HostPtrReadOnly, Size,
PropsList);
}

void *MemoryManager::allocateMemImage(
ContextImplPtr TargetContext, SYCLMemObjI *MemObj, void *UserPtr,
bool HostPtrReadOnly, size_t Size, const RT::PiMemImageDesc &Desc,
const RT::PiMemImageFormat &Format, const EventImplPtr &InteropEvent,
const ContextImplPtr &InteropContext, RT::PiEvent &OutEventToWait) {
const ContextImplPtr &InteropContext, const sycl::property_list &PropsList,
RT::PiEvent &OutEventToWait) {
if (TargetContext->is_host())
return allocateHostMemory(MemObj, UserPtr, HostPtrReadOnly, Size);
return allocateHostMemory(MemObj, UserPtr, HostPtrReadOnly, Size,
PropsList);
if (UserPtr && InteropContext)
return allocateInteropMemObject(TargetContext, UserPtr, InteropEvent,
InteropContext, OutEventToWait);
InteropContext, PropsList, OutEventToWait);
return allocateImageObject(TargetContext, UserPtr, HostPtrReadOnly, Desc,
Format);
Format, PropsList);
}

void *MemoryManager::allocateMemSubBuffer(ContextImplPtr TargetContext,
Expand Down
Loading