Skip to content

Commit

Permalink
[NPU] Add pfn build log to pfn-related function (openvinotoolkit#26772)
Browse files Browse the repository at this point in the history
### Details:
There are many OPENVINO_THROW, OPENVINO_ASSERT inside
https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp,
call getLatestBuildError to show error info when pfn-related function is
called and remove exception handle fuction that would never be called.
Use a macro THROW_ON_FAIL_FOR_LEVELZERO_EXT to simplify exception
handling code.
There are two functions zeroUtils::throwOnFail() in zero_utils.hpp, but
only the two-parameters function zeroUtils::throwOnFail() is actually
used. And zeroUtils::throwOnFail() will use its code location instead of
the real location where issue happen, so use a macro
THROW_ON_FAIL_FOR_LEVELZERO instead of the function
zeroUtils::throwOnFail() with two parameters.
Function zeroUtils::throwOnFail() with three parameters is preserved.

### Tickets:
 - [EISW-139871](https://jira.devtools.intel.com/browse/EISW-139871)
  • Loading branch information
ShaojieZhuIntel authored and CuriousPanCake committed Nov 6, 2024
1 parent 16f484e commit 5b3afc4
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "intel_npu/common/npu.hpp"
#include "intel_npu/common/sync_infer_request.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "zero_executor.hpp"
#include "zero_pipeline.hpp"
#include "zero_profiling.hpp"
#include "zero_remote_tensor.hpp"
#include "zero_utils.hpp"
#include "zero_wrappers.hpp"

namespace intel_npu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#pragma once

#include "intel_npu/utils/zero/zero_utils.hpp"
#include "zero_executor.hpp"
#include "zero_memory.hpp"
#include "zero_profiling.hpp"
#include "zero_utils.hpp"
#include "zero_wrappers.hpp"

namespace intel_npu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <ze_graph_ext.h>

#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "zero_types.hpp"
#include "zero_utils.hpp"

namespace intel_npu {
class CommandList;
Expand Down
30 changes: 16 additions & 14 deletions src/plugins/intel_npu/src/backend/src/zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include "intel_npu/common/itt.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "zero_executor.hpp"
#include "zero_host_tensor.hpp"
#include "zero_infer_request.hpp"
#include "zero_remote_tensor.hpp"
#include "zero_utils.hpp"

using namespace intel_npu;

Expand All @@ -20,8 +20,8 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs
log("ZeroDevice", Logger::global().level()) {
log.debug("ZeroDevice::ZeroDevice init");
device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
zeroUtils::throwOnFail("zeDeviceGetProperties",
zeDeviceGetProperties(_initStructs->getDevice(), &device_properties));
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties",
zeDeviceGetProperties(_initStructs->getDevice(), &device_properties));

// Query PCI information
// Older drivers do not have this implementend. Linux driver returns NOT_IMPLEMENTED, while windows driver returns
Expand Down Expand Up @@ -62,7 +62,7 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs
std::vector<ze_command_queue_group_properties_t> command_group_properties;
uint32_t command_queue_group_count = 0;
// Discover all command queue groups
zeroUtils::throwOnFail(
THROW_ON_FAIL_FOR_LEVELZERO(
"zeDeviceGetCommandQueueGroupProperties",
zeDeviceGetCommandQueueGroupProperties(_initStructs->getDevice(), &command_queue_group_count, nullptr));

Expand All @@ -74,10 +74,10 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs
prop.pNext = nullptr;
}

zeroUtils::throwOnFail("zeDeviceGetCommandQueueGroupProperties",
zeDeviceGetCommandQueueGroupProperties(_initStructs->getDevice(),
&command_queue_group_count,
command_group_properties.data()));
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetCommandQueueGroupProperties",
zeDeviceGetCommandQueueGroupProperties(_initStructs->getDevice(),
&command_queue_group_count,
command_group_properties.data()));

// Find the corresponding command queue group.
log.debug("ZeroDevice::ZeroDevice - findGroupOrdinal");
Expand Down Expand Up @@ -138,17 +138,19 @@ uint32_t ZeroDevice::getMaxNumSlices() const {

uint64_t ZeroDevice::getAllocMemSize() const {
ze_graph_memory_query_t query{};
zeroUtils::throwOnFail(
"pfnQueryContextMemory",
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query));
ze_result_t result =
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);

return query.allocated;
}

uint64_t ZeroDevice::getTotalMemSize() const {
ze_graph_memory_query_t query{};
zeroUtils::throwOnFail(
"pfnQueryContextMemory",
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query));
ze_result_t result =
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);

