-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][L0] Add support for pinned host memory. #2633
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
c621923
to
bb4bd5e
Compare
We do need a test for this. Please make sure to cover the interaction of such (pinned) allocated memory and mapping/unmapping. |
|
||
ZE_CALL( | ||
zeMemAllocDevice(Context->ZeContext, &ZeDesc, Size, 1, ZeDevice, &Ptr)); | ||
ZE_CALL(zeMemAllocShared(Context->ZeContext, &ZeDeviceMemDesc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the DeviceIsIntegrated
then the zeMemAllocHost
is sufficient, and I believe is faster. Otherwise, as requested by user, the allocation should be accessible from the host, so zeMemAllocSahred
seems good then. I am not sure what will be the interaction of such allocated buffer with the map/unmap operations, whose implementations are highly coupled with this create one. Please add a functional test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1957,6 +1973,8 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size, | |||
HostPtr, Size, nullptr, 0, | |||
nullptr)); | |||
} | |||
} else if ((Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not setting the HostPtr
to the allocated memory, so you can't get here, right? (line 1962 should be false). So why is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead verify that HostPtr
is null when PI_MEM_FLAGS_HOST_PTR_ALLOC is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smaslov-intel are you saying that hostPtr and PI_MEM_FLAGS_HOST_PTR_ALLOC is mutually exclusive? My understanding was that they are not. fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see in https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/clCreateBuffer.html:
CL_MEM_ALLOC_HOST_PTR and CL_MEM_USE_HOST_PTR are mutually exclusive.
PI_MEM_FLAGS_HOST_PTR_ALLOC is analogous to CL_MEM_ALLOC_HOST_PTR
I'm confused about what this PR is doing. Is it adding support for https://github.com/intel/llvm/tree/sycl/sycl/doc/extensions/UsePinnedMemoryProperty? If so I'm confused: I don't get why USM shared allocations are used here at all. |
@@ -390,6 +390,7 @@ struct _pi_mem : _pi_object { | |||
char *MapHostPtr; | |||
|
|||
// Flag to indicate that this memory is allocated in host memory | |||
// if created with PI_MEM_FLAGS_HOST_PTR_ALLOC and/or integrated devices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Let's not list all the cases when memory is allocated on host, since that might change in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
buffer<int, 1> a(data1, range<1>(10), {property::buffer::use_host_ptr()}); | ||
buffer<int, 1> b( | ||
range<1>(10), | ||
{ext::oneapi::property::buffer::use_pinned_host_memory()}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test which verifies that piMemBufferCreate with PI_MEM_FLAGS_HOST_PTR_ALLOC allocates memory using zeMemAllocHost?
|
||
ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, 1, &Ptr)); | ||
|
||
} else if (DeviceIsIntegrated) { | ||
ze_host_mem_alloc_desc_t ZeDesc = {}; | ||
ZeDesc.flags = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor. Probably, these two branches could be merged.
#include <cassert> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <cassert> | |
#include <cassert> |
Minor.
the use_pinned_host_memory.cpp test seems to be moved into intel/llvm-test-suite. |
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
Signed-off-by: rbegam <[email protected]>
That's OK. |
ping @smaslov-intel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It would be great to put a link to the test in the PR (or better yet into description of the commit).
@rbegam, do you have link to test? This change seems ready to merge. |
@pvchupin yes, I am updating the commit msg with it. |
When llvm-spirv is built in-tree as part of LLVM, and the LLVM build also includes libclc, libclc will require a native version of llvm-spirv to be built. To accommodate this, call setup_host_tool. This change by itself is intended to have no effect at the moment, but enables a future LLVM change. Original commit: KhronosGroup/SPIRV-LLVM-Translator@a276363ccac20bf
This change implements the support for pinned host memory in level_zero plugin. It allocates pinned host memory when PI_MEM_FLAGS_HOST_PTR_ALLOC is set. Pinned host memories are automatically accessible from the device through PCI. This property also ensures that the memory map/unmap operations are free of cost and the buffer is optimized for frequent accesses from the host.
A test is added for this change in a separate PR for the intel/llvm-test-suite: intel/llvm-test-suite#83
Signed-off-by: rbegam [email protected]