Skip to content

Commit

Permalink
Added ITT traces to GStreamingExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
AsyaPronina committed May 4, 2021
1 parent 7de627c commit 96e2e5a
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 105 deletions.
12 changes: 12 additions & 0 deletions modules/gapi/CMakeLists.txt
Expand Up @@ -162,6 +162,9 @@ set(gapi_srcs
# Python bridge
src/backends/ie/bindings_ie.cpp
src/backends/python/gpythonbackend.cpp

# Utils (ITT tracing)
src/utils/itt.cpp
)

ocv_add_dispatched_file(backends/fluid/gfluidimgproc_func SSE4_1 AVX2)
Expand All @@ -178,13 +181,22 @@ ocv_module_include_directories("${CMAKE_CURRENT_LIST_DIR}/src")
ocv_create_module()

ocv_target_link_libraries(${the_module} PRIVATE ade)

if(OPENCV_GAPI_INF_ENGINE)
ocv_target_link_libraries(${the_module} PRIVATE ${INF_ENGINE_TARGET})
endif()

if(HAVE_TBB)
ocv_target_link_libraries(${the_module} PRIVATE tbb)
endif()

# TODO: Consider support of ITT in G-API standalone mode.
if(CV_TRACE AND HAVE_ITT)
ocv_target_compile_definitions(${the_module} PRIVATE -DOPENCV_WITH_ITT=1)
ocv_module_include_directories(${ITT_INCLUDE_DIRS})
ocv_target_link_libraries(${the_module} PRIVATE ${ITT_LIBRARIES})
endif()

set(__test_extra_deps "")
if(OPENCV_GAPI_INF_ENGINE)
list(APPEND __test_extra_deps ${INF_ENGINE_TARGET})
Expand Down
4 changes: 2 additions & 2 deletions modules/gapi/src/backends/common/gmetabackend.cpp
Expand Up @@ -71,7 +71,7 @@ void GraphMetaExecutable::run(std::vector<InObj> &&input_objs,
cv::util::get<cv::detail::OpaqueRef>(out_arg) = it->second;
}

class GraphMetaBackendImpl final: public cv::gapi::GBackend::Priv {
class GGraphMetaBackendImpl final: public cv::gapi::GBackend::Priv {
virtual void unpackKernel(ade::Graph &,
const ade::NodeHandle &,
const cv::GKernelImpl &) override {
Expand All @@ -88,7 +88,7 @@ class GraphMetaBackendImpl final: public cv::gapi::GBackend::Priv {
};

cv::gapi::GBackend graph_meta_backend() {
static cv::gapi::GBackend this_backend(std::make_shared<GraphMetaBackendImpl>());
static cv::gapi::GBackend this_backend(std::make_shared<GGraphMetaBackendImpl>());
return this_backend;
}

Expand Down
13 changes: 10 additions & 3 deletions modules/gapi/src/backends/cpu/gcpubackend.cpp
Expand Up @@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018-2020 Intel Corporation
// Copyright (C) 2018-2021 Intel Corporation


#include "precomp.hpp"
Expand All @@ -26,6 +26,8 @@

#include "api/gbackend_priv.hpp" // FIXME: Make it part of Backend SDK!

#include "utils/itt.hpp"

// FIXME: Is there a way to take a typed graph (our GModel),
// and create a new typed graph _ATOP_ of that (by extending with a couple of
// new types?).
Expand Down Expand Up @@ -251,8 +253,13 @@ void cv::gimpl::GCPUExecutable::run(std::vector<InObj> &&input_objs,
context.m_state = m_nodesToStates.at(op_info.nh);
}

// Now trigger the executable unit
k.m_runF(context);
{
GAPI_ITT_DYNAMIC_LOCAL_HANDLE(op_hndl, op.k.name.c_str());
GAPI_ITT_AUTO_TRACE_GUARD(op_hndl);

// Now trigger the executable unit
k.m_runF(context);
}

//As Kernels are forbidden to allocate memory for (Mat) outputs,
//this code seems redundant, at least for Mats
Expand Down
5 changes: 5 additions & 0 deletions modules/gapi/src/backends/ie/giebackend.cpp
Expand Up @@ -60,6 +60,8 @@ template<typename T> using QueueClass = tbb::concurrent_bounded_queue<T>;
template<typename T> using QueueClass = cv::gapi::own::concurrent_bounded_queue<T>;
#endif // TBB

#include "utils/itt.hpp"

namespace IE = InferenceEngine;

namespace {
Expand Down Expand Up @@ -757,6 +759,9 @@ static void configureInputInfo(const IE::InputInfo::Ptr& ii, const cv::GMetaArg
// to post outputs blobs (cv::GMat's).
static void PostOutputs(InferenceEngine::InferRequest &request,
std::shared_ptr<IECallContext> ctx) {
GAPI_ITT_STATIC_LOCAL_HANDLE(ie_cb_post_outputs_hndl, "IE_async_callback_PostOutputs");
GAPI_ITT_AUTO_TRACE_GUARD(ie_cb_post_outputs_hndl);

for (auto i : ade::util::iota(ctx->uu.params.num_out))
{
auto& out_mat = ctx->outMatR(i);
Expand Down
21 changes: 21 additions & 0 deletions modules/gapi/src/compiler/gislandmodel.cpp
Expand Up @@ -335,6 +335,27 @@ ade::NodeHandle GIslandModel::producerOf(const ConstGraph &g, ade::NodeHandle &d
return ade::NodeHandle();
}

std::string GIslandModel::traceIslandName(const ade::NodeHandle& island_nh, const Graph& g) {
auto island_ptr = g.metadata(island_nh).get<FusedIsland>().object;
std::string island_name = island_ptr->name();

std::string backend_name = "";
auto backend_impl = island_ptr->backend().priv();
std::string backend_impl_type_name = typeid(backend_impl).name();
std::regex rgx("G([a-zA-Z0-9]+)BackendImpl");
std::smatch matches;
if (std::regex_search(backend_impl_type_name, matches, rgx)) {
if (2ul == matches.size()) {
backend_name = matches[1].str();
}
else {
backend_name = backend_impl_type_name;
}
}

return island_name + "_" + backend_name;
}

void GIslandExecutable::run(GIslandExecutable::IInput &in, GIslandExecutable::IOutput &out)
{
// Default implementation: just reuse the existing old-fashioned run
Expand Down
8 changes: 7 additions & 1 deletion modules/gapi/src/compiler/gislandmodel.hpp
Expand Up @@ -10,6 +10,8 @@

#include <unordered_set>
#include <memory> // shared_ptr
#include <typeinfo> // typeid
#include <regex>

#include <ade/graph.hpp>
#include <ade/typed_graph.hpp>
Expand Down Expand Up @@ -290,7 +292,11 @@ namespace GIslandModel
// from the original model (! don't mix with DataSlot)
// FIXME: GAPI_EXPORTS because of tests only!
ade::NodeHandle GAPI_EXPORTS producerOf(const ConstGraph &g, ade::NodeHandle &data_nh);

// traceIslandName - returns pretty island name for passed island node.
// Function uses RTTI to assembly name.
// In case if name of backend implementation class doesn't fit G[Name]BackendImpl pattern,
// raw mangled name of class will be used.
std::string traceIslandName(const ade::NodeHandle& op_nh, const Graph& g);
} // namespace GIslandModel

}} // namespace cv::gimpl
Expand Down
59 changes: 0 additions & 59 deletions modules/gapi/src/executor/gapi_itt.hpp

This file was deleted.

0 comments on commit 96e2e5a

Please sign in to comment.