Skip to content

Commit 9f61c8e

Browse files
authored
[SYCL] Align USM buffer location implementation for malloc_device with malloc_shared (#6269)
Use the same call to USMDeviceAlloc with an empty property list in all cases, to allow for straight-forward extension with future properties. Query buffer location extension only if buffer location property is passed. This amends #5634 See also #6220
1 parent c76ef5c commit 9f61c8e

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7207,7 +7207,7 @@ static pi_result USMDeviceAllocImpl(void **ResultPtr, pi_context Context,
72077207
PI_ASSERT(Device, PI_INVALID_DEVICE);
72087208

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

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,27 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
129129
switch (Kind) {
130130
case alloc::device: {
131131
Id = detail::getSyclObjImpl(Dev)->getHandleRef();
132-
// Parse out buffer location property
132+
133+
std::array<pi_usm_mem_properties, 3> Props;
134+
auto PropsIter = Props.begin();
135+
133136
// Buffer location is only supported on FPGA devices
134-
bool IsBufferLocSupported =
135-
Dev.has_extension("cl_intel_mem_alloc_buffer_location");
136-
if (IsBufferLocSupported &&
137-
PropList.has_property<cl::sycl::ext::intel::experimental::property::
138-
usm::buffer_location>()) {
139-
auto location = PropList
140-
.get_property<cl::sycl::ext::intel::experimental::
141-
property::usm::buffer_location>()
142-
.get_buffer_location();
143-
pi_usm_mem_properties props[3] = {PI_MEM_USM_ALLOC_BUFFER_LOCATION,
144-
location, 0};
145-
Error = Plugin.call_nocheck<PiApiKind::piextUSMDeviceAlloc>(
146-
&RetVal, C, Id, props, Size, Alignment);
147-
} else {
148-
Error = Plugin.call_nocheck<PiApiKind::piextUSMDeviceAlloc>(
149-
&RetVal, C, Id, nullptr, Size, Alignment);
137+
if (PropList.has_property<cl::sycl::ext::intel::experimental::property::
138+
usm::buffer_location>() &&
139+
Dev.has_extension("cl_intel_mem_alloc_buffer_location")) {
140+
*PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
141+
*PropsIter++ = PropList
142+
.get_property<cl::sycl::ext::intel::experimental::
143+
property::usm::buffer_location>()
144+
.get_buffer_location();
150145
}
146+
147+
assert(PropsIter >= Props.begin() && PropsIter < Props.end());
148+
*PropsIter++ = 0; // null-terminate property list
149+
150+
Error = Plugin.call_nocheck<PiApiKind::piextUSMDeviceAlloc>(
151+
&RetVal, C, Id, Props.data(), Size, Alignment);
152+
151153
break;
152154
}
153155
case alloc::shared: {

0 commit comments

Comments
 (0)