Skip to content

Commit

Permalink
[Python API] bind ProfilingInfo (#55)
Browse files Browse the repository at this point in the history
* bind ProfilingInfo

* Add tests

* Fix code style

* Add property
  • Loading branch information
Alexey Lebedev authored Nov 8, 2021
1 parent a6e21e4 commit 9cebdc7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions runtime/bindings/python/src/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions runtime/bindings/python/src/pyopenvino/core/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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();
});

}
28 changes: 28 additions & 0 deletions runtime/bindings/python/src/pyopenvino/core/profiling_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "pyopenvino/core/profiling_info.hpp"

#include <pybind11/chrono.h>

#include "openvino/runtime/profiling_info.hpp"

namespace py = pybind11;

void regclass_ProfilingInfo(py::module m) {
py::class_<ov::runtime::ProfilingInfo, std::shared_ptr<ov::runtime::ProfilingInfo>> 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_<ov::runtime::ProfilingInfo::Status>(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();
}
11 changes: 11 additions & 0 deletions runtime/bindings/python/src/pyopenvino/core/profiling_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <pybind11/pybind11.h>

namespace py = pybind11;

void regclass_ProfilingInfo(py::module m);
2 changes: 2 additions & 0 deletions runtime/bindings/python/src/pyopenvino/pyopenvino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 9cebdc7

Please sign in to comment.