diff --git a/runtime/bindings/python/src/openvino/__init__.py b/runtime/bindings/python/src/openvino/__init__.py index 5634960d064d8c..ceab3f6b48f6d2 100644 --- a/runtime/bindings/python/src/openvino/__init__.py +++ b/runtime/bindings/python/src/openvino/__init__.py @@ -45,6 +45,7 @@ from openvino.pyopenvino import ColorFormat from openvino.pyopenvino import PreProcessChannel from openvino.pyopenvino import Tensor +from openvino.pyopenvino import ProfilingInfo from openvino import opset1 from openvino import opset2 diff --git a/runtime/bindings/python/src/pyopenvino/core/infer_request.cpp b/runtime/bindings/python/src/pyopenvino/core/infer_request.cpp index f3885bcdbfa633..ad9374b5dd1f36 100644 --- a/runtime/bindings/python/src/pyopenvino/core/infer_request.cpp +++ b/runtime/bindings/python/src/pyopenvino/core/infer_request.cpp @@ -254,6 +254,10 @@ void regclass_InferRequest(py::module m) { }, py::arg("tensor")); + cls.def("get_profiling_info", [](InferRequestWrapper& self) { + return self._request.get_profiling_info(); + }); + cls.def_property_readonly("inputs", [](InferRequestWrapper& self) { return self._inputs; }); @@ -281,4 +285,9 @@ void regclass_InferRequest(py::module m) { cls.def_property_readonly("latency", [](InferRequestWrapper& self) { return self.get_latency(); }); + + cls.def_property_readonly("profiling_info", [](InferRequestWrapper& self) { + return self._request.get_profiling_info(); + }); + } diff --git a/runtime/bindings/python/src/pyopenvino/core/profiling_info.cpp b/runtime/bindings/python/src/pyopenvino/core/profiling_info.cpp new file mode 100644 index 00000000000000..9619e070386017 --- /dev/null +++ b/runtime/bindings/python/src/pyopenvino/core/profiling_info.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "pyopenvino/core/profiling_info.hpp" + +#include + +#include "openvino/runtime/profiling_info.hpp" + +namespace py = pybind11; + +void regclass_ProfilingInfo(py::module m) { + py::class_> cls(m, "ProfilingInfo"); + cls.def(py::init<>()) + .def_readwrite("status", &ov::runtime::ProfilingInfo::status) + .def_readwrite("real_time", &ov::runtime::ProfilingInfo::real_time) + .def_readwrite("cpu_time", &ov::runtime::ProfilingInfo::cpu_time) + .def_readwrite("node_name", &ov::runtime::ProfilingInfo::node_name) + .def_readwrite("exec_type", &ov::runtime::ProfilingInfo::exec_type) + .def_readwrite("node_type", &ov::runtime::ProfilingInfo::node_type); + + py::enum_(cls, "Status") + .value("NOT_RUN", ov::runtime::ProfilingInfo::Status::NOT_RUN) + .value("OPTIMIZED_OUT", ov::runtime::ProfilingInfo::Status::OPTIMIZED_OUT) + .value("EXECUTED", ov::runtime::ProfilingInfo::Status::EXECUTED) + .export_values(); +} diff --git a/runtime/bindings/python/src/pyopenvino/core/profiling_info.hpp b/runtime/bindings/python/src/pyopenvino/core/profiling_info.hpp new file mode 100644 index 00000000000000..023935f620e913 --- /dev/null +++ b/runtime/bindings/python/src/pyopenvino/core/profiling_info.hpp @@ -0,0 +1,11 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +namespace py = pybind11; + +void regclass_ProfilingInfo(py::module m); diff --git a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp index 5f9e66c064d89f..37cdab7e042a00 100644 --- a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp +++ b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp @@ -33,6 +33,7 @@ #include "pyopenvino/core/ie_preprocess_info.hpp" #include "pyopenvino/core/infer_request.hpp" #include "pyopenvino/core/offline_transformations.hpp" +#include "pyopenvino/core/profiling_info.hpp" #include "pyopenvino/core/tensor.hpp" #include "pyopenvino/core/tensor_description.hpp" #include "pyopenvino/core/version.hpp" @@ -149,6 +150,7 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_Parameter(m); regclass_InputInfo(m); // regclass_InferQueue(m); + regclass_ProfilingInfo(m); regclass_PreProcessInfo(m); regmodule_offline_transformations(m); diff --git a/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py b/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py index 2db8d5340a645e..0d058b518fb451 100644 --- a/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py +++ b/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py @@ -4,9 +4,10 @@ import numpy as np import os import pytest +import datetime from ..conftest import image_path, model_path -from openvino import Core, Tensor +from openvino import Core, Tensor, ProfilingInfo is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD" test_net_xml, test_net_bin = model_path(is_myriad) @@ -25,7 +26,6 @@ def read_image(): return image -@pytest.mark.skip(reason="ProfilingInfo has to be bound") def test_get_profiling_info(device): core = Core() func = core.read_model(test_net_xml, test_net_bin) @@ -34,12 +34,13 @@ def test_get_profiling_info(device): img = read_image() request = exec_net.create_infer_request() request.infer({0: img}) - pc = request.get_profiling_info() - - assert pc["29"]["status"] == "EXECUTED" - assert pc["29"]["layer_type"] == "FullyConnected" - del exec_net - del core + prof_info = request.get_profiling_info() + soft_max_node = next(node for node in prof_info if node.node_name == "fc_out") + assert soft_max_node.node_type == "Softmax" + assert soft_max_node.status == ProfilingInfo.Status.OPTIMIZED_OUT + assert isinstance(soft_max_node.real_time, datetime.timedelta) + assert isinstance(soft_max_node.cpu_time, datetime.timedelta) + assert isinstance(soft_max_node.exec_type, str) def test_tensor_setter(device):