Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python API] bind ProfilingInfo #55

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions runtime/bindings/python/src/pyopenvino/core/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ void regclass_InferRequest(py::module m) {
},
py::arg("tensor"));

cls.def("get_profiling_info", [](InferRequestWrapper& self) {
return self._request.get_profiling_info();
Copy link
Owner

@akuporos akuporos Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to implement it like property profiling_info

Copy link

@jiwaszki jiwaszki Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be done both ways. Function and property co-existing is fine with me.

});

cls.def_property_readonly("input_tensors", [](InferRequestWrapper& self) {
return self._inputs;
});
Expand Down
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