mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Implement asynchronous execution for islands
This commit is contained in:
committed by
Ruslan Garnov
parent
cb5921b375
commit
b1f42a6506
@@ -327,13 +327,36 @@ void GIslandExecutable::run(GIslandExecutable::IInput &in, GIslandExecutable::IO
|
||||
std::vector<OutObj> out_objs;
|
||||
const auto &in_desc = in.desc();
|
||||
const auto &out_desc = out.desc();
|
||||
const auto in_vector = in.get(); // FIXME: passing temporary objects to toRange() leads to issues
|
||||
const auto in_msg = in.get();
|
||||
if (cv::util::holds_alternative<cv::gimpl::EndOfStream>(in_msg))
|
||||
{
|
||||
out.post(cv::gimpl::EndOfStream{});
|
||||
return;
|
||||
}
|
||||
GAPI_Assert(cv::util::holds_alternative<cv::GRunArgs>(in_msg));
|
||||
const auto in_vector = cv::util::get<cv::GRunArgs>(in_msg);
|
||||
in_objs.reserve(in_desc.size());
|
||||
out_objs.reserve(out_desc.size());
|
||||
for (auto &&it: ade::util::zip(ade::util::toRange(in_desc),
|
||||
ade::util::toRange(in_vector)))
|
||||
{
|
||||
in_objs.emplace_back(std::get<0>(it), std::get<1>(it));
|
||||
// FIXME: Not every Island expects a cv::Mat instead of own::Mat on input
|
||||
// This kludge should go as a result of de-ownification
|
||||
const cv::GRunArg& in_data_orig = std::get<1>(it);
|
||||
cv::GRunArg in_data;
|
||||
switch (in_data_orig.index())
|
||||
{
|
||||
case cv::GRunArg::index_of<cv::Mat>():
|
||||
in_data = cv::GRunArg{cv::to_own(cv::util::get<cv::Mat>(in_data_orig))};
|
||||
break;
|
||||
case cv::GRunArg::index_of<cv::Scalar>():
|
||||
in_data = cv::GRunArg{(cv::util::get<cv::Scalar>(in_data_orig))};
|
||||
break;
|
||||
default:
|
||||
in_data = in_data_orig;
|
||||
break;
|
||||
}
|
||||
in_objs.emplace_back(std::get<0>(it), std::move(in_data));
|
||||
}
|
||||
for (auto &&it: ade::util::indexed(ade::util::toRange(out_desc)))
|
||||
{
|
||||
|
||||
@@ -151,15 +151,18 @@ public:
|
||||
void set(const std::vector<cv::gimpl::RcDesc> &newd) { d = newd; }
|
||||
const std::vector<cv::gimpl::RcDesc> &desc() const { return d; }
|
||||
};
|
||||
struct EndOfStream {};
|
||||
using StreamMsg = cv::util::variant<EndOfStream, cv::GRunArgs>;
|
||||
struct GIslandExecutable::IInput: public GIslandExecutable::IODesc {
|
||||
virtual ~IInput() = default;
|
||||
virtual cv::GRunArgs get() = 0; // Get a new input vector (blocking)
|
||||
virtual cv::GRunArgs try_get() = 0; // Get a new input vector (non-blocking)
|
||||
virtual StreamMsg get() = 0; // Get a new input vector (blocking)
|
||||
virtual StreamMsg try_get() = 0; // Get a new input vector (non-blocking)
|
||||
};
|
||||
struct GIslandExecutable::IOutput: public GIslandExecutable::IODesc {
|
||||
virtual ~IOutput() = default;
|
||||
virtual GRunArgP get(int idx) = 0; // Allocate (wrap) a new data object for output idx
|
||||
virtual void post(GRunArgP&&) = 0; // Release the object back to the framework (mark available)
|
||||
virtual void post(EndOfStream&&) = 0; // Post end-of-stream marker back to the framework
|
||||
};
|
||||
|
||||
// GIslandEmitter - a backend-specific thing which feeds data into
|
||||
|
||||
Reference in New Issue
Block a user