Skip to content

Commit

Permalink
Update debug log
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Wang <[email protected]>
  • Loading branch information
XinWangIntel committed Nov 14, 2024
1 parent 386606f commit 13011ea
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 96 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,25 @@ namespace intel_npu {
ZeGraphExtWrappers::ZeGraphExtWrappers(const std::shared_ptr<ZeroInitStructsHolder>& 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) {
Expand All @@ -112,17 +123,19 @@ 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.",
result,
_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,
Expand All @@ -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,
Expand All @@ -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);
}

Expand All @@ -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 <name_0><name_1><name_2> to unordered_set of string
Expand Down Expand Up @@ -217,13 +236,15 @@ std::unordered_set<std::string> 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",
result,
_zeroInitStruct->getGraphDdiTable());

// Get the result data of query
_logger.debug("getQueryResultFromSupportLayers - perfrom pfnQueryNetworkGetSupportedLayers to get data");
std::vector<char> supportedLayers(size);
result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkGetSupportedLayers(hGraphQueryNetwork,
&size,
Expand All @@ -232,6 +253,7 @@ std::unordered_set<std::string> 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());

Expand All @@ -255,46 +277,42 @@ std::unordered_set<std::string> ZeGraphExtWrappers::queryGraph(std::pair<size_t,
ze_graph_query_network_handle_t hGraphQueryNetwork = nullptr;

// For ext version == 1.3 && == 1.4
if (SupportAPIGraphQueryNetworkV1(_graphExtVersion)) {
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 - performing pfnQueryNetworkCreate");
result = _zeroInitStruct->getGraphDdiTable().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)) {
// For ext version >= 1.5
ze_graph_query_network_handle_t hGraphQueryNetwork = nullptr;

// For ext version >= 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);
}
Expand All @@ -308,10 +326,6 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pair<size_t, std::shar
const std::string& buildFlags,
const uint32_t& flags) const {
ze_graph_handle_t graphHandle;

_logger.info("compileIR Using extension version: %d.%d",
ZE_MAJOR_VERSION(_graphExtVersion),
ZE_MINOR_VERSION(_graphExtVersion));
if (NotSupportGraph2(_graphExtVersion)) {
// For ext version <1.5, calling pfnCreate api in _zeroInitStruct->getGraphDdiTable()
ze_graph_desc_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES,
Expand All @@ -321,7 +335,7 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pair<size_t, std::shar
serializedIR.second.get(),
buildFlags.c_str()};

_logger.debug("createGraph - performing pfnCreate");
_logger.debug("getGraphHandle - perform pfnCreate");
// Create querynetwork handle
auto result = _zeroInitStruct->getGraphDdiTable().pfnCreate(_zeroInitStruct->getContext(),
_zeroInitStruct->getDevice(),
Expand All @@ -338,7 +352,7 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pair<size_t, std::shar
buildFlags.c_str(),
flags};

_logger.debug("createGraph - performing pfnCreate2");
_logger.debug("getGraphHandle - perform pfnCreate2");
// Create querynetwork handle
auto result = _zeroInitStruct->getGraphDdiTable().pfnCreate2(_zeroInitStruct->getContext(),
_zeroInitStruct->getDevice(),
Expand All @@ -363,6 +377,7 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(const std::vector<uint8_t>&
network.data(),
nullptr};

_logger.debug("getGraphHandle - perform pfnCreate");
auto result = _zeroInitStruct->getGraphDdiTable().pfnCreate(_zeroInitStruct->getContext(),
_zeroInitStruct->getDevice(),
&desc,
Expand Down Expand Up @@ -434,6 +449,7 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,
std::vector<IODescriptor>& 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());

Expand All @@ -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<ze_graph_argument_metadata_t> 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());
Expand All @@ -482,18 +500,16 @@ 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;

for (uint32_t index = 0; index < graphProperties.numGraphArgs; ++index) {
getMetadata(graphHandle, index, meta.inputs, meta.outputs);
}
// TODO: support this information in CiD [track: E#33479]
meta.numStreams = 1;
meta.bindRelatedDescriptors();

return meta;
}

Expand Down

0 comments on commit 13011ea

Please sign in to comment.