Skip to content

[L0v2] Add retrieval of native graph handle#22097

Draft
KFilipek wants to merge 4 commits into
intel:syclfrom
KFilipek:09-native_graph_api
Draft

[L0v2] Add retrieval of native graph handle#22097
KFilipek wants to merge 4 commits into
intel:syclfrom
KFilipek:09-native_graph_api

Conversation

@KFilipek
Copy link
Copy Markdown
Contributor

This PR introduces two new experimental entry points to expose the underlying
native graph handle from a UR graph.

KFilipek added 3 commits May 22, 2026 16:24
…iveHandleExp

Introduce two experimental APIs to retrieve native graph handles from
ur_exp_graph_handle_t and ur_exp_executable_graph_handle_t.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two new experimental Unified Runtime (UR) Graph entry points to retrieve the underlying native graph/executable-graph handle, enabling direct interop with the backend driver (implemented for Level Zero v2, stubbed elsewhere) and plumbed through the loader and its layers.

Changes:

  • Introduces urGraphGetNativeHandleExp and urGraphExecutableGraphGetNativeHandleExp across the public API, DDI tables, loader exports, and tracing/validation layers.
  • Implements native handle retrieval in the Level Zero v2 adapter; other adapters expose the functions as unsupported/not implemented.
  • Updates printing/logging and code-generation inputs/templates to recognize and format the new APIs.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
unified-runtime/source/ur_api.cpp Adds stub API entry points for graph native-handle retrieval.
unified-runtime/source/loader/ur_print.cpp Adds parameter-print helpers for the new graph APIs.
unified-runtime/source/loader/ur_libapi.cpp Adds loader dispatch for the new graph native-handle APIs.
unified-runtime/source/loader/ur_ldrddi.cpp Adds loader intercept/DDI wiring for the new graph native-handle APIs.
unified-runtime/source/loader/loader.map.in Exports new loader symbols for the graph native-handle APIs and their print helpers.
unified-runtime/source/loader/loader.def.in Exports new loader symbols for Windows builds.
unified-runtime/source/loader/layers/validation/ur_valddi.cpp Adds validation-layer intercepts and parameter checks for the new APIs.
unified-runtime/source/loader/layers/tracing/ur_trcddi.cpp Adds tracing-layer intercepts, logging, and callbacks for the new APIs.
unified-runtime/source/adapters/opencl/ur_interface_loader.cpp Wires new function pointers into the OpenCL adapter’s GraphExp proc table.
unified-runtime/source/adapters/opencl/graph.cpp Adds OpenCL stubs returning unsupported for the new APIs.
unified-runtime/source/adapters/offload/ur_interface_loader.cpp Wires new function pointers into the offload adapter’s GraphExp proc table.
unified-runtime/source/adapters/offload/graph.cpp Adds offload stubs returning unsupported for the new APIs.
unified-runtime/source/adapters/native_cpu/ur_interface_loader.cpp Wires new function pointers into the native_cpu adapter’s GraphExp proc table.
unified-runtime/source/adapters/native_cpu/graph.cpp Adds native_cpu stubs (DIE_NO_IMPLEMENTATION) for the new APIs.
unified-runtime/source/adapters/mock/ur_mockddi.cpp Adds mock-layer intercepts for the new graph native-handle APIs.
unified-runtime/source/adapters/level_zero/v2/graph.cpp Implements native handle retrieval for Level Zero v2 graphs/executable graphs.
unified-runtime/source/adapters/level_zero/ur_interface_loader.hpp Declares Level Zero adapter entry points for the new APIs.
unified-runtime/source/adapters/level_zero/ur_interface_loader.cpp Wires Level Zero adapter function pointers for the new APIs.
unified-runtime/source/adapters/level_zero/graph.cpp Adds Level Zero (non-v2) stubs returning unsupported for the new APIs.
unified-runtime/source/adapters/hip/ur_interface_loader.cpp Wires HIP adapter function pointers for the new APIs.
unified-runtime/source/adapters/hip/graph.cpp Adds HIP stubs returning unsupported for the new APIs.
unified-runtime/source/adapters/cuda/ur_interface_loader.cpp Wires CUDA adapter function pointers for the new APIs.
unified-runtime/source/adapters/cuda/graph.cpp Adds CUDA stubs returning unsupported for the new APIs.
unified-runtime/scripts/templates/mockddi.cpp.mako Generalizes mock native-handle generation for output/input parameter naming.
unified-runtime/scripts/core/registry.yml Adds new ur_function_t enumerators for tracing/callback identification.
unified-runtime/scripts/core/exp-graph.yml Defines the new experimental Graph API functions for code generation.
unified-runtime/include/unified-runtime/ur_print.hpp Adds enum printing + params-struct printing for the new APIs.
unified-runtime/include/unified-runtime/ur_print.h Declares new print helper functions for params structs.
unified-runtime/include/unified-runtime/ur_ddi.h Extends GraphExp DDI table with new function pointers.
unified-runtime/include/unified-runtime/ur_api.h Declares the new APIs, new ur_function_t enumerators, and callback params structs.
unified-runtime/include/unified-runtime/ur_api_funcs.def Registers the new APIs in the function list used for generation/export.

Comment on lines +9892 to +9899
ur_result_t UR_APICALL urGraphGetNativeHandleExp(
/// [in] Handle of the graph.
ur_exp_graph_handle_t hGraph,
/// [out] A pointer to the native handle of the graph.
ur_native_handle_t *phNativeGraph) {
ur_result_t result = UR_RESULT_SUCCESS;
return result;
}
Comment on lines +9919 to +9926
ur_result_t UR_APICALL urExecutableGraphGetNativeHandleExp(
/// [in] Handle of the executable graph.
ur_exp_executable_graph_handle_t hExecutableGraph,
/// [out] A pointer to the native handle of the executable graph.
ur_native_handle_t *phNativeExecutableGraph) {
ur_result_t result = UR_RESULT_SUCCESS;
return result;
}
Comment on lines +13917 to +13945
UR_APIEXPORT ur_result_t UR_APICALL urGraphGetNativeHandleExp(
/// [in] Handle of the graph.
ur_exp_graph_handle_t hGraph,
/// [out] A pointer to the native handle of the graph.
ur_native_handle_t *phNativeGraph);

///////////////////////////////////////////////////////////////////////////////
/// @brief Return platform native executable graph handle.
///
/// @details
/// - Retrieved native handle can be used for direct interaction with the
/// native platform driver.
///
/// @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 == hExecutableGraph`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phNativeExecutableGraph`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
UR_APIEXPORT ur_result_t UR_APICALL urExecutableGraphGetNativeHandleExp(
/// [in] Handle of the executable graph.
ur_exp_executable_graph_handle_t hExecutableGraph,
/// [out] A pointer to the native handle of the executable graph.
ur_native_handle_t *phNativeExecutableGraph);
Co-authored-by: Cursor <cursoragent@cursor.com>
@KFilipek KFilipek force-pushed the 09-native_graph_api branch from 23587ef to 6713213 Compare May 22, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants