Skip to content

[G-API] GExecutor abstract interface#21762

Closed
OrestChura wants to merge 3 commits intoopencv:4.xfrom
OrestChura:oc/gexec_abstract
Closed

[G-API] GExecutor abstract interface#21762
OrestChura wants to merge 3 commits intoopencv:4.xfrom
OrestChura:oc/gexec_abstract

Conversation

@OrestChura
Copy link
Copy Markdown
Contributor

Inheritor of #19329

This pull request separates GExecutor into interface (more accurately the base part with customization points) and GSerialExecutor which is an implementation for the naive executor.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

// - cv::MediaFrame - for media buffers
// - cv::Scalar - for single values (with up to four components inside)
// - cv::detail::VectorRef - an untyped wrapper over std::vector<T>
// - cv::detail::OpaqueRef - an untyped wrapper over an object with an arbitrary type T
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it a valid change from me? I'm just not sure these types used for exchanging between Islands

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks valid

}
}

void assignMetaStubExec(Mag& mag, const RcDesc &rc, const cv::GRunArg::Meta &meta) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as for me it looks like these bunch of functions which interact with Mag should be members of this class Mag
Or located in different file at least

Could you move out this functions into different file, please?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to do that, Magazine class itself is not bound to its contents (it is template)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can consider this as part of further refactoring if ever we'll need it in more than 1 place

Copy link
Copy Markdown
Contributor

@sivanov-work sivanov-work left a comment

Choose a reason for hiding this comment

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

Are there any unit tests for check backward compatibility for that changes?

virtual StreamMsg get() override
{
cv::GRunArgs res;
for (const auto &rc : desc()) { res.emplace_back(magazine::getArg(mag, rc)); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it possible to make res.reserve(desc.size()) ?

{
set(rcs);
}
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I recommend moving this (input + output) out into separate files also

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Input/Output implementations are executor-specific, maybe no need to move

}
};

void cv::gimpl::GSerialExecutor::initResource(const ade::NodeHandle & nh, const ade::NodeHandle &orig_nh)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not the clearest method name: what kind of resource ? As for me methods with prefix init called at once usually to init something global resource but here we sequencially make initResource in loop.
Can we give more suitable name for that?

// (5), (6)
Input i{m_res, op.in_objects};
Output o{m_res, op.out_objects};
op.isl_exec->run(i, o);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Previously

struct OpDesc
    {
        std::vector<RcDesc> in_objects;
        std::vector<RcDesc> out_objects;
        std::shared_ptr<GIslandExecutable> isl_exec;
    };

I cannot understand an idea: what is the reason to group in_objject, out_objects and isl_exec together and do not use it's coupling benefit. It looks like it should be decoupled or regroupped them in any other way

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is legacy, this executor has been written based on CPU backend so CPU operations turned into "Islands" (but remained "ops" for some reason)

GAPI_Assert(canReshape());
auto& g = *m_orig_graph.get();
ade::passes::PassContext ctx{g};
passes::initMeta(ctx, inMetas);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if this is some kind of checks then should it be done on canReshape part?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not a check

// 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-2022 Intel Corporation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just 2022 I suppose


void cv::gimpl::GSerialExecutor::runImpl(cv::gimpl::GRuntimeArgs &&args)
{
// (2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please, remove those steps or add documentation on them at the begging of the runImpl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather add that documentation piece back :)

// 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-2022 Intel Corporation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2022

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

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

👍 probably the what's needs to be addressed is a comment about serial executor's execution flow

GModel::ConstGraph cgr(*pg);

// FIXME: select which executor will be actually used,
// make GExecutor abstract.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GExecutor is irrelevant here, since this method is about Streaming

}
}

void assignMetaStubExec(Mag& mag, const RcDesc &rc, const cv::GRunArg::Meta &meta) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to do that, Magazine class itself is not bound to its contents (it is template)

}
}

void assignMetaStubExec(Mag& mag, const RcDesc &rc, const cv::GRunArg::Meta &meta) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can consider this as part of further refactoring if ever we'll need it in more than 1 place

{
set(rcs);
}
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Input/Output implementations are executor-specific, maybe no need to move


void cv::gimpl::GSerialExecutor::runImpl(cv::gimpl::GRuntimeArgs &&args)
{
// (2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather add that documentation piece back :)

// (5), (6)
Input i{m_res, op.in_objects};
Output o{m_res, op.out_objects};
op.isl_exec->run(i, o);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is legacy, this executor has been written based on CPU backend so CPU operations turned into "Islands" (but remained "ops" for some reason)

@dmatveev dmatveev self-assigned this Mar 30, 2022
@dmatveev dmatveev added this to the 4.6.0 milestone Mar 30, 2022
} // namespace gimpl
} // namespace cv

#endif // OPENCV_GAPI_GEXECUTOR_HPP
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be aligned with OPENCV_GAPI_SERIAL_EXECUTOR_HPP

or even add _SRC_: OPENCV_GAPI_SRC_SERIAL_EXECUTOR_HPP

@alalek
Copy link
Copy Markdown
Member

alalek commented Apr 1, 2022

Conflicting files
modules/gapi/src/executor/gexecutor.cpp

Please rebase to resolve conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants