Skip to content

Commit aa04ce1

Browse files
committed
Add Native Command support to command-buffer
Enables support for using native commands inside a command-buffer.
1 parent 87d4a32 commit aa04ce1

32 files changed

+1130
-1
lines changed

include/ur_api.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ typedef enum ur_function_t {
429429
UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT = 246,
430430
/// Enumerator for ::urPhysicalMemGetInfo
431431
UR_FUNCTION_PHYSICAL_MEM_GET_INFO = 249,
432+
/// Enumerator for ::urCommandBufferAppendNativeCommandExp
433+
UR_FUNCTION_COMMAND_BUFFER_APPEND_NATIVE_COMMAND_EXP = 250,
434+
/// Enumerator for ::urCommandBufferGetNativeHandleExp
435+
UR_FUNCTION_COMMAND_BUFFER_GET_NATIVE_HANDLE_EXP = 252,
432436
/// @cond
433437
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
434438
/// @endcond
@@ -10992,6 +10996,51 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMAdviseExp(
1099210996
/// [out][optional] Handle to this command.
1099310997
ur_exp_command_buffer_command_handle_t *phCommand);
1099410998

10999+
///////////////////////////////////////////////////////////////////////////////
11000+
/// @brief Function adding work through the native API to be executed
11001+
/// immediately.
11002+
typedef void (*ur_exp_command_buffer_native_command_function_t)(
11003+
/// [in][out] pointer to data to be passed to callback
11004+
void *pUserData);
11005+
11006+
///////////////////////////////////////////////////////////////////////////////
11007+
/// @brief Append nodes through a native backend API
11008+
///
11009+
/// @returns
11010+
/// - ::UR_RESULT_SUCCESS
11011+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
11012+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
11013+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
11014+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
11015+
/// + `NULL == hCommandBuffer`
11016+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
11017+
/// + `NULL == pfnNativeCommand`
11018+
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP
11019+
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP
11020+
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP
11021+
/// + `pSyncPointWaitList == NULL && numSyncPointsInWaitList > 0`
11022+
/// + `pSyncPointWaitList != NULL && numSyncPointsInWaitList == 0`
11023+
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
11024+
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
11025+
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
11026+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendNativeCommandExp(
11027+
/// [in] handle of the command-buffer object.
11028+
ur_exp_command_buffer_handle_t hCommandBuffer,
11029+
/// [in] function calling the native underlying API, to be executed
11030+
/// immediately.
11031+
ur_exp_command_buffer_native_command_function_t pfnNativeCommand,
11032+
/// [in][optional] data used by pfnNativeCommand
11033+
void *pData,
11034+
/// [in][optional] TODO
11035+
ur_exp_command_buffer_handle_t hChildCommandBuffer,
11036+
/// [in] The number of sync points in the provided dependency list.
11037+
uint32_t numSyncPointsInWaitList,
11038+
/// [in][optional] A list of sync points that this command depends on. May
11039+
/// be ignored if command-buffer is in-order.
11040+
const ur_exp_command_buffer_sync_point_t *pSyncPointWaitList,
11041+
/// [out][optional] sync point associated with this command.
11042+
ur_exp_command_buffer_sync_point_t *pSyncPoint);
11043+
1099511044
///////////////////////////////////////////////////////////////////////////////
1099611045
/// @brief Submit a command-buffer for execution on a queue.
1099711046
///
@@ -11218,6 +11267,30 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferGetInfoExp(
1121811267
/// [out][optional] bytes returned in command-buffer property
1121911268
size_t *pPropSizeRet);
1122011269

11270+
///////////////////////////////////////////////////////////////////////////////
11271+
/// @brief Return platform native command-buffer handle.
11272+
///
11273+
/// @details
11274+
/// - Retrieved native handle can be used for direct interaction with the
11275+
/// native platform driver.
11276+
///
11277+
/// @returns
11278+
/// - ::UR_RESULT_SUCCESS
11279+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
11280+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
11281+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
11282+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
11283+
/// + `NULL == hCommandBuffer`
11284+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
11285+
/// + `NULL == phNativeCommandBuffer`
11286+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
11287+
/// + If the adapter has no underlying equivalent handle.
11288+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferGetNativeHandleExp(
11289+
/// [in] handle of the command-buffer.
11290+
ur_exp_command_buffer_handle_t hCommandBuffer,
11291+
/// [out] a pointer to the native handle of the command-buffer.
11292+
ur_native_handle_t *phNativeCommandBuffer);
11293+
1122111294
#if !defined(__GNUC__)
1122211295
#pragma endregion
1122311296
#endif
@@ -14174,6 +14247,20 @@ typedef struct ur_command_buffer_append_usm_advise_exp_params_t {
1417414247
ur_exp_command_buffer_command_handle_t **pphCommand;
1417514248
} ur_command_buffer_append_usm_advise_exp_params_t;
1417614249

14250+
///////////////////////////////////////////////////////////////////////////////
14251+
/// @brief Function parameters for urCommandBufferAppendNativeCommandExp
14252+
/// @details Each entry is a pointer to the parameter passed to the function;
14253+
/// allowing the callback the ability to modify the parameter's value
14254+
typedef struct ur_command_buffer_append_native_command_exp_params_t {
14255+
ur_exp_command_buffer_handle_t *phCommandBuffer;
14256+
ur_exp_command_buffer_native_command_function_t *ppfnNativeCommand;
14257+
void **ppData;
14258+
ur_exp_command_buffer_handle_t *phChildCommandBuffer;
14259+
uint32_t *pnumSyncPointsInWaitList;
14260+
const ur_exp_command_buffer_sync_point_t **ppSyncPointWaitList;
14261+
ur_exp_command_buffer_sync_point_t **ppSyncPoint;
14262+
} ur_command_buffer_append_native_command_exp_params_t;
14263+
1417714264
///////////////////////////////////////////////////////////////////////////////
1417814265
/// @brief Function parameters for urCommandBufferEnqueueExp
1417914266
/// @details Each entry is a pointer to the parameter passed to the function;
@@ -14227,6 +14314,15 @@ typedef struct ur_command_buffer_get_info_exp_params_t {
1422714314
size_t **ppPropSizeRet;
1422814315
} ur_command_buffer_get_info_exp_params_t;
1422914316

14317+
///////////////////////////////////////////////////////////////////////////////
14318+
/// @brief Function parameters for urCommandBufferGetNativeHandleExp
14319+
/// @details Each entry is a pointer to the parameter passed to the function;
14320+
/// allowing the callback the ability to modify the parameter's value
14321+
typedef struct ur_command_buffer_get_native_handle_exp_params_t {
14322+
ur_exp_command_buffer_handle_t *phCommandBuffer;
14323+
ur_native_handle_t **pphNativeCommandBuffer;
14324+
} ur_command_buffer_get_native_handle_exp_params_t;
14325+
1423014326
///////////////////////////////////////////////////////////////////////////////
1423114327
/// @brief Function parameters for urUsmP2PEnablePeerAccessExp
1423214328
/// @details Each entry is a pointer to the parameter passed to the function;

include/ur_api_funcs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ _UR_API(urCommandBufferAppendMemBufferReadRectExp)
181181
_UR_API(urCommandBufferAppendMemBufferFillExp)
182182
_UR_API(urCommandBufferAppendUSMPrefetchExp)
183183
_UR_API(urCommandBufferAppendUSMAdviseExp)
184+
_UR_API(urCommandBufferAppendNativeCommandExp)
184185
_UR_API(urCommandBufferEnqueueExp)
185186
_UR_API(urCommandBufferUpdateKernelLaunchExp)
186187
_UR_API(urCommandBufferUpdateSignalEventExp)
187188
_UR_API(urCommandBufferUpdateWaitEventsExp)
188189
_UR_API(urCommandBufferGetInfoExp)
190+
_UR_API(urCommandBufferGetNativeHandleExp)
189191
_UR_API(urUsmP2PEnablePeerAccessExp)
190192
_UR_API(urUsmP2PDisablePeerAccessExp)
191193
_UR_API(urUsmP2PPeerAccessGetInfoExp)

include/ur_ddi.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,15 @@ typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferAppendUSMAdviseExp_t)(
15901590
const ur_event_handle_t *, ur_exp_command_buffer_sync_point_t *,
15911591
ur_event_handle_t *, ur_exp_command_buffer_command_handle_t *);
15921592

