Skip to content

Commit 34ec82d

Browse files
authored
[UR] Pass pi_mem_properties in pi2ur for piMemBufferCreate (#12665)
- 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 <[email protected]>
1 parent 73d3473 commit 34ec82d

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

sycl/plugins/unified_runtime/pi2ur.hpp

+38-4
Original file line numberDiff line numberDiff line change
@@ -2670,10 +2670,6 @@ inline pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags,
26702670
PI_ASSERT(Context, PI_ERROR_INVALID_CONTEXT);
26712671
PI_ASSERT(RetMem, PI_ERROR_INVALID_VALUE);
26722672

2673-
if (properties != nullptr) {
2674-
die("piMemBufferCreate: no mem properties goes to Level-Zero RT yet");
2675-
}
2676-
26772673
ur_context_handle_t UrContext =
26782674
reinterpret_cast<ur_context_handle_t>(Context);
26792675

@@ -2697,6 +2693,44 @@ inline pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags,
26972693
ur_buffer_properties_t UrProps{};
26982694
UrProps.stype = UR_STRUCTURE_TYPE_BUFFER_PROPERTIES;
26992695
UrProps.pHost = HostPtr;
2696+
2697+
ur_buffer_channel_properties_t bufferChannelProperties{};
2698+
bufferChannelProperties.stype = UR_STRUCTURE_TYPE_BUFFER_CHANNEL_PROPERTIES;
2699+
ur_buffer_alloc_location_properties_t bufferLocationProperties{};
2700+
bufferLocationProperties.stype =
2701+
UR_STRUCTURE_TYPE_BUFFER_ALLOC_LOCATION_PROPERTIES;
2702+
if (properties != nullptr) {
2703+
bool bufferLocationPropertySet = false;
2704+
bool bufferMemChannelPropertySet = false;
2705+
uint64_t allocBufferLocation = 0;
2706+
uint32_t allocBufferMemChannel = 0;
2707+
// pi mem properties must ended by 0
2708+
size_t I = 0;
2709+
while (properties[I] != 0) {
2710+
if (properties[I] == PI_MEM_PROPERTIES_ALLOC_BUFFER_LOCATION) {
2711+
allocBufferLocation = properties[I + 1];
2712+
bufferLocationPropertySet = true;
2713+
} else if (properties[I] == PI_MEM_PROPERTIES_CHANNEL) {
2714+
allocBufferMemChannel = properties[I + 1];
2715+
bufferMemChannelPropertySet = true;
2716+
}
2717+
I += 2;
2718+
}
2719+
void *extensionProperties = nullptr;
2720+
if (bufferLocationPropertySet) {
2721+
bufferLocationProperties.location = allocBufferLocation;
2722+
extensionProperties = &bufferLocationProperties;
2723+
}
2724+
if (bufferMemChannelPropertySet) {
2725+
bufferChannelProperties.channel = allocBufferMemChannel;
2726+
extensionProperties = &bufferChannelProperties;
2727+
}
2728+
if (bufferLocationPropertySet && bufferMemChannelPropertySet) {
2729+
bufferLocationProperties.pNext = &bufferChannelProperties;
2730+
extensionProperties = &bufferLocationProperties;
2731+
}
2732+
UrProps.pNext = extensionProperties;
2733+
}
27002734
ur_mem_handle_t *UrBuffer = reinterpret_cast<ur_mem_handle_t *>(RetMem);
27012735
HANDLE_ERRORS(
27022736
urMemBufferCreate(UrContext, UrBufferFlags, Size, &UrProps, UrBuffer));

0 commit comments

Comments
 (0)