Skip to content

Commit

Permalink
Merge pull request #2682 from Xewar313/add-append-usm-memory-v2-comma…
Browse files Browse the repository at this point in the history
…ndbuffer

Add USMMemcpy to v2 command buffer
  • Loading branch information
pbalcer authored Feb 11, 2025
2 parents 396f568 + 80379ca commit d033432
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
11 changes: 0 additions & 11 deletions source/adapters/level_zero/v2/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,6 @@ ur_result_t urBindlessImagesReleaseExternalSemaphoreExp(
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t urCommandBufferAppendUSMMemcpyExp(
ur_exp_command_buffer_handle_t hCommandBuffer, void *pDst, const void *pSrc,
size_t size, uint32_t numSyncPointsInWaitList,
const ur_exp_command_buffer_sync_point_t *pSyncPointWaitList,
uint32_t NumEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_exp_command_buffer_sync_point_t *pSyncPoint, ur_event_handle_t *phEvent,
ur_exp_command_buffer_command_handle_t *phCommand) {
logger::error("{} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t urCommandBufferAppendUSMFillExp(
ur_exp_command_buffer_handle_t hCommandBuffer, void *pMemory,
const void *pPattern, size_t patternSize, size_t size,
Expand Down
27 changes: 27 additions & 0 deletions source/adapters/level_zero/v2/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
return exceptionToResult(std::current_exception());
}

ur_result_t urCommandBufferAppendUSMMemcpyExp(
ur_exp_command_buffer_handle_t hCommandBuffer, void *pDst, const void *pSrc,
size_t size, uint32_t numSyncPointsInWaitList,
const ur_exp_command_buffer_sync_point_t *pSyncPointWaitList,
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_exp_command_buffer_sync_point_t *pSyncPoint, ur_event_handle_t *phEvent,
ur_exp_command_buffer_command_handle_t *phCommand) try {

// the same issue as in urCommandBufferAppendKernelLaunchExp
std::ignore = numEventsInWaitList;
std::ignore = phEventWaitList;
std::ignore = phEvent;
// sync mechanic can be ignored, because all lists are in-order
std::ignore = numSyncPointsInWaitList;
std::ignore = pSyncPointWaitList;
std::ignore = pSyncPoint;

std::ignore = phCommand;
// Responsibility of UMD to offload to copy engine
UR_CALL(hCommandBuffer->commandListManager.appendUSMMemcpy(
false, pDst, pSrc, size, 0, nullptr, nullptr));

return UR_RESULT_SUCCESS;
} catch (...) {
return exceptionToResult(std::current_exception());
}

ur_result_t
urCommandBufferGetInfoExp(ur_exp_command_buffer_handle_t hCommandBuffer,
ur_exp_command_buffer_info_t propName,
Expand Down
24 changes: 24 additions & 0 deletions source/adapters/level_zero/v2/command_list_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ ur_result_t ur_command_list_manager::appendKernelLaunch(
return UR_RESULT_SUCCESS;
}

ur_result_t ur_command_list_manager::appendUSMMemcpy(
bool blocking, void *pDst, const void *pSrc, size_t size,
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent) {
TRACK_SCOPE_LATENCY("ur_command_list_manager::appendUSMMemcpy");

std::scoped_lock<ur_shared_mutex> lock(this->Mutex);

auto zeSignalEvent = getSignalEvent(phEvent, UR_COMMAND_USM_MEMCPY);

auto [pWaitEvents, numWaitEvents] =
getWaitListView(phEventWaitList, numEventsInWaitList);

ZE2UR_CALL(zeCommandListAppendMemoryCopy,
(zeCommandList.get(), pDst, pSrc, size, zeSignalEvent,
numWaitEvents, pWaitEvents));

if (blocking) {
ZE2UR_CALL(zeCommandListHostSynchronize, (zeCommandList.get(), UINT64_MAX));
}

return UR_RESULT_SUCCESS;
}

ze_command_list_handle_t ur_command_list_manager::getZeCommandList() {
return zeCommandList.get();
}
5 changes: 5 additions & 0 deletions source/adapters/level_zero/v2/command_list_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ struct ur_command_list_manager : public _ur_object {
const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent);

ur_result_t appendUSMMemcpy(bool blocking, void *pDst, const void *pSrc,
size_t size, uint32_t numEventsInWaitList,
const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent);

ze_command_list_handle_t getZeCommandList();

wait_list_view getWaitListView(const ur_event_handle_t *phWaitEvents,
Expand Down
18 changes: 3 additions & 15 deletions source/adapters/level_zero/v2/queue_immediate_in_order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,21 +698,9 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueUSMMemcpy(
// TODO: parametrize latency tracking with 'blocking'
TRACK_SCOPE_LATENCY("ur_queue_immediate_in_order_t::enqueueUSMMemcpy");

std::scoped_lock<ur_shared_mutex> lock(this->Mutex);

auto zeSignalEvent = getSignalEvent(phEvent, UR_COMMAND_USM_MEMCPY);

auto [pWaitEvents, numWaitEvents] =
getWaitListView(phEventWaitList, numEventsInWaitList);

ZE2UR_CALL(zeCommandListAppendMemoryCopy,
(commandListManager.getZeCommandList(), pDst, pSrc, size,
zeSignalEvent, numWaitEvents, pWaitEvents));

if (blocking) {
ZE2UR_CALL(zeCommandListHostSynchronize,
(commandListManager.getZeCommandList(), UINT64_MAX));
}
UR_CALL(commandListManager.appendUSMMemcpy(blocking, pDst, pSrc, size,
numEventsInWaitList,
phEventWaitList, phEvent));

return UR_RESULT_SUCCESS;
}
Expand Down

0 comments on commit d033432

Please sign in to comment.