Skip to content

Commit 6e89821

Browse files
authored
[SYCL] Support USM buffer location property in malloc_shared (#6218)
This ports commit 12c988a from malloc_device to malloc_shared for use with the FPGA Runtime for OpenCL. See malloc_device implementation in #5634 See extension specification in #5665
1 parent 36a9ee2 commit 6e89821

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <CL/sycl/usm.hpp>
1515
#include <detail/queue_impl.hpp>
1616

17+
#include <array>
18+
#include <cassert>
1719
#include <cstdlib>
1820
#include <memory>
1921

@@ -150,16 +152,32 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
150152
}
151153
case alloc::shared: {
152154
Id = detail::getSyclObjImpl(Dev)->getHandleRef();
155+
156+
std::array<pi_usm_mem_properties, 5> Props;
157+
auto PropsIter = Props.begin();
158+
153159
if (PropList.has_property<
154160
cl::sycl::ext::oneapi::property::usm::device_read_only>()) {
155-
pi_usm_mem_properties Props[3] = {PI_MEM_ALLOC_FLAGS,
156-
PI_MEM_ALLOC_DEVICE_READ_ONLY, 0};
157-
Error = Plugin.call_nocheck<PiApiKind::piextUSMSharedAlloc>(
158-
&RetVal, C, Id, Props, Size, Alignment);
159-
} else {
160-
Error = Plugin.call_nocheck<PiApiKind::piextUSMSharedAlloc>(
161-
&RetVal, C, Id, nullptr, Size, Alignment);
161+
*PropsIter++ = PI_MEM_ALLOC_FLAGS;
162+
*PropsIter++ = PI_MEM_ALLOC_DEVICE_READ_ONLY;
162163
}
164+
165+
if (Dev.has_extension("cl_intel_mem_alloc_buffer_location") &&
166+
PropList.has_property<cl::sycl::ext::intel::experimental::property::
167+
usm::buffer_location>()) {
168+
*PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
169+
*PropsIter++ = PropList
170+
.get_property<cl::sycl::ext::intel::experimental::
171+
property::usm::buffer_location>()
172+
.get_buffer_location();
173+
}
174+
175+
assert(PropsIter >= Props.begin() && PropsIter < Props.end());
176+
*PropsIter++ = 0; // null-terminate property list
177+
178+
Error = Plugin.call_nocheck<PiApiKind::piextUSMSharedAlloc>(
179+
&RetVal, C, Id, Props.data(), Size, Alignment);
180+
163181
break;
164182
}
165183
case alloc::host:

sycl/test/extensions/usm/usm_alloc_utility.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ int main() {
6767
array = (int *)malloc_shared(N * sizeof(int), q);
6868
check_and_free(array, dev, ctxt);
6969

70-
array = (int *)malloc_shared(N * sizeof(int), q, property_list{});
70+
array = (int *)malloc_shared(
71+
N * sizeof(int), q,
72+
property_list{
73+
ext::intel::experimental::property::usm::buffer_location{2}});
7174
check_and_free(array, dev, ctxt);
7275

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

77-
array = (int *)aligned_alloc_shared(alignof(long long), N * sizeof(int),
78-
dev, ctxt, property_list{});
80+
array = (int *)aligned_alloc_shared(
81+
alignof(long long), N * sizeof(int), dev, ctxt,
82+
property_list{
83+
ext::intel::experimental::property::usm::buffer_location{2}});
7984
check_and_free(array, dev, ctxt);
8085
}
8186

0 commit comments

Comments
 (0)