Skip to content

Commit

Permalink
rename macro definition
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaojieZhuIntel committed Oct 10, 2024
1 parent 377a995 commit fc66e1a
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 128 deletions.
24 changes: 12 additions & 12 deletions src/plugins/intel_npu/src/backend/include/zero_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ namespace intel_npu {

namespace zeroUtils {

#define THROW_ON_FAIL_FOR_GRAPH_EXT(step, result, graph_ddi_table_ext) \
OPENVINO_THROW("L0 ", \
step, \
" result: ", \
ze_result_to_string(result), \
", code 0x", \
std::hex, \
uint64_t(result), \
" - ", \
ze_result_to_description(result), \
" . ", \
#define THROW_ON_FAIL_FOR_LEVELZERO_EXT(step, result, graph_ddi_table_ext) \
OPENVINO_THROW("L0 ", \
step, \
" result: ", \
ze_result_to_string(result), \
", code 0x", \
std::hex, \
uint64_t(result), \
" - ", \
ze_result_to_description(result), \
" . ", \
intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext));

#define THROW_ON_FAIL_FOR_BACKEND(step, result) \
#define THROW_ON_FAIL_FOR_LEVELZERO(step, result) \
if (ZE_RESULT_SUCCESS != result) { \
OPENVINO_THROW("L0 ", \
step, \
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/intel_npu/src/backend/src/zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
THROW_ON_FAIL_FOR_BACKEND("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
THROW_ON_FAIL_FOR_BACKEND(
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;
}

THROW_ON_FAIL_FOR_BACKEND("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 @@ -141,7 +141,7 @@ uint64_t ZeroDevice::getAllocMemSize() const {
ze_result_t result =
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_GRAPH_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);
}
return query.allocated;
}
Expand All @@ -151,7 +151,7 @@ uint64_t ZeroDevice::getTotalMemSize() const {
ze_result_t result =
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_GRAPH_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);
}
return query.total;
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_npu/src/backend/src/zero_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
ze_result_t result =
_graph_ddi_table_ext.pfnCreate(_initStructs->getContext(), _initStructs->getDevice(), &desc, &_graph);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_GRAPH_EXT("pfnCreate", result, _graph_ddi_table_ext);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnCreate", result, _graph_ddi_table_ext);
}

} else {
Expand All @@ -68,7 +68,7 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i

ze_result_t result = _graph_ddi_table_ext.pfnGetProperties(_graph, &props);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_GRAPH_EXT("pfnGetProperties", result, _graph_ddi_table_ext);
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) {
Expand All @@ -83,7 +83,7 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
arg3.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;
ze_result_t result = _graph_ddi_table_ext.pfnGetArgumentProperties3(_graph, index, &arg3);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_GRAPH_EXT("pfnGetArgumentProperties3", result, _graph_ddi_table_ext);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _graph_ddi_table_ext);
}

if (arg3.type == ZE_GRAPH_ARGUMENT_TYPE_INPUT) {
Expand Down Expand Up @@ -171,7 +171,7 @@ void ZeroExecutor::setWorkloadType(const ov::WorkloadType workloadType) const {
void ZeroExecutor::setArgumentValue(uint32_t argi_, const void* argv_) const {
ze_result_t result = _graph_ddi_table_ext.pfnSetArgumentValue(_graph, argi_, argv_);
if (ZE_RESULT_SUCCESS != result) {
THROW_ON_FAIL_FOR_GRAPH_EXT("zeGraphSetArgumentValue", result, _graph_ddi_table_ext);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("zeGraphSetArgumentValue", result, _graph_ddi_table_ext);
}
}

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;
THROW_ON_FAIL_FOR_BACKEND("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
32 changes: 16 additions & 16 deletions src/plugins/intel_npu/src/backend/src/zero_init.cpp
Original file line number Diff line number Diff line change
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");
THROW_ON_FAIL_FOR_BACKEND("zeInit", zeInit(ZE_INIT_FLAG_VPU_ONLY));
THROW_ON_FAIL_FOR_LEVELZERO("zeInit", zeInit(ZE_INIT_FLAG_VPU_ONLY));

uint32_t drivers = 0;
THROW_ON_FAIL_FOR_BACKEND("zeDriverGet", zeDriverGet(&drivers, nullptr));
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGet", zeDriverGet(&drivers, nullptr));

std::vector<ze_driver_handle_t> all_drivers(drivers);
THROW_ON_FAIL_FOR_BACKEND("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 = {};
THROW_ON_FAIL_FOR_BACKEND("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;
THROW_ON_FAIL_FOR_BACKEND("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);
THROW_ON_FAIL_FOR_BACKEND("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) {
THROW_ON_FAIL_FOR_BACKEND(
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;
THROW_ON_FAIL_FOR_BACKEND("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;
THROW_ON_FAIL_FOR_BACKEND(
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
THROW_ON_FAIL_FOR_BACKEND("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};
THROW_ON_FAIL_FOR_BACKEND("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
26 changes: 14 additions & 12 deletions src/plugins/intel_npu/src/backend/src/zero_profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ ProfilingPool::~ProfilingPool() {
}

void ProfilingQuery::create(const ze_graph_profiling_pool_handle_t& profiling_pool) {
THROW_ON_FAIL_FOR_BACKEND("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) {
THROW_ON_FAIL_FOR_BACKEND(
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) {
THROW_ON_FAIL_FOR_BACKEND(
THROW_ON_FAIL_FOR_LEVELZERO(
"getProfilingProperties",
_graph_profiling_ddi_table_ext.pfnDeviceGetProfilingDataProperties(_device_handle, properties));
}
Expand Down Expand Up @@ -187,24 +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;
THROW_ON_FAIL_FOR_BACKEND("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};
THROW_ON_FAIL_FOR_BACKEND(
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_BACKEND("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_end)); // alight to 64 bytes to match npu l2 cache line size
}

void NpuInferProfiling::sampleNpuTimestamps() {
Expand Down
25 changes: 13 additions & 12 deletions src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ ZeroRemoteTensor::ZeroRemoteTensor(std::shared_ptr<ov::IRemoteContext> context,
_mem_type(mem_type),
_mem(mem) {
_ze_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
THROW_ON_FAIL_FOR_BACKEND("zeDeviceGetProperties",
zeDeviceGetProperties(_init_structs->getDevice(), &_ze_properties));
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties",
zeDeviceGetProperties(_init_structs->getDevice(), &_ze_properties));

const auto byte_size = ov::element::get_memory_size(_element_type, shape_size(_shape));

Expand Down Expand Up @@ -98,8 +98,9 @@ void ZeroRemoteTensor::allocate(const size_t bytes) {
} else {
desc = {ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC, nullptr, 0};
}
THROW_ON_FAIL_FOR_BACKEND("zeMemAllocHost",
zeMemAllocHost(_init_structs->getContext(), &desc, size, STANDARD_PAGE_SIZE, &_data));
THROW_ON_FAIL_FOR_LEVELZERO(
"zeMemAllocHost",
zeMemAllocHost(_init_structs->getContext(), &desc, size, STANDARD_PAGE_SIZE, &_data));
break;
}
case MemType::SHARED_BUF: {
Expand All @@ -117,13 +118,13 @@ void ZeroRemoteTensor::allocate(const size_t bytes) {
_mem,
nullptr};
ze_device_mem_alloc_desc_t desc = {ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC, &memory_import, 0, 0};
THROW_ON_FAIL_FOR_BACKEND("zeMemAllocDevice",
zeMemAllocDevice(_init_structs->getContext(),
&desc,
bytes,
STANDARD_PAGE_SIZE,
_init_structs->getDevice(),
&_data));
THROW_ON_FAIL_FOR_LEVELZERO("zeMemAllocDevice",
zeMemAllocDevice(_init_structs->getContext(),
&desc,
bytes,
STANDARD_PAGE_SIZE,
_init_structs->getDevice(),
&_data));
#else
// in the case of Linux platforms memory could be changed after allocation - using zeMemAllocHost for importing
// memory
Expand All @@ -132,7 +133,7 @@ void ZeroRemoteTensor::allocate(const size_t bytes) {
ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF,
static_cast<int>(reinterpret_cast<intptr_t>(_mem))};
ze_host_mem_alloc_desc_t desc = {.pNext = &memory_import};
THROW_ON_FAIL_FOR_BACKEND(
THROW_ON_FAIL_FOR_LEVELZERO(
"zeMemAllocHost",
zeMemAllocHost(_init_structs->getContext(), &desc, bytes, STANDARD_PAGE_SIZE, &_data));
#endif
Expand Down
Loading

0 comments on commit fc66e1a

Please sign in to comment.