return query.total;
}

Expand Down
22 changes: 13 additions & 9 deletions src/plugins/intel_npu/src/backend/src/zero_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include "intel_npu/common/itt.hpp"
#include "intel_npu/config/common.hpp"
#include "intel_npu/prefix.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "openvino/runtime/properties.hpp"
#include "ze_command_queue_npu_ext.h"
#include "zero_device.hpp"
#include "zero_utils.hpp"

using namespace intel_npu;

Expand Down Expand Up @@ -50,10 +50,9 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
_networkDesc->compiledNetwork.size(),
_networkDesc->compiledNetwork.data(),
nullptr};

zeroUtils::throwOnFail(
"pfnCreate",
_graph_ddi_table_ext.pfnCreate(_initStructs->getContext(), _initStructs->getDevice(), &desc, &_graph));
ze_result_t result =
_graph_ddi_table_ext.pfnCreate(_initStructs->getContext(), _initStructs->getDevice(), &desc, &_graph);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnCreate", result, _graph_ddi_table_ext);

} else {
_logger.debug("reuse graph handle created from compiler");
Expand All @@ -65,7 +64,9 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
ze_graph_properties_t props{};
props.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;

zeroUtils::throwOnFail("pfnGetProperties", _graph_ddi_table_ext.pfnGetProperties(_graph, &props));
ze_result_t result = _graph_ddi_table_ext.pfnGetProperties(_graph, &props);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetProperties", result, _graph_ddi_table_ext);

auto targetDriverExtVersion = _graph_ddi_table_ext.version();
if (targetDriverExtVersion <= ZE_GRAPH_EXT_VERSION_1_1) {
OPENVINO_THROW("Incompatibility between the NPU plugin and driver! The driver version is too old, please "
Expand All @@ -77,8 +78,8 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
for (uint32_t index = 0; index < props.numGraphArgs; ++index) {
ze_graph_argument_properties_3_t arg3{};
arg3.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;
zeroUtils::throwOnFail("pfnGetArgumentProperties3",
_graph_ddi_table_ext.pfnGetArgumentProperties3(_graph, index, &arg3));
ze_result_t result = _graph_ddi_table_ext.pfnGetArgumentProperties3(_graph, index, &arg3);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _graph_ddi_table_ext);

if (arg3.type == ZE_GRAPH_ARGUMENT_TYPE_INPUT) {
_input_descriptors.push_back(ArgumentDescriptor{arg3, index});
Expand Down Expand Up @@ -163,7 +164,10 @@ void ZeroExecutor::setWorkloadType(const ov::WorkloadType workloadType) const {
}

void ZeroExecutor::setArgumentValue(uint32_t argi_, const void* argv_) const {
zeroUtils::throwOnFail("zeGraphSetArgumentValue", _graph_ddi_table_ext.pfnSetArgumentValue(_graph, argi_, argv_));
ze_result_t result = _graph_ddi_table_ext.pfnSetArgumentValue(_graph, argi_, argv_);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_LEVELZERO_EXT("zeGraphSetArgumentValue", result, _graph_ddi_table_ext);
}
}

void ZeroExecutor::mutexLock() const {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
}

_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
zeroUtils::throwOnFail("zeDeviceGetProperties",
zeDeviceGetProperties(_executor->getInitStructs()->getDevice(), &_properties));
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties",
zeDeviceGetProperties(_executor->getInitStructs()->getDevice(), &_properties));

_outputAllocator = std::make_shared<const zeroMemory::HostMemAllocator>(_initStructs);
_inputAllocator =
Expand Down
34 changes: 17 additions & 17 deletions src/plugins/intel_npu/src/backend/src/zero_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "intel_npu/common/itt.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "ze_api.h"
#include "ze_command_queue_npu_ext.h"
#include "zero_utils.hpp"

#ifdef _WIN32
namespace {
Expand Down Expand Up @@ -54,13 +54,13 @@ static std::tuple<uint32_t, std::string> queryDriverExtensionVersion(
ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder", Logger::global().level()) {
OV_ITT_SCOPED_TASK(itt::domains::LevelZeroBackend, "ZeroInitStructsHolder::ZeroInitStructsHolder");
log.debug("ZeroInitStructsHolder - performing zeInit on VPU only");
zeroUtils::throwOnFail("zeInit", zeInit(ZE_INIT_FLAG_VPU_ONLY));
THROW_ON_FAIL_FOR_LEVELZERO("zeInit", zeInit(ZE_INIT_FLAG_VPU_ONLY));

uint32_t drivers = 0;
zeroUtils::throwOnFail("zeDriverGet", zeDriverGet(&drivers, nullptr));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGet", zeDriverGet(&drivers, nullptr));

std::vector<ze_driver_handle_t> all_drivers(drivers);
zeroUtils::throwOnFail("zeDriverGet", zeDriverGet(&drivers, all_drivers.data()));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGet", zeDriverGet(&drivers, all_drivers.data()));

// Get our target driver
driver_properties.stype = ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;
Expand All @@ -79,7 +79,7 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",

// Check L0 API version
ze_api_version_t ze_drv_api_version = {};
zeroUtils::throwOnFail("zeDriverGetApiVersion", zeDriverGetApiVersion(driver_handle, &ze_drv_api_version));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetApiVersion", zeDriverGetApiVersion(driver_handle, &ze_drv_api_version));

if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(ze_drv_api_version)) {
OPENVINO_THROW("Incompatibility between NPU plugin and driver! ",
Expand All @@ -97,13 +97,13 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",
}

uint32_t count = 0;
zeroUtils::throwOnFail("zeDriverGetExtensionProperties",
zeDriverGetExtensionProperties(driver_handle, &count, nullptr));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",
zeDriverGetExtensionProperties(driver_handle, &count, nullptr));

std::vector<ze_driver_extension_properties_t> extProps;
extProps.resize(count);
zeroUtils::throwOnFail("zeDriverGetExtensionProperties",
zeDriverGetExtensionProperties(driver_handle, &count, extProps.data()));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",
zeDriverGetExtensionProperties(driver_handle, &count, extProps.data()));

// Query our graph extension version
std::string graph_ext_name;
Expand Down Expand Up @@ -148,7 +148,7 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",
// Load our command queue extension
ze_command_queue_npu_dditable_ext_last_t* _command_queue_npu_dditable_ext = nullptr;
if (command_queue_ext_version) {
zeroUtils::throwOnFail(
THROW_ON_FAIL_FOR_LEVELZERO(
"zeDriverGetExtensionFunctionAddress " + command_queue_ext_name,
zeDriverGetExtensionFunctionAddress(driver_handle,
command_queue_ext_name.c_str(),
Expand All @@ -161,10 +161,10 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",

// Load our graph extension
ze_graph_dditable_ext_last_t* graph_ddi_table_ext = nullptr;
zeroUtils::throwOnFail("zeDriverGetExtensionFunctionAddress",
zeDriverGetExtensionFunctionAddress(driver_handle,
graph_ext_name.c_str(),
reinterpret_cast<void**>(&graph_ddi_table_ext)));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionFunctionAddress",
zeDriverGetExtensionFunctionAddress(driver_handle,
graph_ext_name.c_str(),
reinterpret_cast<void**>(&graph_ddi_table_ext)));
graph_dditable_ext_decorator =
std::make_unique<ze_graph_dditable_ext_decorator>(graph_ddi_table_ext, graph_ext_version);

Expand All @@ -189,7 +189,7 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",

// Load our profiling extension
ze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;
zeroUtils::throwOnFail(
THROW_ON_FAIL_FOR_LEVELZERO(
"zeDriverGetExtensionFunctionAddress",
zeDriverGetExtensionFunctionAddress(driver_handle,
"ZE_extension_profiling_data",
Expand All @@ -200,11 +200,11 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",

uint32_t device_count = 1;
// Get our target device
zeroUtils::throwOnFail("zeDeviceGet", zeDeviceGet(driver_handle, &device_count, &device_handle));
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGet", zeDeviceGet(driver_handle, &device_count, &device_handle));

// Create context - share between the compiler and the backend
ze_context_desc_t context_desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, 0, 0};
zeroUtils::throwOnFail("zeContextCreate", zeContextCreate(driver_handle, &context_desc, &context));
THROW_ON_FAIL_FOR_LEVELZERO("zeContextCreate", zeContextCreate(driver_handle, &context_desc, &context));
log.debug("ZeroInitStructsHolder initialize complete");
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/backend/src/zero_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "zero_memory.hpp"

#include "intel_npu/utils/zero/zero_api.hpp"
#include "zero_utils.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"

namespace intel_npu {
namespace zeroMemory {
Expand Down
39 changes: 21 additions & 18 deletions src/plugins/intel_npu/src/backend/src/zero_profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "intel_npu/config/compiler.hpp"
#include "intel_npu/profiling.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "zero_profiling.hpp"
#include "zero_utils.hpp"

namespace intel_npu {
namespace zeroProfiling {
Expand Down Expand Up @@ -46,8 +46,9 @@ ProfilingPool::~ProfilingPool() {
}

void ProfilingQuery::create(const ze_graph_profiling_pool_handle_t& profiling_pool) {
zeroUtils::throwOnFail("pfnProfilingQueryCreate",
_graph_profiling_ddi_table_ext.pfnProfilingQueryCreate(profiling_pool, _index, &_handle));
THROW_ON_FAIL_FOR_LEVELZERO(
"pfnProfilingQueryCreate",
_graph_profiling_ddi_table_ext.pfnProfilingQueryCreate(profiling_pool, _index, &_handle));
}

LayerStatistics ProfilingQuery::getLayerStatistics() const {
Expand All @@ -66,7 +67,7 @@ void ProfilingQuery::queryGetData(const ze_graph_profiling_type_t profilingType,
uint32_t* pSize,
uint8_t* pData) const {
if (_handle && pSize) {
zeroUtils::throwOnFail(
THROW_ON_FAIL_FOR_LEVELZERO(
"pfnProfilingQueryGetData",
_graph_profiling_ddi_table_ext.pfnProfilingQueryGetData(_handle, profilingType, pSize, pData));
}
Expand All @@ -92,7 +93,7 @@ template std::vector<uint8_t> ProfilingQuery::getData<uint8_t>() const;

void ProfilingQuery::getProfilingProperties(ze_device_profiling_data_properties_t* properties) const {
if (_handle && properties) {
zeroUtils::throwOnFail(
THROW_ON_FAIL_FOR_LEVELZERO(
"getProfilingProperties",
_graph_profiling_ddi_table_ext.pfnDeviceGetProfilingDataProperties(_device_handle, properties));
}
Expand Down Expand Up @@ -187,23 +188,25 @@ NpuInferProfiling::NpuInferProfiling(ze_context_handle_t context,
_logger("InferProfiling", loglevel) {
/// Fetch and store the device timer resolution
_dev_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2;
zeroUtils::throwOnFail("zeDeviceGetProperties", zeDeviceGetProperties(_device_handle, &_dev_properties));
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties", zeDeviceGetProperties(_device_handle, &_dev_properties));
/// Request mem allocations
ze_host_mem_alloc_desc_t desc = {ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC,
nullptr,
ZE_HOST_MEM_ALLOC_FLAG_BIAS_CACHED};
zeroUtils::throwOnFail("zeMemAllocHost",
zeMemAllocHost(_context,
&desc,
sizeof(uint64_t),
64,
&npu_ts_infer_start)); // align to 64 bytes to match npu l2 cache line size
zeroUtils::throwOnFail("zeMemAllocHost",
zeMemAllocHost(_context,
&desc,
sizeof(uint64_t),
64,
&npu_ts_infer_end)); // alight to 64 bytes to match npu l2 cache line size
THROW_ON_FAIL_FOR_LEVELZERO(
"zeMemAllocHost",
zeMemAllocHost(_context,
&desc,
sizeof(uint64_t),
64,
&npu_ts_infer_start)); // align to 64 bytes to match npu l2 cache line size
THROW_ON_FAIL_FOR_LEVELZERO(
"zeMemAllocHost",
zeMemAllocHost(_context,
&desc,
sizeof(uint64_t),
64,
&npu_ts_infer_end)); // alight to 64 bytes to match npu l2 cache line size
}

void NpuInferProfiling::sampleNpuTimestamps() {
Expand Down
Loading

0 comments on commit 5b3afc4

Please sign in to comment.