Skip to content

Commit 2c7caab

Browse files
authored
[SYCL] Support USM buffer location property in malloc_host (#6220)
See malloc_shared implementation in #6218 See extension specification in #5665
1 parent 9f61c8e commit 2c7caab

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7271,7 +7271,7 @@ static pi_result USMHostAllocImpl(void **ResultPtr, pi_context Context,
72717271
PI_ASSERT(Context, PI_INVALID_CONTEXT);
72727272

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

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ namespace detail {
4646
namespace usm {
4747

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

7374
switch (Kind) {
7475
case alloc::host: {
76+
std::array<pi_usm_mem_properties, 3> Props;
77+
auto PropsIter = Props.begin();
78+
79+
if (PropList.has_property<cl::sycl::ext::intel::experimental::property::
80+
usm::buffer_location>() &&
81+
Ctxt.get_platform().has_extension(
82+
"cl_intel_mem_alloc_buffer_location")) {
83+
*PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
84+
*PropsIter++ = PropList
85+
.get_property<cl::sycl::ext::intel::experimental::
86+
property::usm::buffer_location>()
87+
.get_buffer_location();
88+
}
89+
90+
assert(PropsIter >= Props.begin() && PropsIter < Props.end());
91+
*PropsIter++ = 0; // null-terminate property list
92+
7593
Error = Plugin.call_nocheck<PiApiKind::piextUSMHostAlloc>(
76-
&RetVal, C, nullptr, Size, Alignment);
94+
&RetVal, C, Props.data(), Size, Alignment);
95+
7796
break;
7897
}
7998
case alloc::device:
@@ -298,9 +317,11 @@ void *malloc_host(size_t Size, const context &Ctxt,
298317
return detail::usm::alignedAllocHost(0, Size, Ctxt, alloc::host, CL);
299318
}
300319

301-
void *malloc_host(size_t Size, const context &Ctxt, const property_list &,
320+
void *malloc_host(size_t Size, const context &Ctxt,
321+
const property_list &PropList,
302322
const detail::code_location CL) {
303-
return malloc_host(Size, Ctxt, CL);
323+
return detail::usm::alignedAllocHost(0, Size, Ctxt, alloc::host, CL,
324+
PropList);
304325
}
305326

306327
void *malloc_host(size_t Size, const queue &Q, const detail::code_location CL) {
@@ -340,9 +361,10 @@ void *aligned_alloc_host(size_t Alignment, size_t Size, const context &Ctxt,
340361
}
341362

342363
void *aligned_alloc_host(size_t Alignment, size_t Size, const context &Ctxt,
343-
const property_list &,
364+
const property_list &PropList,
344365
const detail::code_location CL) {
345-
return aligned_alloc_host(Alignment, Size, Ctxt, CL);
366+
return detail::usm::alignedAllocHost(Alignment, Size, Ctxt, alloc::host, CL,
367+
PropList);
346368
}
347369

348370
void *aligned_alloc_host(size_t Alignment, size_t Size, const queue &Q,

sycl/test/extensions/usm/usm_alloc_utility.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ int main() {
5151
array = (int *)malloc_host(N * sizeof(int), q);
5252
check_and_free(array, dev, ctxt);
5353

54-
array = (int *)malloc_host(N * sizeof(int), q, property_list{});
54+
array = (int *)malloc_host(
55+
N * sizeof(int), q,
56+
property_list{
57+
ext::intel::experimental::property::usm::buffer_location{2}});
5558
check_and_free(array, dev, ctxt);
5659

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

61-
array = (int *)aligned_alloc_host(alignof(long long), N * sizeof(int), ctxt,
62-
property_list{});
64+
array = (int *)aligned_alloc_host(
65+
alignof(long long), N * sizeof(int), ctxt,
66+
property_list{
67+
ext::intel::experimental::property::usm::buffer_location{2}});
6368
check_and_free(array, dev, ctxt);
6469
}
6570

0 commit comments

Comments
 (0)