Skip to content

Commit aa57f89

Browse files
author
Petr Vesely
committed
[ur] Add urDeviceGetGlobalTimestamps
1 parent 7ef04f9 commit aa57f89

File tree

8 files changed

+229
-1
lines changed

8 files changed

+229
-1
lines changed

include/ur.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,13 @@ class ur_queue_dditable_t(Structure):
19061906
else:
19071907
_urDeviceCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, ur_platform_handle_t, POINTER(ur_device_handle_t) )
19081908

1909+
###############################################################################
1910+
## @brief Function-pointer for urDeviceGetGlobalTimestamps
1911+
if __use_win_types:
1912+
_urDeviceGetGlobalTimestamps_t = WINFUNCTYPE( ur_result_t, ur_device_handle_t, POINTER(c_ulonglong), POINTER(c_ulonglong) )
1913+
else:
1914+
_urDeviceGetGlobalTimestamps_t = CFUNCTYPE( ur_result_t, ur_device_handle_t, POINTER(c_ulonglong), POINTER(c_ulonglong) )
1915+
19091916

19101917
###############################################################################
19111918
## @brief Table of Device functions pointers
@@ -1918,7 +1925,8 @@ class ur_device_dditable_t(Structure):
19181925
("pfnPartition", c_void_p), ## _urDevicePartition_t
19191926
("pfnSelectBinary", c_void_p), ## _urDeviceSelectBinary_t
19201927
("pfnGetNativeHandle", c_void_p), ## _urDeviceGetNativeHandle_t
1921-
("pfnCreateWithNativeHandle", c_void_p) ## _urDeviceCreateWithNativeHandle_t
1928+
("pfnCreateWithNativeHandle", c_void_p), ## _urDeviceCreateWithNativeHandle_t
1929+
("pfnGetGlobalTimestamps", c_void_p) ## _urDeviceGetGlobalTimestamps_t
19221930
]
19231931

19241932
###############################################################################
@@ -2177,5 +2185,6 @@ def __init__(self, version : ur_api_version_t):
21772185
self.urDeviceSelectBinary = _urDeviceSelectBinary_t(self.__dditable.Device.pfnSelectBinary)
21782186
self.urDeviceGetNativeHandle = _urDeviceGetNativeHandle_t(self.__dditable.Device.pfnGetNativeHandle)
21792187
self.urDeviceCreateWithNativeHandle = _urDeviceCreateWithNativeHandle_t(self.__dditable.Device.pfnCreateWithNativeHandle)
2188+
self.urDeviceGetGlobalTimestamps = _urDeviceGetGlobalTimestamps_t(self.__dditable.Device.pfnGetGlobalTimestamps)
21802189

21812190
# success!

include/ur_api.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,6 +3148,36 @@ urDeviceCreateWithNativeHandle(
31483148
ur_device_handle_t* phDevice ///< [out] pointer to the handle of the device object created.
31493149
);
31503150

3151+
///////////////////////////////////////////////////////////////////////////////
3152+
/// @brief static
3153+
///
3154+
/// @details
3155+
/// - The application may call this function from simultaneous threads for
3156+
/// the same context.
3157+
/// - The implementation of this function should be thread-safe.
3158+
///
3159+
/// @remarks
3160+
/// _Analogues_
3161+
/// - **clGetDeviceAndHostTimer**
3162+
///
3163+
/// @returns
3164+
/// - ::UR_RESULT_SUCCESS
3165+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
3166+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
3167+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
3168+
/// + `NULL == hDevice`
3169+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
3170+
/// + `NULL == pDeviceTimestamp`
3171+
/// + `NULL == pHostTimestamp`
3172+
UR_APIEXPORT ur_result_t UR_APICALL
3173+
urDeviceGetGlobalTimestamps(
3174+
ur_device_handle_t hDevice, ///< [in] handle of the device instance
3175+
uint64_t* pDeviceTimestamp, ///< [out] pointer to the Device's global timestamp that
3176+
///< correlates with the Host's global timestamp value
3177+
uint64_t* pHostTimestamp ///< [out] pointer to the Host's global timestamp that
3178+
///< correlates with the Device's global timestamp value
3179+
);
3180+
31513181
#if !defined(__GNUC__)
31523182
#pragma endregion
31533183
#endif
@@ -7115,6 +7145,30 @@ typedef void (UR_APICALL *ur_pfnDeviceCreateWithNativeHandleCb_t)(
71157145
void** ppTracerInstanceUserData
71167146
);
71177147

