diff --git a/unified-runtime/include/unified-runtime/ur_api.h b/unified-runtime/include/unified-runtime/ur_api.h index ce889941d39c6..8aadc23285552 100644 --- a/unified-runtime/include/unified-runtime/ur_api.h +++ b/unified-runtime/include/unified-runtime/ur_api.h @@ -510,6 +510,10 @@ typedef enum ur_function_t { UR_FUNCTION_USM_HOST_ALLOC_UNREGISTER_EXP = 313, /// Enumerator for ::urQueueGetGraphExp UR_FUNCTION_QUEUE_GET_GRAPH_EXP = 314, + /// Enumerator for ::urGraphGetNativeHandleExp + UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP = 315, + /// Enumerator for ::urExecutableGraphGetNativeHandleExp + UR_FUNCTION_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP = 316, /// @cond UR_FUNCTION_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -13892,6 +13896,54 @@ UR_APIEXPORT ur_result_t UR_APICALL urGraphDumpContentsExp( /// [in] Path to the file to write the dumped graph contents. const char *filePath); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Return platform native 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 == hGraph` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phNativeGraph` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE +/// + If the adapter has no underlying equivalent handle. +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); + #if !defined(__GNUC__) #pragma endregion #endif @@ -16423,6 +16475,24 @@ typedef struct ur_graph_dump_contents_exp_params_t { const char **pfilePath; } ur_graph_dump_contents_exp_params_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urGraphGetNativeHandleExp +/// @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_graph_get_native_handle_exp_params_t { + ur_exp_graph_handle_t *phGraph; + ur_native_handle_t **pphNativeGraph; +} ur_graph_get_native_handle_exp_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urExecutableGraphGetNativeHandleExp +/// @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_executable_graph_get_native_handle_exp_params_t { + ur_exp_executable_graph_handle_t *phExecutableGraph; + ur_native_handle_t **pphNativeExecutableGraph; +} ur_executable_graph_get_native_handle_exp_params_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urIPCGetMemHandleExp /// @details Each entry is a pointer to the parameter passed to the function; diff --git a/unified-runtime/include/unified-runtime/ur_api_funcs.def b/unified-runtime/include/unified-runtime/ur_api_funcs.def index c73c88213600f..4f2a6dc3fddb5 100644 --- a/unified-runtime/include/unified-runtime/ur_api_funcs.def +++ b/unified-runtime/include/unified-runtime/ur_api_funcs.def @@ -218,6 +218,8 @@ _UR_API(urGraphDestroyExp) _UR_API(urGraphExecutableGraphDestroyExp) _UR_API(urGraphIsEmptyExp) _UR_API(urGraphDumpContentsExp) +_UR_API(urGraphGetNativeHandleExp) +_UR_API(urExecutableGraphGetNativeHandleExp) _UR_API(urIPCGetMemHandleExp) _UR_API(urIPCPutMemHandleExp) _UR_API(urIPCOpenMemHandleExp) diff --git a/unified-runtime/include/unified-runtime/ur_ddi.h b/unified-runtime/include/unified-runtime/ur_ddi.h index 2fda5130c0ed8..d602118aa1703 100644 --- a/unified-runtime/include/unified-runtime/ur_ddi.h +++ b/unified-runtime/include/unified-runtime/ur_ddi.h @@ -1892,6 +1892,11 @@ typedef ur_result_t(UR_APICALL *ur_pfnGraphIsEmptyExp_t)(ur_exp_graph_handle_t, typedef ur_result_t(UR_APICALL *ur_pfnGraphDumpContentsExp_t)( ur_exp_graph_handle_t, const char *); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urGraphGetNativeHandleExp +typedef ur_result_t(UR_APICALL *ur_pfnGraphGetNativeHandleExp_t)( + ur_exp_graph_handle_t, ur_native_handle_t *); + /////////////////////////////////////////////////////////////////////////////// /// @brief Table of GraphExp functions pointers typedef struct ur_graph_exp_dditable_t { @@ -1901,6 +1906,7 @@ typedef struct ur_graph_exp_dditable_t { ur_pfnGraphExecutableGraphDestroyExp_t pfnExecutableGraphDestroyExp; ur_pfnGraphIsEmptyExp_t pfnIsEmptyExp; ur_pfnGraphDumpContentsExp_t pfnDumpContentsExp; + ur_pfnGraphGetNativeHandleExp_t pfnGetNativeHandleExp; } ur_graph_exp_dditable_t; /////////////////////////////////////////////////////////////////////////////// @@ -1923,6 +1929,37 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( typedef ur_result_t(UR_APICALL *ur_pfnGetGraphExpProcAddrTable_t)( ur_api_version_t, ur_graph_exp_dditable_t *); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urExecutableGraphGetNativeHandleExp +typedef ur_result_t(UR_APICALL *ur_pfnExecutableGraphGetNativeHandleExp_t)( + ur_exp_executable_graph_handle_t, ur_native_handle_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Table of ExecutableGraphExp functions pointers +typedef struct ur_executable_graph_exp_dditable_t { + ur_pfnExecutableGraphGetNativeHandleExp_t pfnGetNativeHandleExp; +} ur_executable_graph_exp_dditable_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's ExecutableGraphExp table +/// with current process' addresses +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION +UR_DLLEXPORT ur_result_t UR_APICALL urGetExecutableGraphExpProcAddrTable( + /// [in] API version requested + ur_api_version_t version, + /// [in,out] pointer to table of DDI function pointers + ur_executable_graph_exp_dditable_t *pDdiTable); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urGetExecutableGraphExpProcAddrTable +typedef ur_result_t(UR_APICALL *ur_pfnGetExecutableGraphExpProcAddrTable_t)( + ur_api_version_t, ur_executable_graph_exp_dditable_t *); + /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urIPCGetMemHandleExp typedef ur_result_t(UR_APICALL *ur_pfnIPCGetMemHandleExp_t)(ur_context_handle_t, @@ -2267,6 +2304,7 @@ typedef struct ur_dditable_t { ur_bindless_images_exp_dditable_t BindlessImagesExp; ur_command_buffer_exp_dditable_t CommandBufferExp; ur_graph_exp_dditable_t GraphExp; + ur_executable_graph_exp_dditable_t ExecutableGraphExp; ur_ipc_exp_dditable_t IPCExp; ur_memory_export_exp_dditable_t MemoryExportExp; ur_usm_p2p_exp_dditable_t UsmP2PExp; diff --git a/unified-runtime/include/unified-runtime/ur_print.h b/unified-runtime/include/unified-runtime/ur_print.h index f309275767a0f..4ace0c54ccff3 100644 --- a/unified-runtime/include/unified-runtime/ur_print.h +++ b/unified-runtime/include/unified-runtime/ur_print.h @@ -3735,6 +3735,27 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintGraphDumpContentsExpParams( const struct ur_graph_dump_contents_exp_params_t *params, char *buffer, const size_t buff_size, size_t *out_size); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_graph_get_native_handle_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintGraphGetNativeHandleExpParams( + const struct ur_graph_get_native_handle_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_executable_graph_get_native_handle_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL +urPrintExecutableGraphGetNativeHandleExpParams( + const struct ur_executable_graph_get_native_handle_exp_params_t *params, + char *buffer, const size_t buff_size, size_t *out_size); + /////////////////////////////////////////////////////////////////////////////// /// @brief Print ur_ipc_get_mem_handle_exp_params_t struct /// @returns diff --git a/unified-runtime/include/unified-runtime/ur_print.hpp b/unified-runtime/include/unified-runtime/ur_print.hpp index fba0340dea515..d3e69187ed3c5 100644 --- a/unified-runtime/include/unified-runtime/ur_print.hpp +++ b/unified-runtime/include/unified-runtime/ur_print.hpp @@ -1377,6 +1377,12 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { case UR_FUNCTION_QUEUE_GET_GRAPH_EXP: os << "UR_FUNCTION_QUEUE_GET_GRAPH_EXP"; break; + case UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP: + os << "UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP"; + break; + case UR_FUNCTION_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP: + os << "UR_FUNCTION_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP"; + break; default: os << "unknown enumerator"; break; @@ -21588,6 +21594,48 @@ inline std::ostream &operator<<( return os; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_graph_get_native_handle_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream & +operator<<(std::ostream &os, + [[maybe_unused]] const struct ur_graph_get_native_handle_exp_params_t + *params) { + + os << ".hGraph = "; + + ur::details::printPtr(os, *(params->phGraph)); + + os << ", "; + os << ".phNativeGraph = "; + + ur::details::printPtr(os, *(params->pphNativeGraph)); + + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the +/// ur_executable_graph_get_native_handle_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream & +operator<<(std::ostream &os, [[maybe_unused]] const struct + ur_executable_graph_get_native_handle_exp_params_t *params) { + + os << ".hExecutableGraph = "; + + ur::details::printPtr(os, *(params->phExecutableGraph)); + + os << ", "; + os << ".phNativeExecutableGraph = "; + + ur::details::printPtr(os, *(params->pphNativeExecutableGraph)); + + return os; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Print operator for the ur_ipc_get_mem_handle_exp_params_t type /// @returns @@ -23235,6 +23283,13 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, case UR_FUNCTION_GRAPH_DUMP_CONTENTS_EXP: { os << (const struct ur_graph_dump_contents_exp_params_t *)params; } break; + case UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP: { + os << (const struct ur_graph_get_native_handle_exp_params_t *)params; + } break; + case UR_FUNCTION_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP: { + os << (const struct ur_executable_graph_get_native_handle_exp_params_t *) + params; + } break; case UR_FUNCTION_IPC_GET_MEM_HANDLE_EXP: { os << (const struct ur_ipc_get_mem_handle_exp_params_t *)params; } break; diff --git a/unified-runtime/scripts/core/exp-graph.yml b/unified-runtime/scripts/core/exp-graph.yml index c01465825b6c0..75a5e0e209df3 100644 --- a/unified-runtime/scripts/core/exp-graph.yml +++ b/unified-runtime/scripts/core/exp-graph.yml @@ -198,3 +198,41 @@ params: - type: const char* name: filePath desc: "[in] Path to the file to write the dumped graph contents." +--- #-------------------------------------------------------------------------- +type: function +desc: "Return platform native graph handle." +class: $xGraph +name: GetNativeHandleExp +details: + - "Retrieved native handle can be used for direct interaction with the native platform driver." +params: + - type: "$x_exp_graph_handle_t" + name: hGraph + desc: | + [in] Handle of the graph. + - type: $x_native_handle_t* + name: phNativeGraph + desc: | + [out] A pointer to the native handle of the graph. +returns: + - $X_RESULT_ERROR_UNSUPPORTED_FEATURE: + - "If the adapter has no underlying equivalent handle." +--- #-------------------------------------------------------------------------- +type: function +desc: "Return platform native executable graph handle." +class: $xExecutableGraph +name: GetNativeHandleExp +details: + - "Retrieved native handle can be used for direct interaction with the native platform driver." +params: + - type: "$x_exp_executable_graph_handle_t" + name: hExecutableGraph + desc: | + [in] Handle of the executable graph. + - type: $x_native_handle_t* + name: phNativeExecutableGraph + desc: | + [out] A pointer to the native handle of the executable graph. +returns: + - $X_RESULT_ERROR_UNSUPPORTED_FEATURE: + - "If the adapter has no underlying equivalent handle." diff --git a/unified-runtime/scripts/core/registry.yml b/unified-runtime/scripts/core/registry.yml index 6c039b80e41d9..2a4d853a001e9 100644 --- a/unified-runtime/scripts/core/registry.yml +++ b/unified-runtime/scripts/core/registry.yml @@ -724,7 +724,13 @@ etors: - name: QUEUE_GET_GRAPH_EXP desc: Enumerator for $xQueueGetGraphExp value: '314' -max_id: '314' +- name: GRAPH_GET_NATIVE_HANDLE_EXP + desc: Enumerator for $xGraphGetNativeHandleExp + value: '315' +- name: EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP + desc: Enumerator for $xExecutableGraphGetNativeHandleExp + value: '316' +max_id: '316' --- type: enum desc: Defines structure types diff --git a/unified-runtime/source/adapters/cuda/graph.cpp b/unified-runtime/source/adapters/cuda/graph.cpp index f7526b4d0a590..7d4eca8d4258e 100644 --- a/unified-runtime/source/adapters/cuda/graph.cpp +++ b/unified-runtime/source/adapters/cuda/graph.cpp @@ -39,3 +39,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urGraphInstantiateGraphExp( ur_exp_executable_graph_handle_t * /* phExecutableGraph */) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } + +UR_APIEXPORT ur_result_t UR_APICALL +urGraphGetNativeHandleExp(ur_exp_graph_handle_t /* hGraph */, + ur_native_handle_t * /* phNativeGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t /* hExecutableGraph */, + ur_native_handle_t * /* phNativeExecutableGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/unified-runtime/source/adapters/cuda/ur_interface_loader.cpp b/unified-runtime/source/adapters/cuda/ur_interface_loader.cpp index cfff918f90302..33ee40c13835b 100644 --- a/unified-runtime/source/adapters/cuda/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/cuda/ur_interface_loader.cpp @@ -90,6 +90,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( pDdiTable->pfnExecutableGraphDestroyExp = urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + urGraphExecutableGraphGetNativeHandleExp; return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/hip/graph.cpp b/unified-runtime/source/adapters/hip/graph.cpp index 48f9271ce8726..dbbfd0fb54ac3 100644 --- a/unified-runtime/source/adapters/hip/graph.cpp +++ b/unified-runtime/source/adapters/hip/graph.cpp @@ -39,3 +39,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urGraphInstantiateGraphExp( ur_exp_executable_graph_handle_t * /* phExecutableGraph */) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } + +UR_APIEXPORT ur_result_t UR_APICALL +urGraphGetNativeHandleExp(ur_exp_graph_handle_t /* hGraph */, + ur_native_handle_t * /* phNativeGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t /* hExecutableGraph */, + ur_native_handle_t * /* phNativeExecutableGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/unified-runtime/source/adapters/hip/ur_interface_loader.cpp b/unified-runtime/source/adapters/hip/ur_interface_loader.cpp index 8152546927bf5..007838a35d4ed 100644 --- a/unified-runtime/source/adapters/hip/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/hip/ur_interface_loader.cpp @@ -90,6 +90,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( pDdiTable->pfnExecutableGraphDestroyExp = urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + urGraphExecutableGraphGetNativeHandleExp; return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/level_zero/graph.cpp b/unified-runtime/source/adapters/level_zero/graph.cpp index 58b010549b26e..19faf917e92f4 100644 --- a/unified-runtime/source/adapters/level_zero/graph.cpp +++ b/unified-runtime/source/adapters/level_zero/graph.cpp @@ -61,4 +61,22 @@ ur_result_t urGraphInstantiateGraphExp( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } +ur_result_t +urGraphGetNativeHandleExp(ur_exp_graph_handle_t /* hGraph */, + ur_native_handle_t * /* phNativeGraph */) { + UR_LOG_LEGACY(ERR, + logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t /* hExecutableGraph */, + ur_native_handle_t * /* phNativeExecutableGraph */) { + UR_LOG_LEGACY(ERR, + logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + } // namespace ur::level_zero diff --git a/unified-runtime/source/adapters/level_zero/ur_interface_loader.cpp b/unified-runtime/source/adapters/level_zero/ur_interface_loader.cpp index 877a4d199c44a..2e74045b67aec 100644 --- a/unified-runtime/source/adapters/level_zero/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/level_zero/ur_interface_loader.cpp @@ -276,6 +276,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( ur::level_zero::urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = ur::level_zero::urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = ur::level_zero::urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = ur::level_zero::urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + ur::level_zero::urGraphExecutableGraphGetNativeHandleExp; return result; } diff --git a/unified-runtime/source/adapters/level_zero/ur_interface_loader.hpp b/unified-runtime/source/adapters/level_zero/ur_interface_loader.hpp index a4a9e9819a95e..924ede83d9f4c 100644 --- a/unified-runtime/source/adapters/level_zero/ur_interface_loader.hpp +++ b/unified-runtime/source/adapters/level_zero/ur_interface_loader.hpp @@ -867,6 +867,11 @@ ur_result_t urQueueGetGraphExp(ur_queue_handle_t hQueue, ur_result_t urGraphIsEmptyExp(ur_exp_graph_handle_t hGraph, bool *pResult); ur_result_t urGraphDumpContentsExp(ur_exp_graph_handle_t hGraph, const char *filePath); +ur_result_t urGraphGetNativeHandleExp(ur_exp_graph_handle_t hGraph, + ur_native_handle_t *phNativeGraph); +ur_result_t urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t hExecutableGraph, + ur_native_handle_t *phNativeExecutableGraph); #ifdef UR_STATIC_ADAPTER_LEVEL_ZERO ur_result_t urAdapterGetDdiTables(ur_dditable_t *ddi); #endif diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.cpp b/unified-runtime/source/adapters/level_zero/v2/graph.cpp index f05da04ccd3b0..f94207ad6c3db 100644 --- a/unified-runtime/source/adapters/level_zero/v2/graph.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/graph.cpp @@ -142,4 +142,30 @@ ur_result_t urGraphDumpContentsExp(ur_exp_graph_handle_t hGraph, return UR_RESULT_SUCCESS; } +ur_result_t urGraphGetNativeHandleExp(ur_exp_graph_handle_t hGraph, + ur_native_handle_t *phNativeGraph) try { + ur_context_handle_t hContext = hGraph->getContext(); + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + *phNativeGraph = reinterpret_cast(hGraph->getZeHandle()); + return UR_RESULT_SUCCESS; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +ur_result_t urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t hExecutableGraph, + ur_native_handle_t *phNativeExecutableGraph) try { + ur_context_handle_t hContext = hExecutableGraph->getContext(); + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + *phNativeExecutableGraph = + reinterpret_cast(hExecutableGraph->getZeHandle()); + return UR_RESULT_SUCCESS; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + } // namespace ur::level_zero diff --git a/unified-runtime/source/adapters/mock/ur_mockddi.cpp b/unified-runtime/source/adapters/mock/ur_mockddi.cpp index 00145e81d7afc..685e1c17a38c0 100644 --- a/unified-runtime/source/adapters/mock/ur_mockddi.cpp +++ b/unified-runtime/source/adapters/mock/ur_mockddi.cpp @@ -12995,6 +12995,101 @@ __urdlllocal ur_result_t UR_APICALL urGraphDumpContentsExp( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphGetNativeHandleExp +__urdlllocal 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) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_graph_get_native_handle_exp_params_t params = {&hGraph, &phNativeGraph}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback("urGraphGetNativeHandleExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback("urGraphGetNativeHandleExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + *phNativeGraph = reinterpret_cast(hGraph); + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback("urGraphGetNativeHandleExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphExecutableGraphGetNativeHandleExp +__urdlllocal ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + /// [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) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_graph_executable_graph_get_native_handle_exp_params_t params = { + &hExecutableGraph, &phNativeExecutableGraph}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback( + "urGraphExecutableGraphGetNativeHandleExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback( + "urGraphExecutableGraphGetNativeHandleExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + *phNativeExecutableGraph = + reinterpret_cast(hExecutableGraph); + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback( + "urGraphExecutableGraphGetNativeHandleExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + } // namespace driver extern "C" { @@ -13458,6 +13553,11 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( pDdiTable->pfnDumpContentsExp = driver::urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = driver::urGraphGetNativeHandleExp; + + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + driver::urGraphExecutableGraphGetNativeHandleExp; + return result; } catch (...) { return exceptionToResult(std::current_exception()); diff --git a/unified-runtime/source/adapters/native_cpu/graph.cpp b/unified-runtime/source/adapters/native_cpu/graph.cpp index 9135921bb567c..1bce83048b05b 100644 --- a/unified-runtime/source/adapters/native_cpu/graph.cpp +++ b/unified-runtime/source/adapters/native_cpu/graph.cpp @@ -45,3 +45,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urGraphInstantiateGraphExp( DIE_NO_IMPLEMENTATION; } + +UR_APIEXPORT ur_result_t UR_APICALL +urGraphGetNativeHandleExp(ur_exp_graph_handle_t /* hGraph */, + ur_native_handle_t * /* phNativeGraph */) { + + DIE_NO_IMPLEMENTATION; +} + +UR_APIEXPORT ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t /* hExecutableGraph */, + ur_native_handle_t * /* phNativeExecutableGraph */) { + + DIE_NO_IMPLEMENTATION; +} diff --git a/unified-runtime/source/adapters/native_cpu/ur_interface_loader.cpp b/unified-runtime/source/adapters/native_cpu/ur_interface_loader.cpp index bc1183e1c9ce4..8400f7cf34e3d 100644 --- a/unified-runtime/source/adapters/native_cpu/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/native_cpu/ur_interface_loader.cpp @@ -90,6 +90,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( pDdiTable->pfnExecutableGraphDestroyExp = urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + urGraphExecutableGraphGetNativeHandleExp; return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/offload/graph.cpp b/unified-runtime/source/adapters/offload/graph.cpp index a1346eed7cba2..5428f1ce8066e 100644 --- a/unified-runtime/source/adapters/offload/graph.cpp +++ b/unified-runtime/source/adapters/offload/graph.cpp @@ -39,3 +39,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urGraphInstantiateGraphExp( ur_exp_executable_graph_handle_t * /* phExecutableGraph */) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } + +UR_APIEXPORT ur_result_t UR_APICALL +urGraphGetNativeHandleExp(ur_exp_graph_handle_t /* hGraph */, + ur_native_handle_t * /* phNativeGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t /* hExecutableGraph */, + ur_native_handle_t * /* phNativeExecutableGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/unified-runtime/source/adapters/offload/ur_interface_loader.cpp b/unified-runtime/source/adapters/offload/ur_interface_loader.cpp index 69d9aafaf4a69..c9ed4f44d9da1 100644 --- a/unified-runtime/source/adapters/offload/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/offload/ur_interface_loader.cpp @@ -90,6 +90,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( pDdiTable->pfnExecutableGraphDestroyExp = urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + urGraphExecutableGraphGetNativeHandleExp; return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/opencl/graph.cpp b/unified-runtime/source/adapters/opencl/graph.cpp index 158dbb9617c47..a1d7e12a1ba5c 100644 --- a/unified-runtime/source/adapters/opencl/graph.cpp +++ b/unified-runtime/source/adapters/opencl/graph.cpp @@ -39,3 +39,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urGraphInstantiateGraphExp( ur_exp_executable_graph_handle_t * /* phExecutableGraph */) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } + +UR_APIEXPORT ur_result_t UR_APICALL +urGraphGetNativeHandleExp(ur_exp_graph_handle_t /* hGraph */, + ur_native_handle_t * /* phNativeGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + ur_exp_executable_graph_handle_t /* hExecutableGraph */, + ur_native_handle_t * /* phNativeExecutableGraph */) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/unified-runtime/source/adapters/opencl/ur_interface_loader.cpp b/unified-runtime/source/adapters/opencl/ur_interface_loader.cpp index 8e1c9ee94b8c3..b3f54f66b3862 100644 --- a/unified-runtime/source/adapters/opencl/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/opencl/ur_interface_loader.cpp @@ -505,6 +505,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( pDdiTable->pfnExecutableGraphDestroyExp = urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + urGraphExecutableGraphGetNativeHandleExp; return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/loader/layers/tracing/ur_trcddi.cpp b/unified-runtime/source/loader/layers/tracing/ur_trcddi.cpp index 6d6ac7919f4d8..bd5073e400a24 100644 --- a/unified-runtime/source/loader/layers/tracing/ur_trcddi.cpp +++ b/unified-runtime/source/loader/layers/tracing/ur_trcddi.cpp @@ -11019,6 +11019,86 @@ __urdlllocal ur_result_t UR_APICALL urGraphDumpContentsExp( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphGetNativeHandleExp +__urdlllocal 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) { + auto pfnGetNativeHandleExp = + getContext()->urDdiTable.GraphExp.pfnGetNativeHandleExp; + + if (nullptr == pfnGetNativeHandleExp) + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ur_graph_get_native_handle_exp_params_t params = {&hGraph, &phNativeGraph}; + uint64_t instance = + getContext()->notify_begin(UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP, + "urGraphGetNativeHandleExp", ¶ms); + + auto &logger = getContext()->logger; + UR_LOG_L(logger, INFO, " ---> urGraphGetNativeHandleExp\n"); + + ur_result_t result = pfnGetNativeHandleExp(hGraph, phNativeGraph); + + getContext()->notify_end(UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP, + "urGraphGetNativeHandleExp", ¶ms, &result, + instance); + + if (logger.getLevel() <= UR_LOGGER_LEVEL_INFO) { + std::ostringstream args_str; + ur::extras::printFunctionParams( + args_str, UR_FUNCTION_GRAPH_GET_NATIVE_HANDLE_EXP, ¶ms); + UR_LOG_L(logger, INFO, " <--- urGraphGetNativeHandleExp({}) -> {};\n", + args_str.str(), result); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphExecutableGraphGetNativeHandleExp +__urdlllocal ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + /// [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) { + auto pfnExecutableGraphGetNativeHandleExp = + getContext()->urDdiTable.GraphExp.pfnExecutableGraphGetNativeHandleExp; + + if (nullptr == pfnExecutableGraphGetNativeHandleExp) + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ur_graph_executable_graph_get_native_handle_exp_params_t params = { + &hExecutableGraph, &phNativeExecutableGraph}; + uint64_t instance = getContext()->notify_begin( + UR_FUNCTION_GRAPH_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP, + "urGraphExecutableGraphGetNativeHandleExp", ¶ms); + + auto &logger = getContext()->logger; + UR_LOG_L(logger, INFO, " ---> urGraphExecutableGraphGetNativeHandleExp\n"); + + ur_result_t result = pfnExecutableGraphGetNativeHandleExp( + hExecutableGraph, phNativeExecutableGraph); + + getContext()->notify_end( + UR_FUNCTION_GRAPH_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP, + "urGraphExecutableGraphGetNativeHandleExp", ¶ms, &result, instance); + + if (logger.getLevel() <= UR_LOGGER_LEVEL_INFO) { + std::ostringstream args_str; + ur::extras::printFunctionParams( + args_str, UR_FUNCTION_GRAPH_EXECUTABLE_GRAPH_GET_NATIVE_HANDLE_EXP, + ¶ms); + UR_LOG_L(logger, INFO, + " <--- urGraphExecutableGraphGetNativeHandleExp({}) -> {};\n", + args_str.str(), result); + } + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Exported function for filling application's Adapter table /// with current process' addresses @@ -11641,6 +11721,15 @@ __urdlllocal ur_result_t UR_APICALL urGetGraphExpProcAddrTable( dditable.pfnDumpContentsExp = pDdiTable->pfnDumpContentsExp; pDdiTable->pfnDumpContentsExp = ur_tracing_layer::urGraphDumpContentsExp; + dditable.pfnGetNativeHandleExp = pDdiTable->pfnGetNativeHandleExp; + pDdiTable->pfnGetNativeHandleExp = + ur_tracing_layer::urGraphGetNativeHandleExp; + + dditable.pfnExecutableGraphGetNativeHandleExp = + pDdiTable->pfnExecutableGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + ur_tracing_layer::urGraphExecutableGraphGetNativeHandleExp; + return result; } /////////////////////////////////////////////////////////////////////////////// diff --git a/unified-runtime/source/loader/layers/validation/ur_valddi.cpp b/unified-runtime/source/loader/layers/validation/ur_valddi.cpp index 7b9a2f5b0982d..2af428ba597a7 100644 --- a/unified-runtime/source/loader/layers/validation/ur_valddi.cpp +++ b/unified-runtime/source/loader/layers/validation/ur_valddi.cpp @@ -11788,6 +11788,61 @@ __urdlllocal ur_result_t UR_APICALL urGraphDumpContentsExp( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphGetNativeHandleExp +__urdlllocal 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) { + auto pfnGetNativeHandleExp = + getContext()->urDdiTable.GraphExp.pfnGetNativeHandleExp; + + if (nullptr == pfnGetNativeHandleExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == phNativeGraph) + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + + if (NULL == hGraph) + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + ur_result_t result = pfnGetNativeHandleExp(hGraph, phNativeGraph); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphExecutableGraphGetNativeHandleExp +__urdlllocal ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + /// [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) { + auto pfnExecutableGraphGetNativeHandleExp = + getContext()->urDdiTable.GraphExp.pfnExecutableGraphGetNativeHandleExp; + + if (nullptr == pfnExecutableGraphGetNativeHandleExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == phNativeExecutableGraph) + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + + if (NULL == hExecutableGraph) + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + ur_result_t result = pfnExecutableGraphGetNativeHandleExp( + hExecutableGraph, phNativeExecutableGraph); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Exported function for filling application's Adapter table /// with current process' addresses @@ -12424,6 +12479,15 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( dditable.pfnDumpContentsExp = pDdiTable->pfnDumpContentsExp; pDdiTable->pfnDumpContentsExp = ur_validation_layer::urGraphDumpContentsExp; + dditable.pfnGetNativeHandleExp = pDdiTable->pfnGetNativeHandleExp; + pDdiTable->pfnGetNativeHandleExp = + ur_validation_layer::urGraphGetNativeHandleExp; + + dditable.pfnExecutableGraphGetNativeHandleExp = + pDdiTable->pfnExecutableGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + ur_validation_layer::urGraphExecutableGraphGetNativeHandleExp; + return result; } diff --git a/unified-runtime/source/loader/loader.def.in b/unified-runtime/source/loader/loader.def.in index 8faa938b745f0..0e4016885dab7 100644 --- a/unified-runtime/source/loader/loader.def.in +++ b/unified-runtime/source/loader/loader.def.in @@ -143,6 +143,8 @@ EXPORTS urGraphDestroyExp urGraphDumpContentsExp urGraphExecutableGraphDestroyExp + urGraphExecutableGraphGetNativeHandleExp + urGraphGetNativeHandleExp urGraphInstantiateGraphExp urGraphIsEmptyExp urIPCCloseMemHandleExp @@ -387,6 +389,8 @@ EXPORTS urPrintGraphDestroyExpParams urPrintGraphDumpContentsExpParams urPrintGraphExecutableGraphDestroyExpParams + urPrintGraphExecutableGraphGetNativeHandleExpParams + urPrintGraphGetNativeHandleExpParams urPrintGraphInstantiateGraphExpParams urPrintGraphIsEmptyExpParams urPrintImageChannelOrder diff --git a/unified-runtime/source/loader/loader.map.in b/unified-runtime/source/loader/loader.map.in index b7f9f3428a5f5..f52719cac2de3 100644 --- a/unified-runtime/source/loader/loader.map.in +++ b/unified-runtime/source/loader/loader.map.in @@ -143,6 +143,8 @@ urGraphDestroyExp; urGraphDumpContentsExp; urGraphExecutableGraphDestroyExp; + urGraphExecutableGraphGetNativeHandleExp; + urGraphGetNativeHandleExp; urGraphInstantiateGraphExp; urGraphIsEmptyExp; urIPCCloseMemHandleExp; @@ -387,6 +389,8 @@ urPrintGraphDestroyExpParams; urPrintGraphDumpContentsExpParams; urPrintGraphExecutableGraphDestroyExpParams; + urPrintGraphExecutableGraphGetNativeHandleExpParams; + urPrintGraphGetNativeHandleExpParams; urPrintGraphInstantiateGraphExpParams; urPrintGraphIsEmptyExpParams; urPrintImageChannelOrder; diff --git a/unified-runtime/source/loader/ur_ldrddi.cpp b/unified-runtime/source/loader/ur_ldrddi.cpp index 7ac726f9c9cb1..09b5f11bdb8e2 100644 --- a/unified-runtime/source/loader/ur_ldrddi.cpp +++ b/unified-runtime/source/loader/ur_ldrddi.cpp @@ -6245,6 +6245,44 @@ __urdlllocal ur_result_t UR_APICALL urGraphDumpContentsExp( return pfnDumpContentsExp(hGraph, filePath); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphGetNativeHandleExp +__urdlllocal 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) { + + auto *dditable = *reinterpret_cast(hGraph); + + auto *pfnGetNativeHandleExp = dditable->GraphExp.pfnGetNativeHandleExp; + if (nullptr == pfnGetNativeHandleExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + // forward to device-platform + return pfnGetNativeHandleExp(hGraph, phNativeGraph); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urGraphExecutableGraphGetNativeHandleExp +__urdlllocal ur_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + /// [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) { + + auto *dditable = *reinterpret_cast(hExecutableGraph); + + auto *pfnExecutableGraphGetNativeHandleExp = + dditable->GraphExp.pfnExecutableGraphGetNativeHandleExp; + if (nullptr == pfnExecutableGraphGetNativeHandleExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + // forward to device-platform + return pfnExecutableGraphGetNativeHandleExp(hExecutableGraph, + phNativeExecutableGraph); +} + } // namespace ur_loader extern "C" { @@ -6818,6 +6856,9 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGraphExpProcAddrTable( ur_loader::urGraphExecutableGraphDestroyExp; pDdiTable->pfnIsEmptyExp = ur_loader::urGraphIsEmptyExp; pDdiTable->pfnDumpContentsExp = ur_loader::urGraphDumpContentsExp; + pDdiTable->pfnGetNativeHandleExp = ur_loader::urGraphGetNativeHandleExp; + pDdiTable->pfnExecutableGraphGetNativeHandleExp = + ur_loader::urGraphExecutableGraphGetNativeHandleExp; } else { // return pointers directly to platform's DDIs *pDdiTable = ur_loader::getContext()->platforms.front().dditable.GraphExp; diff --git a/unified-runtime/source/loader/ur_libapi.cpp b/unified-runtime/source/loader/ur_libapi.cpp index 51f6ca8ee556f..bf43cc40d97f4 100644 --- a/unified-runtime/source/loader/ur_libapi.cpp +++ b/unified-runtime/source/loader/ur_libapi.cpp @@ -11373,4 +11373,72 @@ ur_result_t UR_APICALL urGraphDumpContentsExp( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Return platform native 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 == hGraph` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phNativeGraph` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE +/// + If the adapter has no underlying equivalent handle. +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) try { + auto pfnGetNativeHandleExp = + ur_lib::getContext()->urDdiTable.GraphExp.pfnGetNativeHandleExp; + if (nullptr == pfnGetNativeHandleExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + return pfnGetNativeHandleExp(hGraph, phNativeGraph); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @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_result_t UR_APICALL urGraphExecutableGraphGetNativeHandleExp( + /// [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) try { + auto pfnExecutableGraphGetNativeHandleExp = + ur_lib::getContext() + ->urDdiTable.GraphExp.pfnExecutableGraphGetNativeHandleExp; + if (nullptr == pfnExecutableGraphGetNativeHandleExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + return pfnExecutableGraphGetNativeHandleExp(hExecutableGraph, + phNativeExecutableGraph); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + } // extern "C" diff --git a/unified-runtime/source/loader/ur_print.cpp b/unified-runtime/source/loader/ur_print.cpp index f500efa52e864..4278ebb613d81 100644 --- a/unified-runtime/source/loader/ur_print.cpp +++ b/unified-runtime/source/loader/ur_print.cpp @@ -2163,6 +2163,23 @@ ur_result_t urPrintGraphDumpContentsExpParams( return str_copy(&ss, buffer, buff_size, out_size); } +ur_result_t urPrintGraphGetNativeHandleExpParams( + const struct ur_graph_get_native_handle_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + +ur_result_t urPrintGraphExecutableGraphGetNativeHandleExpParams( + const struct ur_graph_executable_graph_get_native_handle_exp_params_t + *params, + char *buffer, const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + ur_result_t urPrintIpcGetMemHandleExpParams( const struct ur_ipc_get_mem_handle_exp_params_t *params, char *buffer, const size_t buff_size, size_t *out_size) { diff --git a/unified-runtime/source/ur_api.cpp b/unified-runtime/source/ur_api.cpp index 81dcda1a4fcb6..ec434e5ee976c 100644 --- a/unified-runtime/source/ur_api.cpp +++ b/unified-runtime/source/ur_api.cpp @@ -9870,3 +9870,57 @@ ur_result_t UR_APICALL urGraphDumpContentsExp( ur_result_t result = UR_RESULT_SUCCESS; return result; } + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Return platform native 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 == hGraph` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phNativeGraph` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE +/// + If the adapter has no underlying equivalent handle. +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; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @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_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; +}