Skip to content

[SYCL] Support USM buffer location property in malloc_shared #6218

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 1 commit into from
Jun 7, 2022
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
32 changes: 25 additions & 7 deletions sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <CL/sycl/usm.hpp>
#include <detail/queue_impl.hpp>

#include <array>
#include <cassert>
#include <cstdlib>
#include <memory>

Expand Down Expand Up @@ -150,16 +152,32 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
}
case alloc::shared: {
Id = detail::getSyclObjImpl(Dev)->getHandleRef();

std::array<pi_usm_mem_properties, 5> Props;
auto PropsIter = Props.begin();

if (PropList.has_property<
cl::sycl::ext::oneapi::property::usm::device_read_only>()) {
pi_usm_mem_properties Props[3] = {PI_MEM_ALLOC_FLAGS,
PI_MEM_ALLOC_DEVICE_READ_ONLY, 0};
Error = Plugin.call_nocheck<PiApiKind::piextUSMSharedAlloc>(
&RetVal, C, Id, Props, Size, Alignment);
} else {
Error = Plugin.call_nocheck<PiApiKind::piextUSMSharedAlloc>(
&RetVal, C, Id, nullptr, Size, Alignment);
*PropsIter++ = PI_MEM_ALLOC_FLAGS;
*PropsIter++ = PI_MEM_ALLOC_DEVICE_READ_ONLY;
}

if (Dev.has_extension("cl_intel_mem_alloc_buffer_location") &&
PropList.has_property<cl::sycl::ext::intel::experimental::property::
usm::buffer_location>()) {
*PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
*PropsIter++ = PropList
.get_property<cl::sycl::ext::intel::experimental::
property::usm::buffer_location>()
.get_buffer_location();
}

assert(PropsIter >= Props.begin() && PropsIter < Props.end());
*PropsIter++ = 0; // null-terminate property list

Error = Plugin.call_nocheck<PiApiKind::piextUSMSharedAlloc>(
&RetVal, C, Id, Props.data(), Size, Alignment);

break;
}
case alloc::host:
Expand Down
11 changes: 8 additions & 3 deletions sycl/test/extensions/usm/usm_alloc_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ int main() {
array = (int *)malloc_shared(N * sizeof(int), q);
check_and_free(array, dev, ctxt);

array = (int *)malloc_shared(N * sizeof(int), q, property_list{});
array = (int *)malloc_shared(
N * sizeof(int), q,
property_list{
ext::intel::experimental::property::usm::buffer_location{2}});
check_and_free(array, dev, ctxt);

array = (int *)aligned_alloc_shared(alignof(long long), N * sizeof(int),
dev, ctxt);
check_and_free(array, dev, ctxt);

array = (int *)aligned_alloc_shared(alignof(long long), N * sizeof(int),
dev, ctxt, property_list{});
array = (int *)aligned_alloc_shared(
alignof(long long), N * sizeof(int), dev, ctxt,
property_list{
ext::intel::experimental::property::usm::buffer_location{2}});
check_and_free(array, dev, ctxt);
}

Expand Down