diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_graph_ext_wrappers.cpp index 240895c91df6a3..bc504176121899 100644 --- a/src/plugins/intel_npu/src/utils/src/zero/zero_graph_ext_wrappers.cpp +++ b/src/plugins/intel_npu/src/utils/src/zero/zero_graph_ext_wrappers.cpp @@ -85,14 +85,25 @@ namespace intel_npu { ZeGraphExtWrappers::ZeGraphExtWrappers(const std::shared_ptr& zeroInitStruct) : _zeroInitStruct(zeroInitStruct), _graphExtVersion(zeroInitStruct->getGraphDdiTable().version()), - _logger("ZeGraphExtWrappers", Logger::global().level()) {} + _logger("ZeGraphExtWrappers", Logger::global().level()) { + _logger.info("Graph ext version used by zero wrapper: %d.%d", + ZE_MAJOR_VERSION(_graphExtVersion), + ZE_MINOR_VERSION(_graphExtVersion)); + _logger.debug("capabilities:"); + _logger.debug("-SupportQuery: %d", !NotSupportQuery(_graphExtVersion)); + _logger.debug("-SupportAPIGraphQueryNetworkV1: %d", SupportAPIGraphQueryNetworkV1(_graphExtVersion)); + _logger.debug("-SupportAPIGraphQueryNetworkV2 :%d", SupportAPIGraphQueryNetworkV2(_graphExtVersion)); + _logger.debug("-SupportpfnCreate2 :%d", !NotSupportGraph2(_graphExtVersion)); + _logger.debug("-SupportArgumentMetadata :%d", !NotSupportArgumentMetadata(_graphExtVersion)); + _logger.debug("-UseCopyForNativeBinary :%d", UseCopyForNativeBinary(_graphExtVersion)); +} ZeGraphExtWrappers::~ZeGraphExtWrappers() { - _logger.debug("ZeGraphExtWrappers obj destroyed"); + _logger.debug("Obj destroyed"); } _ze_result_t ZeGraphExtWrappers::destroyGraph(ze_graph_handle_t graphHandle) { - _logger.debug("destroyGraph - pfnDestroy graphHandle"); + _logger.debug("destroyGraph - perfrom pfnDestroy"); auto result = _zeroInitStruct->getGraphDdiTable().pfnDestroy(graphHandle); if (ZE_RESULT_SUCCESS != result) { @@ -112,10 +123,11 @@ void ZeGraphExtWrappers::getGraphBinary(ze_graph_handle_t graphHandle, OPENVINO_THROW("Graph handle is null"); } - _logger.info("ZeGraphExtWrappers getGraphBinary get blob from graphHandle"); + _logger.debug("getGraphBinary - get blob from graphHandle"); if (UseCopyForNativeBinary(_graphExtVersion)) { // Get blob size first + _logger.debug("getGraphBinary - perfrom pfnGetNativeBinary to get size"); auto result = _zeroInitStruct->getGraphDdiTable().pfnGetNativeBinary(graphHandle, &blobSize, nullptr); blob.resize(blobSize); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetNativeBinary get blob size, Failed to compile network.", @@ -123,6 +135,7 @@ void ZeGraphExtWrappers::getGraphBinary(ze_graph_handle_t graphHandle, _zeroInitStruct->getGraphDdiTable()); // Get blob data + _logger.debug("getGraphBinary - perfrom pfnGetNativeBinary to get data"); result = _zeroInitStruct->getGraphDdiTable().pfnGetNativeBinary(graphHandle, &blobSize, blob.data()); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetNativeBinary get blob data, Failed to compile network.", result, @@ -131,6 +144,7 @@ void ZeGraphExtWrappers::getGraphBinary(ze_graph_handle_t graphHandle, blobPtr = blob.data(); } else { // Get blob ptr and size + _logger.debug("getGraphBinary - perfrom pfnGetNativeBinary2 to get size and data"); auto result = _zeroInitStruct->getGraphDdiTable().pfnGetNativeBinary2(graphHandle, &blobSize, &blobPtr); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetNativeBinary get blob size, Failed to compile network.", result, @@ -139,19 +153,24 @@ void ZeGraphExtWrappers::getGraphBinary(ze_graph_handle_t graphHandle, } void ZeGraphExtWrappers::setGraphArgumentValue(ze_graph_handle_t graphHandle, uint32_t argi, const void* argv) const { + _logger.debug("setGraphArgumentValue - perform pfnSetArgumentValue"); auto result = _zeroInitStruct->getGraphDdiTable().pfnSetArgumentValue(graphHandle, argi, argv); THROW_ON_FAIL_FOR_LEVELZERO_EXT("zeGraphSetArgumentValue", result, _zeroInitStruct->getGraphDdiTable()); } void ZeGraphExtWrappers::initializeGraph(ze_graph_handle_t graphHandle, const Config& config) const { if (_zeroInitStruct->getGraphDdiTable().version() < ZE_GRAPH_EXT_VERSION_1_8) { + _logger.debug("Use initialize_graph_through_command_list for ext version smaller than 1.8"); initialize_graph_through_command_list(graphHandle, config); } else { + _logger.debug("Initialize graph based on graph properties for ext version larger than 1.8"); ze_graph_properties_2_t properties = {}; properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; + _logger.debug("initializeGraph - perfrom pfnGetProperties2"); _zeroInitStruct->getGraphDdiTable().pfnGetProperties2(graphHandle, &properties); if (properties.initStageRequired & ZE_GRAPH_STAGE_INITIALIZE) { + _logger.debug("initializeGraph - perfrom pfnGraphInitialize"); _zeroInitStruct->getGraphDdiTable().pfnGraphInitialize(graphHandle); } @@ -169,23 +188,23 @@ void ZeGraphExtWrappers::initialize_graph_through_command_list(ze_graph_handle_t zeDeviceGetProperties(_zeroInitStruct->getDevice(), &deviceProperties)); auto groupOrdinal = zeroUtils::findGroupOrdinal(_zeroInitStruct->getDevice(), deviceProperties); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list init start - create graph_command_list"); + _logger.debug("initialize_graph_through_command_list init start - create graph_command_list"); CommandList graph_command_list(_zeroInitStruct, groupOrdinal); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - create graph_command_queue"); + _logger.debug("initialize_graph_through_command_list - create graph_command_queue"); CommandQueue graph_command_queue(_zeroInitStruct, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, groupOrdinal, false); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - create fence"); + _logger.debug("initialize_graph_through_command_list - create fence"); Fence fence(graph_command_queue); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - performing appendGraphInitialize"); + _logger.debug("initialize_graph_through_command_list - performing appendGraphInitialize"); graph_command_list.appendGraphInitialize(graphHandle); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - closing graph command list"); + _logger.debug("initialize_graph_through_command_list - closing graph command list"); graph_command_list.close(); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - performing executeCommandList"); + _logger.debug("initialize_graph_through_command_list - performing executeCommandList"); graph_command_queue.executeCommandList(graph_command_list, fence); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - performing hostSynchronize"); + _logger.debug("initialize_graph_through_command_list - performing hostSynchronize"); fence.hostSynchronize(); - _logger.debug("ZeGraphExtWrappers::initialize_graph_through_command_list - hostSynchronize completed"); + _logger.debug("initialize_graph_through_command_list - hostSynchronize completed"); } // Parse the result string of query from foramt to unordered_set of string @@ -217,6 +236,7 @@ std::unordered_set ZeGraphExtWrappers::getQueryResultFromSupportedL ZE_MINOR_VERSION(_graphExtVersion)); } // Get the size of query result + _logger.debug("getQueryResultFromSupportLayers - perfrom pfnQueryNetworkGetSupportedLayers to get size"); size_t size = 0; result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkGetSupportedLayers(hGraphQueryNetwork, &size, nullptr); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryNetworkGetSupportedLayers get size of query result", @@ -224,6 +244,7 @@ std::unordered_set ZeGraphExtWrappers::getQueryResultFromSupportedL _zeroInitStruct->getGraphDdiTable()); // Get the result data of query + _logger.debug("getQueryResultFromSupportLayers - perfrom pfnQueryNetworkGetSupportedLayers to get data"); std::vector supportedLayers(size); result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkGetSupportedLayers(hGraphQueryNetwork, &size, @@ -232,6 +253,7 @@ std::unordered_set ZeGraphExtWrappers::getQueryResultFromSupportedL result, _zeroInitStruct->getGraphDdiTable()); + _logger.debug("getQueryResultFromSupportLayers - perfrom pfnQueryNetworkDestroy"); result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkDestroy(hGraphQueryNetwork); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryNetworkDestroy", result, _zeroInitStruct->getGraphDdiTable()); @@ -255,22 +277,20 @@ std::unordered_set ZeGraphExtWrappers::queryGraph(std::pairgetGraphDdiTable().pfnQueryNetworkCreate(_zeroInitStruct->getContext(), - _zeroInitStruct->getDevice(), - &desc, - &hGraphQueryNetwork); - THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryNetworkCreate", result, _zeroInitStruct->getGraphDdiTable()); - } + ze_graph_desc_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES, + nullptr, + ZE_GRAPH_FORMAT_NGRAPH_LITE, + serializedIR.first, + serializedIR.second.get(), + buildFlags.c_str()}; + + // Create querynetwork handle + _logger.debug("For ext of 1.3 and 1.4 - perform pfnQueryNetworkCreate"); + result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkCreate(_zeroInitStruct->getContext(), + _zeroInitStruct->getDevice(), + &desc, + &hGraphQueryNetwork); + THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryNetworkCreate", result, _zeroInitStruct->getGraphDdiTable()); return getQueryResultFromSupportedLayers(result, hGraphQueryNetwork); } else if (SupportAPIGraphQueryNetworkV2(_graphExtVersion)) { @@ -278,23 +298,21 @@ std::unordered_set ZeGraphExtWrappers::queryGraph(std::pair= 1.5 - if (SupportAPIGraphQueryNetworkV2(_graphExtVersion)) { - ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES, - nullptr, - ZE_GRAPH_FORMAT_NGRAPH_LITE, - serializedIR.first, - serializedIR.second.get(), - buildFlags.c_str(), - ZE_GRAPH_FLAG_NONE}; - - // Create querynetwork handle - _logger.debug("For ext larger than 1.4 - performing pfnQueryNetworkCreate2"); - result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkCreate2(_zeroInitStruct->getContext(), - _zeroInitStruct->getDevice(), - &desc, - &hGraphQueryNetwork); - THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryNetworkCreate2", result, _zeroInitStruct->getGraphDdiTable()); - } + ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES, + nullptr, + ZE_GRAPH_FORMAT_NGRAPH_LITE, + serializedIR.first, + serializedIR.second.get(), + buildFlags.c_str(), + ZE_GRAPH_FLAG_NONE}; + + // Create querynetwork handle + _logger.debug("For ext larger than 1.4 - perform pfnQueryNetworkCreate2"); + result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkCreate2(_zeroInitStruct->getContext(), + _zeroInitStruct->getDevice(), + &desc, + &hGraphQueryNetwork); + THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryNetworkCreate2", result, _zeroInitStruct->getGraphDdiTable()); return getQueryResultFromSupportedLayers(result, hGraphQueryNetwork); } @@ -308,10 +326,6 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pairgetGraphDdiTable() ze_graph_desc_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES, @@ -321,7 +335,7 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pairgetGraphDdiTable().pfnCreate(_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), @@ -338,7 +352,7 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pairgetGraphDdiTable().pfnCreate2(_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), @@ -363,6 +377,7 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(const std::vector& network.data(), nullptr}; + _logger.debug("getGraphHandle - perform pfnCreate"); auto result = _zeroInitStruct->getGraphDdiTable().pfnCreate(_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), &desc, @@ -434,6 +449,7 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle, std::vector& outputs) const { if (NotSupportArgumentMetadata(_graphExtVersion)) { ze_graph_argument_properties_3_t arg; + _logger.debug("getMetadata - perfrom pfnGetArgumentProperties3"); auto result = _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, index, &arg); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable()); @@ -451,12 +467,14 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle, } } else { ze_graph_argument_properties_3_t arg; + _logger.debug("getMetadata - perfrom pfnGetArgumentProperties3"); auto result = _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, index, &arg); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable()); std::optional optionalMetadata = std::nullopt; if (!isStateInputName(arg.name) && !isStateOutputName(arg.name) && !isShapeTensorName(arg.name)) { + _logger.debug("getMetadata - perfrom pfnGetArgumentMetadata"); ze_graph_argument_metadata_t metadata; result = _zeroInitStruct->getGraphDdiTable().pfnGraphGetArgumentMetadata(graphHandle, index, &metadata); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGraphGetArgumentMetadata", result, _zeroInitStruct->getGraphDdiTable()); @@ -482,6 +500,7 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle, NetworkMetadata ZeGraphExtWrappers::getNetworkMeta(ze_graph_handle_t graphHandle) const { ze_graph_properties_t graphProperties{}; + _logger.debug("getNetworkMeta - perfrom pfnGetProperties"); auto result = _zeroInitStruct->getGraphDdiTable().pfnGetProperties(graphHandle, &graphProperties); THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetProperties", result, _zeroInitStruct->getGraphDdiTable()); NetworkMetadata meta;