Skip to content

Commit

Permalink
[UR] Pass pi_mem_properties in pi2ur for piMemBufferCreate (#12665)
Browse files Browse the repository at this point in the history
- Remove the restriction in pi2ur such that piMemBufferCreate can pass
the pi_mem_properties as the pNext properties to the UR Adapters.

Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
  • Loading branch information
nrspruit authored Feb 9, 2024
1 parent 73d3473 commit 34ec82d
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions sycl/plugins/unified_runtime/pi2ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2670,10 +2670,6 @@ inline pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags,
PI_ASSERT(Context, PI_ERROR_INVALID_CONTEXT);
PI_ASSERT(RetMem, PI_ERROR_INVALID_VALUE);

if (properties != nullptr) {
die("piMemBufferCreate: no mem properties goes to Level-Zero RT yet");
}

ur_context_handle_t UrContext =
reinterpret_cast<ur_context_handle_t>(Context);

Expand All @@ -2697,6 +2693,44 @@ inline pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags,
ur_buffer_properties_t UrProps{};
UrProps.stype = UR_STRUCTURE_TYPE_BUFFER_PROPERTIES;
UrProps.pHost = HostPtr;

ur_buffer_channel_properties_t bufferChannelProperties{};
bufferChannelProperties.stype = UR_STRUCTURE_TYPE_BUFFER_CHANNEL_PROPERTIES;
ur_buffer_alloc_location_properties_t bufferLocationProperties{};
bufferLocationProperties.stype =
UR_STRUCTURE_TYPE_BUFFER_ALLOC_LOCATION_PROPERTIES;
if (properties != nullptr) {
bool bufferLocationPropertySet = false;
bool bufferMemChannelPropertySet = false;
uint64_t allocBufferLocation = 0;
uint32_t allocBufferMemChannel = 0;
// pi mem properties must ended by 0
size_t I = 0;
while (properties[I] != 0) {
if (properties[I] == PI_MEM_PROPERTIES_ALLOC_BUFFER_LOCATION) {
allocBufferLocation = properties[I + 1];
bufferLocationPropertySet = true;
} else if (properties[I] == PI_MEM_PROPERTIES_CHANNEL) {
allocBufferMemChannel = properties[I + 1];
bufferMemChannelPropertySet = true;
}
I += 2;
}
void *extensionProperties = nullptr;
if (bufferLocationPropertySet) {
bufferLocationProperties.location = allocBufferLocation;
extensionProperties = &bufferLocationProperties;
}
if (bufferMemChannelPropertySet) {
bufferChannelProperties.channel = allocBufferMemChannel;
extensionProperties = &bufferChannelProperties;
}
if (bufferLocationPropertySet && bufferMemChannelPropertySet) {
bufferLocationProperties.pNext = &bufferChannelProperties;
extensionProperties = &bufferLocationProperties;
}
UrProps.pNext = extensionProperties;
}
ur_mem_handle_t *UrBuffer = reinterpret_cast<ur_mem_handle_t *>(RetMem);
HANDLE_ERRORS(
urMemBufferCreate(UrContext, UrBufferFlags, Size, &UrProps, UrBuffer));
Expand Down

0 comments on commit 34ec82d

Please sign in to comment.