Skip to content

Commit 12f57b5

Browse files
igchorkbenzie
authored andcommitted
Fix urMemBufferCreateWithNativeHandle for host memory (#18066)
In case of creating a buffer from native host memory pointer, there was a missing initialization step. Host memory content was not being copied to the underlying buffer device memory.
1 parent 6e4a614 commit 12f57b5

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

source/adapters/level_zero/v2/memory.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,19 @@ ur_discrete_buffer_handle_t::ur_discrete_buffer_handle_t(
205205

206206
ur_discrete_buffer_handle_t::ur_discrete_buffer_handle_t(
207207
ur_context_handle_t hContext, ur_device_handle_t hDevice, void *devicePtr,
208-
size_t size, device_access_mode_t accessMode, void *writeBackMemory,
209-
bool ownZePtr)
208+
size_t size, device_access_mode_t accessMode, void *hostPtr, bool ownZePtr)
210209
: ur_mem_buffer_t(hContext, size, accessMode),
211210
deviceAllocations(hContext->getPlatform()->getNumDevices()),
212-
activeAllocationDevice(hDevice), writeBackPtr(writeBackMemory),
211+
activeAllocationDevice(hDevice), writeBackPtr(hostPtr),
213212
hostAllocations() {
214213

215214
if (!devicePtr) {
216215
hDevice = hDevice ? hDevice : hContext->getDevices()[0];
217216
devicePtr = allocateOnDevice(hDevice, size);
217+
218+
if (hostPtr) {
219+
UR_CALL_THROWS(migrateBufferTo(hDevice, hostPtr, size));
220+
}
218221
} else {
219222
assert(hDevice);
220223
deviceAllocations[hDevice->Id.value()] = usm_unique_ptr_t(

0 commit comments

Comments
 (0)