Skip to content

[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

Merged
merged 16 commits into from
Jan 5, 2021
Merged

Conversation

rbegam
Copy link
Contributor

@rbegam rbegam commented Oct 14, 2020

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]

@rbegam rbegam requested a review from smaslov-intel as a code owner October 14, 2020 02:53
Copy link
Contributor

@smaslov-intel smaslov-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

Copy link
Contributor

@smaslov-intel smaslov-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test

Copy link
Contributor

@smaslov-intel smaslov-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@rbegam rbegam force-pushed the pinned-host branch 2 times, most recently from c621923 to bb4bd5e Compare October 26, 2020 18:02
@smaslov-intel
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

@rbegam rbegam Nov 16, 2020

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.

Copy link
Contributor

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

@jbrodman
Copy link
Contributor

jbrodman commented Nov 16, 2020

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.
It seems like a buffer should be represented as 2 allocations: 1 in host memory, 1 in device memory.
The property says that the host memory one should likely be done as a USM host allocation instead of system malloc as that usually means it's pinned.

@rbegam rbegam requested a review from a team as a code owner December 23, 2020 23:42
@@ -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.
Copy link
Contributor

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.

smaslov-intel
smaslov-intel previously approved these changes Dec 24, 2020
Copy link
Contributor

@smaslov-intel smaslov-intel left a 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()});
Copy link
Contributor

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?

Comment on lines 2105 to 2107

ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, 1, &Ptr));

} else if (DeviceIsIntegrated) {
ze_host_mem_alloc_desc_t ZeDesc = {};
ZeDesc.flags = 0;

Copy link
Contributor

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.

Comment on lines 12 to 13
#include <cassert>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <cassert>
#include <cassert>

Minor.

@rbegam
Copy link
Contributor Author

rbegam commented Dec 24, 2020

the use_pinned_host_memory.cpp test seems to be moved into intel/llvm-test-suite.
@romanovvlad I am going to remove the test from this PR and submit a new one for intel/llvm-test-suite. is that okay?

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]>
@romanovvlad
Copy link
Contributor

the use_pinned_host_memory.cpp test seems to be moved into intel/llvm-test-suite.
@romanovvlad I am going to remove the test from this PR and submit a new one for intel/llvm-test-suite. is that okay?

That's OK.

@rbegam
Copy link
Contributor Author

rbegam commented Dec 28, 2020

ping @smaslov-intel

Copy link
Contributor

@smaslov-intel smaslov-intel left a 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).

@pvchupin
Copy link
Contributor

pvchupin commented Jan 5, 2021

@rbegam, do you have link to test? This change seems ready to merge.

@rbegam
Copy link
Contributor Author

rbegam commented Jan 5, 2021

@pvchupin yes, I am updating the commit msg with it.

@pvchupin pvchupin merged commit 0b9a749 into intel:sycl Jan 5, 2021
iclsrc pushed a commit that referenced this pull request Jul 26, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants