Skip to content

[SYCL] Align USM buffer location implementation for malloc_device with malloc_shared #6269

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 2 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 @@ -7214,7 +7214,7 @@ static pi_result USMDeviceAllocImpl(void **ResultPtr, pi_context Context,
PI_ASSERT(Device, PI_INVALID_DEVICE);

// 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
36 changes: 19 additions & 17 deletions sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,27 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
switch (Kind) {
case alloc::device: {
Id = detail::getSyclObjImpl(Dev)->getHandleRef();
// Parse out buffer location property

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

// Buffer location is only supported on FPGA devices
bool IsBufferLocSupported =
Dev.has_extension("cl_intel_mem_alloc_buffer_location");
if (IsBufferLocSupported &&
PropList.has_property<cl::sycl::ext::intel::experimental::property::
usm::buffer_location>()) {
auto location = PropList
.get_property<cl::sycl::ext::intel::experimental::
property::usm::buffer_location>()
.get_buffer_location();
pi_usm_mem_properties props[3] = {PI_MEM_USM_ALLOC_BUFFER_LOCATION,
location, 0};
Error = Plugin.call_nocheck<PiApiKind::piextUSMDeviceAlloc>(
&RetVal, C, Id, props, Size, Alignment);
} else {
Error = Plugin.call_nocheck<PiApiKind::piextUSMDeviceAlloc>(
&RetVal, C, Id, nullptr, Size, Alignment);
if (PropList.has_property<cl::sycl::ext::intel::experimental::property::
usm::buffer_location>() &&
Dev.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::piextUSMDeviceAlloc>(
&RetVal, C, Id, Props.data(), Size, Alignment);

break;
}
case alloc::shared: {
Expand Down