Fluid Internal Parallelism:

- add comments on signature of custom parallel_for
  - use cv::parallel_for_ by default
pull/15443/head
Anton Potapov 5 years ago
parent 55c1720719
commit 758156a9b6
  1. 5
      modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp
  2. 26
      modules/gapi/src/backends/fluid/gfluidbackend.cpp

@ -106,7 +106,10 @@ struct GFluidParallelOutputRois
struct GFluidParallelFor
{
std::function<void(std::size_t, std::function<void(std::size_t)>)> parallel_for;
//this function accepts:
// - size of the "parallel" range as the first argument
// - and a function to be called on the range items, designated by item index
std::function<void(std::size_t size, std::function<void(std::size_t index)>)> parallel_for;
};
namespace detail

@ -16,6 +16,7 @@
#include <ade/util/algorithm.hpp>
#include <ade/util/chain_range.hpp>
#include <ade/util/iota_range.hpp>
#include <ade/util/range.hpp>
#include <ade/util/zip_range.hpp>
@ -96,12 +97,31 @@ namespace
const auto parallel_out_rois = cv::gimpl::getCompileArg<cv::GFluidParallelOutputRois>(args);
const auto gpfor = cv::gimpl::getCompileArg<cv::GFluidParallelFor>(args);
auto serial_for = [](std::size_t count, std::function<void(std::size_t)> f){
for (std::size_t i = 0; i < count; ++i){
#if !defined(GAPI_STANDALONE)
auto default_pfor = [](std::size_t count, std::function<void(std::size_t)> f){
struct Body : cv::ParallelLoopBody {
decltype(f) func;
Body( decltype(f) && _f) : func(_f){}
virtual void operator() (const cv::Range& r) const CV_OVERRIDE
{
for (std::size_t i : ade::util::iota(r.start, r.end))
{
func(i);
}
}
};
cv::parallel_for_(cv::Range{0,static_cast<int>(count)}, Body{std::move(f)});
};
#else
auto default_pfor = [](std::size_t count, std::function<void(std::size_t)> f){
for (auto i : ade::util::iota(count)){
f(i);
}
};
auto pfor = gpfor.has_value() ? gpfor.value().parallel_for : serial_for;
#endif
auto pfor = gpfor.has_value() ? gpfor.value().parallel_for : default_pfor;
return parallel_out_rois.has_value() ?
EPtr{new cv::gimpl::GParallelFluidExecutable (graph, graph_data, std::move(parallel_out_rois.value().parallel_rois), pfor)}
: EPtr{new cv::gimpl::GFluidExecutable (graph, graph_data, std::move(rois.rois))}

Loading…
Cancel
Save