7148+
///////////////////////////////////////////////////////////////////////////////
7149+
/// @brief Callback function parameters for urDeviceGetGlobalTimestamps
7150+
/// @details Each entry is a pointer to the parameter passed to the function;
7151+
/// allowing the callback the ability to modify the parameter's value
7152+
typedef struct ur_device_get_global_timestamps_params_t
7153+
{
7154+
ur_device_handle_t* phDevice;
7155+
uint64_t** ppDeviceTimestamp;
7156+
uint64_t** ppHostTimestamp;
7157+
} ur_device_get_global_timestamps_params_t;
7158+
7159+
///////////////////////////////////////////////////////////////////////////////
7160+
/// @brief Callback function-pointer for urDeviceGetGlobalTimestamps
7161+
/// @param[in] params Parameters passed to this instance
7162+
/// @param[in] result Return value
7163+
/// @param[in] pTracerUserData Per-Tracer user data
7164+
/// @param[in,out] ppTracerInstanceUserData Per-Tracer, Per-Instance user data
7165+
typedef void (UR_APICALL *ur_pfnDeviceGetGlobalTimestampsCb_t)(
7166+
ur_device_get_global_timestamps_params_t* params,
7167+
ur_result_t result,
7168+
void* pTracerUserData,
7169+
void** ppTracerInstanceUserData
7170+
);
7171+
71187172
///////////////////////////////////////////////////////////////////////////////
71197173
/// @brief Table of Device callback functions pointers
71207174
typedef struct ur_device_callbacks_t
@@ -7127,6 +7181,7 @@ typedef struct ur_device_callbacks_t
71277181
ur_pfnDeviceSelectBinaryCb_t pfnSelectBinaryCb;
71287182
ur_pfnDeviceGetNativeHandleCb_t pfnGetNativeHandleCb;
71297183
ur_pfnDeviceCreateWithNativeHandleCb_t pfnCreateWithNativeHandleCb;
7184+
ur_pfnDeviceGetGlobalTimestampsCb_t pfnGetGlobalTimestampsCb;
71307185
} ur_device_callbacks_t;
71317186

71327187
///////////////////////////////////////////////////////////////////////////////

include/ur_ddi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,14 @@ typedef ur_result_t (UR_APICALL *ur_pfnDeviceCreateWithNativeHandle_t)(
14201420
ur_device_handle_t*
14211421
);
14221422

1423+
///////////////////////////////////////////////////////////////////////////////
1424+
/// @brief Function-pointer for urDeviceGetGlobalTimestamps
1425+
typedef ur_result_t (UR_APICALL *ur_pfnDeviceGetGlobalTimestamps_t)(
1426+
ur_device_handle_t,
1427+
uint64_t*,
1428+
uint64_t*
1429+
);
1430+
14231431
///////////////////////////////////////////////////////////////////////////////
14241432
/// @brief Table of Device functions pointers
14251433
typedef struct ur_device_dditable_t
@@ -1432,6 +1440,7 @@ typedef struct ur_device_dditable_t
14321440
ur_pfnDeviceSelectBinary_t pfnSelectBinary;
14331441
ur_pfnDeviceGetNativeHandle_t pfnGetNativeHandle;
14341442
ur_pfnDeviceCreateWithNativeHandle_t pfnCreateWithNativeHandle;
1443+
ur_pfnDeviceGetGlobalTimestamps_t pfnGetGlobalTimestamps;
14351444
} ur_device_dditable_t;
14361445

14371446
///////////////////////////////////////////////////////////////////////////////

scripts/core/device.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,29 @@ params:
568568
name: phDevice
569569
desc: |
570570
[out] pointer to the handle of the device object created.
571+
--- #--------------------------------------------------------------------------
572+
type: function
573+
desc: "Returns synchronized Host and Device global timestamps."
574+
class: $xDevice
575+
name: GetGlobalTimestamps
576+
desc: static
577+
ordinal: "0"
578+
analogue:
579+
- "**clGetDeviceAndHostTimer**"
580+
details:
581+
- "The application may call this function from simultaneous threads for the same context."
582+
- "The implementation of this function should be thread-safe."
583+
params:
584+
- type: $x_device_handle_t
585+
name: hDevice
586+
desc: "[in] handle of the device instance"
587+
- type: "uint64_t*"
588+
name: pDeviceTimestamp
589+
desc: |
590+
[out] pointer to the Device's global timestamp that
591+
correlates with the Host's global timestamp value
592+
- type: "uint64_t*"
593+
name: pHostTimestamp
594+
desc: |
595+
[out] pointer to the Host's global timestamp that
596+
correlates with the Device's global timestamp value

