Commit 89f23a35 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #15091 from anton-potapov:fluid_internal_parallellism_custom_pfor

parents 79310a00 8936d556
...@@ -104,12 +104,23 @@ struct GFluidParallelOutputRois ...@@ -104,12 +104,23 @@ struct GFluidParallelOutputRois
std::vector<GFluidOutputRois> parallel_rois; std::vector<GFluidOutputRois> parallel_rois;
}; };
struct GFluidParallelFor
{
std::function<void(std::size_t, std::function<void(std::size_t)>)> parallel_for;
};
namespace detail namespace detail
{ {
template<> struct CompileArgTag<GFluidOutputRois> template<> struct CompileArgTag<GFluidOutputRois>
{ {
static const char* tag() { return "gapi.fluid.outputRois"; } static const char* tag() { return "gapi.fluid.outputRois"; }
}; };
template<> struct CompileArgTag<GFluidParallelFor>
{
static const char* tag() { return "gapi.fluid.parallelFor"; }
};
template<> struct CompileArgTag<GFluidParallelOutputRois> template<> struct CompileArgTag<GFluidParallelOutputRois>
{ {
static const char* tag() { return "gapi.fluid.parallelOutputRois"; } static const char* tag() { return "gapi.fluid.parallelOutputRois"; }
......
...@@ -94,8 +94,16 @@ namespace ...@@ -94,8 +94,16 @@ namespace
auto graph_data = fluidExtractInputDataFromGraph(graph, nodes); auto graph_data = fluidExtractInputDataFromGraph(graph, nodes);
const auto parallel_out_rois = cv::gimpl::getCompileArg<cv::GFluidParallelOutputRois>(args); 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){
f(i);
}
};
auto pfor = gpfor.has_value() ? gpfor.value().parallel_for : serial_for;
return parallel_out_rois.has_value() ? return parallel_out_rois.has_value() ?
EPtr{new cv::gimpl::GParallelFluidExecutable (graph, graph_data, std::move(parallel_out_rois.value().parallel_rois))} 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))} : EPtr{new cv::gimpl::GFluidExecutable (graph, graph_data, std::move(rois.rois))}
; ;
} }
...@@ -1325,7 +1333,9 @@ void cv::gimpl::GFluidExecutable::run(std::vector<InObj> &input_objs, ...@@ -1325,7 +1333,9 @@ void cv::gimpl::GFluidExecutable::run(std::vector<InObj> &input_objs,
cv::gimpl::GParallelFluidExecutable::GParallelFluidExecutable(const ade::Graph &g, cv::gimpl::GParallelFluidExecutable::GParallelFluidExecutable(const ade::Graph &g,
const FluidGraphInputData &graph_data, const FluidGraphInputData &graph_data,
const std::vector<GFluidOutputRois> &parallelOutputRois) const std::vector<GFluidOutputRois> &parallelOutputRois,
const decltype(parallel_for) &pfor)
: parallel_for(pfor)
{ {
for (auto&& rois : parallelOutputRois){ for (auto&& rois : parallelOutputRois){
tiles.emplace_back(new GFluidExecutable(g, graph_data, rois.rois)); tiles.emplace_back(new GFluidExecutable(g, graph_data, rois.rois));
...@@ -1342,10 +1352,10 @@ void cv::gimpl::GParallelFluidExecutable::reshape(ade::Graph&, const GCompileArg ...@@ -1342,10 +1352,10 @@ void cv::gimpl::GParallelFluidExecutable::reshape(ade::Graph&, const GCompileArg
void cv::gimpl::GParallelFluidExecutable::run(std::vector<InObj> &&input_objs, void cv::gimpl::GParallelFluidExecutable::run(std::vector<InObj> &&input_objs,
std::vector<OutObj> &&output_objs) std::vector<OutObj> &&output_objs)
{ {
for (auto& tile : tiles ){ parallel_for(tiles.size(), [&, this](std::size_t index){
GAPI_Assert((bool)tile); GAPI_Assert((bool)tiles[index]);
tile->run(input_objs, output_objs); tiles[index]->run(input_objs, output_objs);
} });
} }
......
...@@ -166,10 +166,12 @@ class GParallelFluidExecutable final: public GIslandExecutable { ...@@ -166,10 +166,12 @@ class GParallelFluidExecutable final: public GIslandExecutable {
GParallelFluidExecutable(const GParallelFluidExecutable&) = delete; // due std::unique_ptr in members list GParallelFluidExecutable(const GParallelFluidExecutable&) = delete; // due std::unique_ptr in members list
std::vector<std::unique_ptr<GFluidExecutable>> tiles; std::vector<std::unique_ptr<GFluidExecutable>> tiles;
decltype(GFluidParallelFor::parallel_for) parallel_for;
public: public:
GParallelFluidExecutable(const ade::Graph &g, GParallelFluidExecutable(const ade::Graph &g,
const FluidGraphInputData &graph_data, const FluidGraphInputData &graph_data,
const std::vector<GFluidOutputRois> &parallelOutputRois); const std::vector<GFluidOutputRois> &parallelOutputRois,
const decltype(parallel_for) &pfor);
virtual inline bool canReshape() const override { return false; } virtual inline bool canReshape() const override { return false; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment