Skip to content

[SYCL] Support USM buffer location property in malloc_host #6220

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 3 commits into from
Jun 8, 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
2 changes: 1 addition & 1 deletion sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7278,7 +7278,7 @@ static pi_result USMHostAllocImpl(void **ResultPtr, pi_context Context,
PI_ASSERT(Context, PI_INVALID_CONTEXT);

// Check that incorrect bits are not set in the properties.
PI_ASSERT(!Properties ||
PI_ASSERT(!Properties || *Properties == 0 ||
(*Properties == PI_MEM_ALLOC_FLAGS && *(Properties + 2) == 0),
PI_INVALID_VALUE);

Expand Down
34 changes: 28 additions & 6 deletions sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace detail {
namespace usm {

void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
alloc Kind, const detail::code_location &CL) {
alloc Kind, const detail::code_location &CL,
const property_list &PropList = {}) {
XPTI_CREATE_TRACEPOINT(CL);
void *RetVal = nullptr;
if (Size == 0)
Expand All @@ -72,8 +73,26 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,

switch (Kind) {
case alloc::host: {
std::array<pi_usm_mem_properties, 3> Props;
auto PropsIter = Props.begin();

if (PropList.has_property<cl::sycl::ext::intel::experimental::property::
usm::buffer_location>() &&
Ctxt.get_platform().has_extension(
"cl_intel_mem_alloc_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::piextUSMHostAlloc>(
&RetVal, C, nullptr, Size, Alignment);
&RetVal, C, Props.data(), Size, Alignment);

break;
}
case alloc::device:
Expand Down Expand Up @@ -296,9 +315,11 @@ void *malloc_host(size_t Size, const context &Ctxt,
return detail::usm::alignedAllocHost(0, Size, Ctxt, alloc::host, CL);
}

void *malloc_host(size_t Size, const context &Ctxt, const property_list &,
void *malloc_host(size_t Size, const context &Ctxt,
const property_list &PropList,
const detail::code_location CL) {
return malloc_host(Size, Ctxt, CL);
return detail::usm::alignedAllocHost(0, Size, Ctxt, alloc::host, CL,
PropList);
}

void *malloc_host(size_t Size, const queue &Q, const detail::code_location CL) {
Expand Down Expand Up @@ -338,9 +359,10 @@ void *aligned_alloc_host(size_t Alignment, size_t Size, const context &Ctxt,
}

void *aligned_alloc_host(size_t Alignment, size_t Size, const context &Ctxt,
const property_list &,
const property_list &PropList,
const detail::code_location CL) {
return aligned_alloc_host(Alignment, Size, Ctxt, CL);
return detail::usm::alignedAllocHost(Alignment, Size, Ctxt, alloc::host, CL,
PropList);
}

void *aligned_alloc_host(size_t Alignment, size_t Size, const queue &Q,
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 @@ -51,15 +51,20 @@ int main() {
array = (int *)malloc_host(N * sizeof(int), q);
check_and_free(array, dev, ctxt);

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

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

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

Expand Down