Skip to content

Commit

Permalink
Reference count command handles
Browse files Browse the repository at this point in the history
  • Loading branch information
EwanC committed Jan 12, 2024
1 parent 1ad0e2c commit b6d5ac4
Show file tree
Hide file tree
Showing 36 changed files with 2,101 additions and 115 deletions.
177 changes: 177 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ typedef enum ur_function_t {
UR_FUNCTION_COMMAND_BUFFER_APPEND_USM_ADVISE_EXP = 213, ///< Enumerator for ::urCommandBufferAppendUSMAdviseExp
UR_FUNCTION_ENQUEUE_COOPERATIVE_KERNEL_LAUNCH_EXP = 214, ///< Enumerator for ::urEnqueueCooperativeKernelLaunchExp
UR_FUNCTION_KERNEL_SUGGEST_MAX_COOPERATIVE_GROUP_COUNT_EXP = 215, ///< Enumerator for ::urKernelSuggestMaxCooperativeGroupCountExp
UR_FUNCTION_COMMAND_BUFFER_RETAIN_COMMAND_EXP = 216, ///< Enumerator for ::urCommandBufferRetainCommandExp
UR_FUNCTION_COMMAND_BUFFER_RELEASE_COMMAND_EXP = 217, ///< Enumerator for ::urCommandBufferReleaseCommandExp
UR_FUNCTION_COMMAND_BUFFER_GET_INFO_EXP = 218, ///< Enumerator for ::urCommandBufferGetInfoExp
UR_FUNCTION_COMMAND_BUFFER_COMMAND_GET_INFO_EXP = 219, ///< Enumerator for ::urCommandBufferCommandGetInfoExp
/// @cond
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -7760,6 +7764,36 @@ urBindlessImagesSignalExternalSemaphoreExp(
#if !defined(__GNUC__)
#pragma region command buffer(experimental)
#endif
///////////////////////////////////////////////////////////////////////////////
/// @brief Command-buffer query information type
typedef enum ur_exp_command_buffer_info_t {
UR_EXP_COMMAND_BUFFER_INFO_CONTEXT = 0, ///< [::ur_context_handle_t] Context information of a command-buffer object
UR_EXP_COMMAND_BUFFER_INFO_DEVICE = 1, ///< [::ur_device_handle_t] Device information of a command-buffer object
UR_EXP_COMMAND_BUFFER_INFO_REFERENCE_COUNT = 2, ///< [uint32_t] Reference count of the command-buffer object.
///< The reference count returned should be considered immediately stale.
///< It is unsuitable for general use in applications. This feature is
///< provided for identifying memory leaks.
/// @cond
UR_EXP_COMMAND_BUFFER_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_exp_command_buffer_info_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Command-buffer command query information type
typedef enum ur_exp_command_buffer_command_info_t {
UR_EXP_COMMAND_BUFFER_COMMAND_INFO_COMMAND_BUFFER = 0, ///< [::ur_exp_command_buffer_handle_t] Command-buffer information of a
///< command-buffer command object
UR_EXP_COMMAND_BUFFER_COMMAND_INFO_REFERENCE_COUNT = 1, ///< [uint32_t] Reference count of the command-buffer object.
///< The reference count returned should be considered immediately stale.
///< It is unsuitable for general use in applications. This feature is
///< provided for identifying memory leaks.
/// @cond
UR_EXP_COMMAND_BUFFER_COMMAND_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_exp_command_buffer_command_info_t;

///////////////////////////////////////////////////////////////////////////////
#ifndef UR_COMMAND_BUFFER_EXTENSION_STRING_EXP
/// @brief The extension string which defines support for command-buffers which
Expand Down Expand Up @@ -8435,6 +8469,43 @@ urCommandBufferEnqueueExp(
///< command-buffer execution instance.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Increment the command object's reference count.
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hCommand`
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferRetainCommandExp(
ur_exp_command_buffer_command_handle_t hCommand ///< [in] Handle of the command-buffer command.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Decrement the command object's reference count and delete the command
/// object if the reference count becomes zero.
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hCommand`
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferReleaseCommandExp(
ur_exp_command_buffer_command_handle_t hCommand ///< [in] Handle of the command-buffer command.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Update a kernel launch command.
///
Expand Down Expand Up @@ -8467,6 +8538,72 @@ urCommandBufferUpdateKernelLaunchExp(
const ur_exp_command_buffer_update_kernel_launch_desc_t *pUpdateKernelLaunch ///< [in] Struct defining how the kernel command is to be updated.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Get command-buffer object information
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hCommandBuffer`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_EXP_COMMAND_BUFFER_INFO_REFERENCE_COUNT < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferGetInfoExp(
ur_exp_command_buffer_handle_t hCommandBuffer, ///< [in] handle of the command-buffer object
ur_exp_command_buffer_info_t propName, ///< [in] the name of the command-buffer property to query
size_t propSize, ///< [in] size in bytes of the command-buffer property value
void *pPropValue, ///< [out][optional][typename(propName, propSize)] value of the
///< command-buffer property
size_t *pPropSizeRet ///< [out][optional] bytes returned in command-buffer property
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Get command-buffer jbject information
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hCommand`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_EXP_COMMAND_BUFFER_COMMAND_INFO_REFERENCE_COUNT < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferCommandGetInfoExp(
ur_exp_command_buffer_command_handle_t hCommand, ///< [in] handle of the command-buffer command object
ur_exp_command_buffer_command_info_t propName, ///< [in] the name of the command-buffer command property to query
size_t propSize, ///< [in] size in bytes of the command-buffer command property value
void *pPropValue, ///< [out][optional][typename(propName, propSize)] value of the
///< command-buffer command property
size_t *pPropSizeRet ///< [out][optional] bytes returned in command-buffer command property
);

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -10819,6 +10956,22 @@ typedef struct ur_command_buffer_enqueue_exp_params_t {
ur_event_handle_t **pphEvent;
} ur_command_buffer_enqueue_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urCommandBufferRetainCommandExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_command_buffer_retain_command_exp_params_t {
ur_exp_command_buffer_command_handle_t *phCommand;
} ur_command_buffer_retain_command_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urCommandBufferReleaseCommandExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_command_buffer_release_command_exp_params_t {
ur_exp_command_buffer_command_handle_t *phCommand;
} ur_command_buffer_release_command_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urCommandBufferUpdateKernelLaunchExp
/// @details Each entry is a pointer to the parameter passed to the function;
Expand All @@ -10828,6 +10981,30 @@ typedef struct ur_command_buffer_update_kernel_launch_exp_params_t {
const ur_exp_command_buffer_update_kernel_launch_desc_t **ppUpdateKernelLaunch;
} ur_command_buffer_update_kernel_launch_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urCommandBufferGetInfoExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_command_buffer_get_info_exp_params_t {
ur_exp_command_buffer_handle_t *phCommandBuffer;
ur_exp_command_buffer_info_t *ppropName;
size_t *ppropSize;
void **ppPropValue;
size_t **ppPropSizeRet;
} ur_command_buffer_get_info_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urCommandBufferCommandGetInfoExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_command_buffer_command_get_info_exp_params_t {
ur_exp_command_buffer_command_handle_t *phCommand;
ur_exp_command_buffer_command_info_t *ppropName;
size_t *ppropSize;
void **ppPropValue;
size_t **ppPropSizeRet;
} ur_command_buffer_command_get_info_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urUsmP2PEnablePeerAccessExp
/// @details Each entry is a pointer to the parameter passed to the function;
Expand Down
32 changes: 32 additions & 0 deletions include/ur_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2011,12 +2011,40 @@ typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferEnqueueExp_t)(
const ur_event_handle_t *,
ur_event_handle_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urCommandBufferRetainCommandExp
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferRetainCommandExp_t)(
ur_exp_command_buffer_command_handle_t);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urCommandBufferReleaseCommandExp
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferReleaseCommandExp_t)(
ur_exp_command_buffer_command_handle_t);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urCommandBufferUpdateKernelLaunchExp
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferUpdateKernelLaunchExp_t)(
ur_exp_command_buffer_command_handle_t,
const ur_exp_command_buffer_update_kernel_launch_desc_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urCommandBufferGetInfoExp
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferGetInfoExp_t)(
ur_exp_command_buffer_handle_t,
ur_exp_command_buffer_info_t,
size_t,
void *,
size_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urCommandBufferCommandGetInfoExp
typedef ur_result_t(UR_APICALL *ur_pfnCommandBufferCommandGetInfoExp_t)(
ur_exp_command_buffer_command_handle_t,
ur_exp_command_buffer_command_info_t,
size_t,
void *,
size_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Table of CommandBufferExp functions pointers
typedef struct ur_command_buffer_exp_dditable_t {
Expand All @@ -2037,7 +2065,11 @@ typedef struct ur_command_buffer_exp_dditable_t {
ur_pfnCommandBufferAppendUSMPrefetchExp_t pfnAppendUSMPrefetchExp;
ur_pfnCommandBufferAppendUSMAdviseExp_t pfnAppendUSMAdviseExp;
ur_pfnCommandBufferEnqueueExp_t pfnEnqueueExp;
ur_pfnCommandBufferRetainCommandExp_t pfnRetainCommandExp;
ur_pfnCommandBufferReleaseCommandExp_t pfnReleaseCommandExp;
ur_pfnCommandBufferUpdateKernelLaunchExp_t pfnUpdateKernelLaunchExp;
ur_pfnCommandBufferGetInfoExp_t pfnGetInfoExp;
ur_pfnCommandBufferCommandGetInfoExp_t pfnCommandGetInfoExp;
} ur_command_buffer_exp_dditable_t;

///////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit b6d5ac4

Please sign in to comment.