source/drivers/null/ur_nullddi.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,33 @@ namespace driver
21382138
return result;
21392139
}
21402140

2141+
///////////////////////////////////////////////////////////////////////////////
2142+
/// @brief Intercept function for urDeviceGetGlobalTimestamps
2143+
__urdlllocal ur_result_t UR_APICALL
2144+
urDeviceGetGlobalTimestamps(
2145+
ur_device_handle_t hDevice, ///< [in] handle of the device instance
2146+
uint64_t* pDeviceTimestamp, ///< [out] pointer to the Device's global timestamp that
2147+
///< correlates with the Host's global timestamp value
2148+
uint64_t* pHostTimestamp ///< [out] pointer to the Host's global timestamp that
2149+
///< correlates with the Device's global timestamp value
2150+
)
2151+
{
2152+
ur_result_t result = UR_RESULT_SUCCESS;
2153+
2154+
// if the driver has created a custom function, then call it instead of using the generic path
2155+
auto pfnGetGlobalTimestamps = d_context.urDdiTable.Device.pfnGetGlobalTimestamps;
2156+
if( nullptr != pfnGetGlobalTimestamps )
2157+
{
2158+
result = pfnGetGlobalTimestamps( hDevice, pDeviceTimestamp, pHostTimestamp );
2159+
}
2160+
else
2161+
{
2162+
// generic implementation
2163+
}
2164+
2165+
return result;
2166+
}
2167+
21412168
///////////////////////////////////////////////////////////////////////////////
21422169
/// @brief Intercept function for urKernelCreate
21432170
__urdlllocal ur_result_t UR_APICALL
@@ -3622,6 +3649,8 @@ urGetDeviceProcAddrTable(
36223649

36233650
pDdiTable->pfnCreateWithNativeHandle = driver::urDeviceCreateWithNativeHandle;
36243651

3652+
pDdiTable->pfnGetGlobalTimestamps = driver::urDeviceGetGlobalTimestamps;
3653+
36253654
return result;
36263655
}
36273656

source/loader/ur_ldrddi.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,34 @@ namespace loader
28702870
return result;
28712871
}
28722872

