Skip to content

Commit 6f159f4

Browse files
authored
[UR] Add spec and implementation for urQueueGetGraphExp (#21817)
Introduces UR graph spec and implementation for `urQueueGetGraphExp` which returns graph handles from a recording queue. The following changes are made: - A map of L0 to UR graph handles is made to fetch UR graph handles from across command lists. This allows UR to fetch the correct graph handle if created by a separate command list manager due to fork-join. Map is stored in the context and protected by a lock. - Map entries are added and removed in graph creation and destruction respectively. - In implicit recording mode (where the user makes no `urGraphCreateExp` call), graph handle creation is done in the first instance of `urQueueGetGraphExp` (if it occurs) instead of `urQueueEndCaptureExp` as the user must be returned a ur_exp_graph_handle_t. - L0 experimental headers are bumped to https://github.com/intel/compute-runtime/releases/tag/26.14.37833.4 where `zeCommandListGetGraphExp` is supported.
1 parent c57417f commit 6f159f4

60 files changed

Lines changed: 955 additions & 203 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

unified-runtime/include/unified-runtime/ur_api.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ typedef enum ur_function_t {
509509
UR_FUNCTION_USM_HOST_ALLOC_REGISTER_EXP = 312,
510510
/// Enumerator for ::urUSMHostAllocUnregisterExp
511511
UR_FUNCTION_USM_HOST_ALLOC_UNREGISTER_EXP = 313,
512+
/// Enumerator for ::urQueueGetGraphExp
513+
UR_FUNCTION_QUEUE_GET_GRAPH_EXP = 314,
512514
/// @cond
513515
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
514516
/// @endcond
@@ -13807,6 +13809,27 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueIsGraphCaptureEnabledExp(
1380713809
/// [out] Pointer to a boolean where the result will be stored.
1380813810
bool *pResult);
1380913811

13812+
///////////////////////////////////////////////////////////////////////////////
13813+
/// @brief Get the graph handle currently being captured on the specified queue.
13814+
///
13815+
/// @returns
13816+
/// - ::UR_RESULT_SUCCESS
13817+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
13818+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
13819+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
13820+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
13821+
/// + `NULL == hQueue`
13822+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
13823+
/// + `NULL == phGraph`
13824+
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
13825+
/// + The queue is not in graph capture mode.
13826+
UR_APIEXPORT ur_result_t UR_APICALL urQueueGetGraphExp(
13827+
/// [in] Handle of the queue to query.
13828+
ur_queue_handle_t hQueue,
13829+
/// [out] Pointer to the handle of the graph being captured. Set to
13830+
/// nullptr if queue is not in capture mode.
13831+
ur_exp_graph_handle_t *phGraph);
13832+
1381013833
///////////////////////////////////////////////////////////////////////////////
1381113834
/// @brief Return whether the given recorded graph contains any nodes.
1381213835
///
@@ -14657,6 +14680,15 @@ typedef struct ur_queue_is_graph_capture_enabled_exp_params_t {
1465714680
bool **ppResult;
1465814681
} ur_queue_is_graph_capture_enabled_exp_params_t;
1465914682

14683+
///////////////////////////////////////////////////////////////////////////////
14684+
/// @brief Function parameters for urQueueGetGraphExp
14685+
/// @details Each entry is a pointer to the parameter passed to the function;
14686+
/// allowing the callback the ability to modify the parameter's value
14687+
typedef struct ur_queue_get_graph_exp_params_t {
14688+
ur_queue_handle_t *phQueue;
14689+
ur_exp_graph_handle_t **pphGraph;
14690+
} ur_queue_get_graph_exp_params_t;
14691+
1466014692
///////////////////////////////////////////////////////////////////////////////
1466114693
/// @brief Function parameters for urSamplerCreate
1466214694
/// @details Each entry is a pointer to the parameter passed to the function;

unified-runtime/include/unified-runtime/ur_api_funcs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ _UR_API(urQueueBeginGraphCaptureExp)
8888
_UR_API(urQueueBeginCaptureIntoGraphExp)
8989
_UR_API(urQueueEndGraphCaptureExp)
9090
_UR_API(urQueueIsGraphCaptureEnabledExp)
91+
_UR_API(urQueueGetGraphExp)
9192
_UR_API(urSamplerCreate)
9293
_UR_API(urSamplerRetain)
9394
_UR_API(urSamplerRelease)

unified-runtime/include/unified-runtime/ur_ddi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,13 +677,19 @@ typedef ur_result_t(UR_APICALL *ur_pfnQueueEndGraphCaptureExp_t)(
677677
typedef ur_result_t(UR_APICALL *ur_pfnQueueIsGraphCaptureEnabledExp_t)(
678678
ur_queue_handle_t, bool *);
679679

680+
///////////////////////////////////////////////////////////////////////////////
681+
/// @brief Function-pointer for urQueueGetGraphExp
682+
typedef ur_result_t(UR_APICALL *ur_pfnQueueGetGraphExp_t)(
683+
ur_queue_handle_t, ur_exp_graph_handle_t *);
684+
680685
///////////////////////////////////////////////////////////////////////////////
681686
/// @brief Table of QueueExp functions pointers
682687
typedef struct ur_queue_exp_dditable_t {
683688
ur_pfnQueueBeginGraphCaptureExp_t pfnBeginGraphCaptureExp;
684689
ur_pfnQueueBeginCaptureIntoGraphExp_t pfnBeginCaptureIntoGraphExp;
685690
ur_pfnQueueEndGraphCaptureExp_t pfnEndGraphCaptureExp;
686691
ur_pfnQueueIsGraphCaptureEnabledExp_t pfnIsGraphCaptureEnabledExp;
692+
ur_pfnQueueGetGraphExp_t pfnGetGraphExp;
687693
} ur_queue_exp_dditable_t;
688694

689695
///////////////////////////////////////////////////////////////////////////////

unified-runtime/include/unified-runtime/ur_print.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintQueueIsGraphCaptureEnabledExpParams(
23542354
const struct ur_queue_is_graph_capture_enabled_exp_params_t *params,
23552355
char *buffer, const size_t buff_size, size_t *out_size);
23562356

2357+
///////////////////////////////////////////////////////////////////////////////
2358+
/// @brief Print ur_queue_get_graph_exp_params_t struct
2359+
/// @returns
2360+
/// - ::UR_RESULT_SUCCESS
2361+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
2362+
/// - `buff_size < out_size`
2363+
UR_APIEXPORT ur_result_t UR_APICALL urPrintQueueGetGraphExpParams(
2364+
const struct ur_queue_get_graph_exp_params_t *params, char *buffer,
2365+
const size_t buff_size, size_t *out_size);
2366+
23572367
///////////////////////////////////////////////////////////////////////////////
23582368
/// @brief Print ur_sampler_create_params_t struct
23592369
/// @returns

unified-runtime/include/unified-runtime/ur_print.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
13751375
case UR_FUNCTION_USM_HOST_ALLOC_UNREGISTER_EXP:
13761376
os << "UR_FUNCTION_USM_HOST_ALLOC_UNREGISTER_EXP";
13771377
break;
1378+
case UR_FUNCTION_QUEUE_GET_GRAPH_EXP:
1379+
os << "UR_FUNCTION_QUEUE_GET_GRAPH_EXP";
1380+
break;
13781381
default:
13791382
os << "unknown enumerator";
13801383
break;
@@ -15490,6 +15493,26 @@ inline std::ostream &operator<<(
1549015493
return os;
1549115494
}
1549215495

15496+
///////////////////////////////////////////////////////////////////////////////
15497+
/// @brief Print operator for the ur_queue_get_graph_exp_params_t type
15498+
/// @returns
15499+
/// std::ostream &
15500+
inline std::ostream &operator<<(
15501+
std::ostream &os,
15502+
[[maybe_unused]] const struct ur_queue_get_graph_exp_params_t *params) {
15503+
15504+
os << ".hQueue = ";
15505+
15506+
ur::details::printPtr(os, *(params->phQueue));
15507+
15508+
os << ", ";
15509+
os << ".phGraph = ";
15510+
15511+
ur::details::printPtr(os, *(params->pphGraph));
15512+
15513+
return os;
15514+
}
15515+
1549315516
///////////////////////////////////////////////////////////////////////////////
1549415517
/// @brief Print operator for the ur_sampler_create_params_t type
1549515518
/// @returns
@@ -22656,6 +22679,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os,
2265622679
case UR_FUNCTION_QUEUE_IS_GRAPH_CAPTURE_ENABLED_EXP: {
2265722680
os << (const struct ur_queue_is_graph_capture_enabled_exp_params_t *)params;
2265822681
} break;
22682+
case UR_FUNCTION_QUEUE_GET_GRAPH_EXP: {
22683+
os << (const struct ur_queue_get_graph_exp_params_t *)params;
22684+
} break;
2265922685
case UR_FUNCTION_SAMPLER_CREATE: {
2266022686
os << (const struct ur_sampler_create_params_t *)params;
2266122687
} break;

unified-runtime/scripts/core/EXP-GRAPH.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Functions
4949
* ${x}QueueBeginCaptureIntoGraphExp
5050
* ${x}QueueEndGraphCaptureExp
5151
* ${x}QueueIsGraphCaptureEnabledExp
52+
* ${x}QueueGetGraphExp
5253
* ${x}EnqueueGraphExp
5354

5455
Changelog
@@ -68,6 +69,9 @@ Changelog
6869
| | Rename QueueAppendGraphExp into |
6970
| | EnqueueGraphExp. |
7071
+-----------+---------------------------------------------+
72+
| 1.3 | Add ${x}QueueGetGraphExp to retrieve graph |
73+
| | handle from queue in capture mode. |
74+
+-----------+---------------------------------------------+
7175

7276
Support
7377
--------------------------------------------------------------------------------

unified-runtime/scripts/core/exp-graph.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ params:
160160
desc: "[out] Pointer to a boolean where the result will be stored."
161161
--- #--------------------------------------------------------------------------
162162
type: function
163+
desc: "Get the graph handle currently being captured on the specified queue."
164+
class: $xQueue
165+
name: GetGraphExp
166+
params:
167+
- type: $x_queue_handle_t
168+
name: hQueue
169+
desc: "[in] Handle of the queue to query."
170+
- type: $x_exp_graph_handle_t*
171+
name: phGraph
172+
desc: "[out] Pointer to the handle of the graph being captured. Set to nullptr if queue is not in capture mode."
173+
returns:
174+
- $X_RESULT_ERROR_INVALID_OPERATION:
175+
- "The queue is not in graph capture mode."
176+
--- #--------------------------------------------------------------------------
177+
type: function
163178
desc: "Return whether the given recorded graph contains any nodes."
164179
class: $xGraph
165180
name: IsEmptyExp

unified-runtime/scripts/core/registry.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,10 @@ etors:
721721
- name: USM_HOST_ALLOC_UNREGISTER_EXP
722722
desc: Enumerator for $xUSMHostAllocUnregisterExp
723723
value: '313'
724-
max_id: '313'
724+
- name: QUEUE_GET_GRAPH_EXP
725+
desc: Enumerator for $xQueueGetGraphExp
726+
value: '314'
727+
max_id: '314'
725728
---
726729
type: enum
727730
desc: Defines structure types

unified-runtime/source/adapters/cuda/queue.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueIsGraphCaptureEnabledExp(
289289
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
290290
}
291291

292+
UR_APIEXPORT ur_result_t UR_APICALL urQueueGetGraphExp(
293+
ur_queue_handle_t /* hQueue */, ur_exp_graph_handle_t * /* phGraph */) {
294+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
295+
}
296+
292297
UR_APIEXPORT ur_result_t UR_APICALL urEnqueueHostTaskExp(
293298
ur_queue_handle_t /* hQueue */,
294299
ur_exp_host_task_function_t /* pfnHostTask */, void * /* data */,

unified-runtime/source/adapters/cuda/ur_interface_loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetQueueExpProcAddrTable(
256256
pDdiTable->pfnBeginCaptureIntoGraphExp = urQueueBeginCaptureIntoGraphExp;
257257
pDdiTable->pfnEndGraphCaptureExp = urQueueEndGraphCaptureExp;
258258
pDdiTable->pfnIsGraphCaptureEnabledExp = urQueueIsGraphCaptureEnabledExp;
259+
pDdiTable->pfnGetGraphExp = urQueueGetGraphExp;
259260

260261
return UR_RESULT_SUCCESS;
261262
}

0 commit comments

Comments
 (0)