1593+
///////////////////////////////////////////////////////////////////////////////
1594+
/// @brief Function-pointer for urCommandBufferAppendNativeCommandExp
1595+
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferAppendNativeCommandExp_t)(
1596+
ur_exp_command_buffer_handle_t,
1597+
ur_exp_command_buffer_native_command_function_t, void *,
1598+
ur_exp_command_buffer_handle_t, uint32_t,
1599+
const ur_exp_command_buffer_sync_point_t *,
1600+
ur_exp_command_buffer_sync_point_t *);
1601+
15931602
///////////////////////////////////////////////////////////////////////////////
15941603
/// @brief Function-pointer for urCommandBufferEnqueueExp
15951604
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferEnqueueExp_t)(
@@ -1619,6 +1628,11 @@ typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferGetInfoExp_t)(
16191628
ur_exp_command_buffer_handle_t, ur_exp_command_buffer_info_t, size_t,
16201629
void *, size_t *);
16211630

1631+
///////////////////////////////////////////////////////////////////////////////
1632+
/// @brief Function-pointer for urCommandBufferGetNativeHandleExp
1633+
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferGetNativeHandleExp_t)(
1634+
ur_exp_command_buffer_handle_t, ur_native_handle_t *);
1635+
16221636
///////////////////////////////////////////////////////////////////////////////
16231637
/// @brief Table of CommandBufferExp functions pointers
16241638
typedef struct ur_command_buffer_exp_dditable_t {
@@ -1639,11 +1653,13 @@ typedef struct ur_command_buffer_exp_dditable_t {
16391653
ur_pfnCommandBufferAppendMemBufferFillExp_t pfnAppendMemBufferFillExp;
16401654
ur_pfnCommandBufferAppendUSMPrefetchExp_t pfnAppendUSMPrefetchExp;
16411655
ur_pfnCommandBufferAppendUSMAdviseExp_t pfnAppendUSMAdviseExp;
1656+
ur_pfnCommandBufferAppendNativeCommandExp_t pfnAppendNativeCommandExp;
16421657
ur_pfnCommandBufferEnqueueExp_t pfnEnqueueExp;
16431658
ur_pfnCommandBufferUpdateKernelLaunchExp_t pfnUpdateKernelLaunchExp;
16441659
ur_pfnCommandBufferUpdateSignalEventExp_t pfnUpdateSignalEventExp;
16451660
ur_pfnCommandBufferUpdateWaitEventsExp_t pfnUpdateWaitEventsExp;
16461661
ur_pfnCommandBufferGetInfoExp_t pfnGetInfoExp;
1662+
ur_pfnCommandBufferGetNativeHandleExp_t pfnGetNativeHandleExp;
16471663
} ur_command_buffer_exp_dditable_t;
16481664

16491665
///////////////////////////////////////////////////////////////////////////////

include/ur_print.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,17 @@ urPrintCommandBufferAppendUsmAdviseExpParams(
31613161
const struct ur_command_buffer_append_usm_advise_exp_params_t *params,
31623162
char *buffer, const size_t buff_size, size_t *out_size);
31633163

3164+
///////////////////////////////////////////////////////////////////////////////
3165+
/// @brief Print ur_command_buffer_append_native_command_exp_params_t struct
3166+
/// @returns
3167+
/// - ::UR_RESULT_SUCCESS
3168+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
3169+
/// - `buff_size < out_size`
3170+
UR_APIEXPORT ur_result_t UR_APICALL
3171+
urPrintCommandBufferAppendNativeCommandExpParams(
3172+
const struct ur_command_buffer_append_native_command_exp_params_t *params,
3173+
char *buffer, const size_t buff_size, size_t *out_size);
3174+
31643175
///////////////////////////////////////////////////////////////////////////////
31653176
/// @brief Print ur_command_buffer_enqueue_exp_params_t struct
31663177
/// @returns
@@ -3214,6 +3225,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintCommandBufferGetInfoExpParams(
32143225
const struct ur_command_buffer_get_info_exp_params_t *params, char *buffer,
32153226
const size_t buff_size, size_t *out_size);
32163227

3228+
///////////////////////////////////////////////////////////////////////////////
3229+
/// @brief Print ur_command_buffer_get_native_handle_exp_params_t struct
3230+
/// @returns
3231+
/// - ::UR_RESULT_SUCCESS
3232+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
3233+
/// - `buff_size < out_size`
3234+
UR_APIEXPORT ur_result_t UR_APICALL
3235+
urPrintCommandBufferGetNativeHandleExpParams(
3236+
const struct ur_command_buffer_get_native_handle_exp_params_t *params,
3237+
char *buffer, const size_t buff_size, size_t *out_size);
3238+
32173239
///////////////////////////////////////////////////////////////////////////////
32183240
/// @brief Print ur_usm_p2p_enable_peer_access_exp_params_t struct
32193241
/// @returns

include/ur_print.hpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,12 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
11771177
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO:
11781178
os << "UR_FUNCTION_PHYSICAL_MEM_GET_INFO";
11791179
break;
1180+
case UR_FUNCTION_COMMAND_BUFFER_APPEND_NATIVE_COMMAND_EXP:
1181+
os << "UR_FUNCTION_COMMAND_BUFFER_APPEND_NATIVE_COMMAND_EXP";
1182+
break;
1183+
case UR_FUNCTION_COMMAND_BUFFER_GET_NATIVE_HANDLE_EXP:
1184+
os << "UR_FUNCTION_COMMAND_BUFFER_GET_NATIVE_HANDLE_EXP";
1185+
break;
11801186
default:
11811187
os << "unknown enumerator";
11821188
break;
@@ -18635,6 +18641,52 @@ operator<<(std::ostream &os, [[maybe_unused]] const struct
1863518641
return os;
1863618642
}
1863718643

18644+
///////////////////////////////////////////////////////////////////////////////
18645+
/// @brief Print operator for the
18646+
/// ur_command_buffer_append_native_command_exp_params_t type
18647+
/// @returns
18648+
/// std::ostream &
18649+
inline std::ostream &
18650+
operator<<(std::ostream &os, [[maybe_unused]] const struct
18651+
ur_command_buffer_append_native_command_exp_params_t *params) {
18652+
18653+
os << ".hCommandBuffer = ";
18654+
18655+
ur::details::printPtr(os, *(params->phCommandBuffer));
18656+
18657+
os << ", ";
18658+
os << ".pfnNativeCommand = ";
18659+
18660+
os << reinterpret_cast<void *>(*(params->ppfnNativeCommand));
18661+
18662+
os << ", ";
18663+
os << ".pData = ";
18664+
18665+
ur::details::printPtr(os, *(params->ppData));
18666+
18667+
os << ", ";
18668+
os << ".hChildCommandBuffer = ";
18669+
18670+
ur::details::printPtr(os, *(params->phChildCommandBuffer));
18671+
18672+
os << ", ";
18673+
os << ".numSyncPointsInWaitList = ";
18674+
18675+
os << *(params->pnumSyncPointsInWaitList);
18676+
18677+
os << ", ";
18678+
os << ".pSyncPointWaitList = ";
18679+
18680+
ur::details::printPtr(os, *(params->ppSyncPointWaitList));
18681+
18682+
os << ", ";
18683+
os << ".pSyncPoint = ";
18684+
18685+
ur::details::printPtr(os, *(params->ppSyncPoint));
18686+
18687+
return os;
18688+
}
18689+
1863818690
///////////////////////////////////////////////////////////////////////////////
1863918691
/// @brief Print operator for the ur_command_buffer_enqueue_exp_params_t type
1864018692
/// @returns
@@ -18797,6 +18849,27 @@ operator<<(std::ostream &os,
1879718849
return os;
1879818850
}
1879918851

18852+
///////////////////////////////////////////////////////////////////////////////
18853+
/// @brief Print operator for the
18854+
/// ur_command_buffer_get_native_handle_exp_params_t type
18855+
/// @returns
18856+
/// std::ostream &
18857+
inline std::ostream &
18858+
operator<<(std::ostream &os, [[maybe_unused]] const struct
18859+
ur_command_buffer_get_native_handle_exp_params_t *params) {
18860+
18861+
os << ".hCommandBuffer = ";
18862+
18863+
ur::details::printPtr(os, *(params->phCommandBuffer));
18864+
18865+
os << ", ";
18866+
os << ".phNativeCommandBuffer = ";
18867+
18868+
ur::details::printPtr(os, *(params->pphNativeCommandBuffer));
18869+
18870+
return os;
18871+
}
18872+
1880018873
///////////////////////////////////////////////////////////////////////////////
1880118874
/// @brief Print operator for the ur_usm_p2p_enable_peer_access_exp_params_t
1880218875
/// type
@@ -20064,6 +20137,10 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os,
2006420137
os << (const struct ur_command_buffer_append_usm_advise_exp_params_t *)
2006520138
params;
2006620139
} break;
20140+
case UR_FUNCTION_COMMAND_BUFFER_APPEND_NATIVE_COMMAND_EXP: {
20141+
os << (const struct ur_command_buffer_append_native_command_exp_params_t *)
20142+
params;
20143+
} break;
2006720144
case UR_FUNCTION_COMMAND_BUFFER_ENQUEUE_EXP: {
2006820145
os << (const struct ur_command_buffer_enqueue_exp_params_t *)params;
2006920146
} break;
@@ -20082,6 +20159,10 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os,
2008220159
case UR_FUNCTION_COMMAND_BUFFER_GET_INFO_EXP: {
2008320160
os << (const struct ur_command_buffer_get_info_exp_params_t *)params;
2008420161
} break;
20162+
case UR_FUNCTION_COMMAND_BUFFER_GET_NATIVE_HANDLE_EXP: {
20163+
os << (const struct ur_command_buffer_get_native_handle_exp_params_t *)
20164+
params;
20165+
} break;
2008520166
case UR_FUNCTION_USM_P2P_ENABLE_PEER_ACCESS_EXP: {
2008620167
os << (const struct ur_usm_p2p_enable_peer_access_exp_params_t *)params;
2008720168
} break;

0 commit comments

Comments
 (0)