2873+
///////////////////////////////////////////////////////////////////////////////
2874+
/// @brief Intercept function for urDeviceGetGlobalTimestamps
2875+
__urdlllocal ur_result_t UR_APICALL
2876+
urDeviceGetGlobalTimestamps(
2877+
ur_device_handle_t hDevice, ///< [in] handle of the device instance
2878+
uint64_t* pDeviceTimestamp, ///< [out] pointer to the Device's global timestamp that
2879+
///< correlates with the Host's global timestamp value
2880+
uint64_t* pHostTimestamp ///< [out] pointer to the Host's global timestamp that
2881+
///< correlates with the Device's global timestamp value
2882+
)
2883+
{
2884+
ur_result_t result = UR_RESULT_SUCCESS;
2885+
2886+
// extract platform's function pointer table
2887+
auto dditable = reinterpret_cast<ur_device_object_t*>( hDevice )->dditable;
2888+
auto pfnGetGlobalTimestamps = dditable->ur.Device.pfnGetGlobalTimestamps;
2889+
if( nullptr == pfnGetGlobalTimestamps )
2890+
return UR_RESULT_ERROR_UNINITIALIZED;
2891+
2892+
// convert loader handle to platform handle
2893+
hDevice = reinterpret_cast<ur_device_object_t*>( hDevice )->handle;
2894+
2895+
// forward to device-platform
2896+
result = pfnGetGlobalTimestamps( hDevice, pDeviceTimestamp, pHostTimestamp );
2897+
2898+
return result;
2899+
}
2900+
28732901
///////////////////////////////////////////////////////////////////////////////
28742902
/// @brief Intercept function for urKernelCreate
28752903
__urdlllocal ur_result_t UR_APICALL
@@ -4991,6 +5019,7 @@ urGetDeviceProcAddrTable(
49915019
pDdiTable->pfnSelectBinary = loader::urDeviceSelectBinary;
49925020
pDdiTable->pfnGetNativeHandle = loader::urDeviceGetNativeHandle;
49935021
pDdiTable->pfnCreateWithNativeHandle = loader::urDeviceCreateWithNativeHandle;
5022+
pDdiTable->pfnGetGlobalTimestamps = loader::urDeviceGetGlobalTimestamps;
49945023
}
49955024
else
49965025
{

source/loader/ur_libapi.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,43 @@ urDeviceCreateWithNativeHandle(
27852785
return pfnCreateWithNativeHandle( hNativeDevice, hPlatform, phDevice );
27862786
}
27872787

2788+
///////////////////////////////////////////////////////////////////////////////
2789+
/// @brief static
2790+
///
2791+
/// @details
2792+
/// - The application may call this function from simultaneous threads for
2793+
/// the same context.
2794+
/// - The implementation of this function should be thread-safe.
2795+
///
2796+
/// @remarks
2797+
/// _Analogues_
2798+
/// - **clGetDeviceAndHostTimer**
2799+
///
2800+
/// @returns
2801+
/// - ::UR_RESULT_SUCCESS
2802+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
2803+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
2804+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
2805+
/// + `NULL == hDevice`
2806+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
2807+
/// + `NULL == pDeviceTimestamp`
2808+
/// + `NULL == pHostTimestamp`
2809+
ur_result_t UR_APICALL
2810+
urDeviceGetGlobalTimestamps(
2811+
ur_device_handle_t hDevice, ///< [in] handle of the device instance
2812+
uint64_t* pDeviceTimestamp, ///< [out] pointer to the Device's global timestamp that
2813+
///< correlates with the Host's global timestamp value
2814+
uint64_t* pHostTimestamp ///< [out] pointer to the Host's global timestamp that
2815+
///< correlates with the Device's global timestamp value
2816+
)
2817+
{
2818+
auto pfnGetGlobalTimestamps = ur_lib::context->urDdiTable.Device.pfnGetGlobalTimestamps;
2819+
if( nullptr == pfnGetGlobalTimestamps )
2820+
return UR_RESULT_ERROR_UNINITIALIZED;
2821+
2822+
return pfnGetGlobalTimestamps( hDevice, pDeviceTimestamp, pHostTimestamp );
2823+
}
2824+
27882825
///////////////////////////////////////////////////////////////////////////////
27892826
/// @brief Create kernel object from a program.
27902827
///

source/ur_api.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,40 @@ urDeviceCreateWithNativeHandle(
25692569
return result;
25702570
}
25712571

2572+
///////////////////////////////////////////////////////////////////////////////
2573+
/// @brief static
2574+
///
2575+
/// @details
2576+
/// - The application may call this function from simultaneous threads for
2577+
/// the same context.
2578+
/// - The implementation of this function should be thread-safe.
2579+
///
2580+
/// @remarks
2581+
/// _Analogues_
2582+
/// - **clGetDeviceAndHostTimer**
2583+
///
2584+
/// @returns
2585+
/// - ::UR_RESULT_SUCCESS
2586+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
2587+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
2588+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
2589+
/// + `NULL == hDevice`
2590+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
2591+
/// + `NULL == pDeviceTimestamp`
2592+
/// + `NULL == pHostTimestamp`
2593+
ur_result_t UR_APICALL
2594+
urDeviceGetGlobalTimestamps(
2595+
ur_device_handle_t hDevice, ///< [in] handle of the device instance
2596+
uint64_t* pDeviceTimestamp, ///< [out] pointer to the Device's global timestamp that
2597+
///< correlates with the Host's global timestamp value
2598+
uint64_t* pHostTimestamp ///< [out] pointer to the Host's global timestamp that
2599+
///< correlates with the Device's global timestamp value
2600+
)
2601+
{
2602+
ur_result_t result = UR_RESULT_SUCCESS;
2603+
return result;
2604+
}
2605+
25722606
///////////////////////////////////////////////////////////////////////////////
25732607
/// @brief Create kernel object from a program.
25742608
///

0 commit comments

Comments
 (0)