mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #15907 from rgarnov:rg/unique_ptr_for_priv_in_fluid
This commit is contained in:
commit
ab4dbff150
@ -82,10 +82,13 @@ public:
|
|||||||
Priv& priv(); // internal use only
|
Priv& priv(); // internal use only
|
||||||
const Priv& priv() const; // internal use only
|
const Priv& priv() const; // internal use only
|
||||||
|
|
||||||
View(Priv* p);
|
View(std::unique_ptr<Priv>&& p);
|
||||||
|
View(View&& v);
|
||||||
|
View& operator=(View&& v);
|
||||||
|
~View();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Priv> m_priv;
|
std::unique_ptr<Priv> m_priv;
|
||||||
const Cache* m_cache;
|
const Cache* m_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,6 +115,8 @@ public:
|
|||||||
BorderOpt border);
|
BorderOpt border);
|
||||||
// Constructor for in/out buffers (for tests)
|
// Constructor for in/out buffers (for tests)
|
||||||
Buffer(const cv::gapi::own::Mat &data, bool is_input);
|
Buffer(const cv::gapi::own::Mat &data, bool is_input);
|
||||||
|
~Buffer();
|
||||||
|
Buffer& operator=(Buffer&&);
|
||||||
|
|
||||||
inline uint8_t* OutLineB(int index = 0)
|
inline uint8_t* OutLineB(int index = 0)
|
||||||
{
|
{
|
||||||
@ -134,13 +139,14 @@ public:
|
|||||||
inline const GMatDesc& meta() const { return m_cache->m_desc; }
|
inline const GMatDesc& meta() const { return m_cache->m_desc; }
|
||||||
|
|
||||||
View mkView(int borderSize, bool ownStorage);
|
View mkView(int borderSize, bool ownStorage);
|
||||||
|
void addView(const View* v);
|
||||||
|
|
||||||
class GAPI_EXPORTS Priv; // internal use only
|
class GAPI_EXPORTS Priv; // internal use only
|
||||||
Priv& priv(); // internal use only
|
Priv& priv(); // internal use only
|
||||||
const Priv& priv() const; // internal use only
|
const Priv& priv() const; // internal use only
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Priv> m_priv;
|
std::unique_ptr<Priv> m_priv;
|
||||||
const Cache* m_cache;
|
const Cache* m_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ template<> struct fluid_get_in<cv::GMat>
|
|||||||
{
|
{
|
||||||
static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx)
|
static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx)
|
||||||
{
|
{
|
||||||
return in_args[idx].unsafe_get<cv::gapi::fluid::View>();
|
return *in_args[idx].unsafe_get<cv::gapi::fluid::View*>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -833,7 +833,8 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
|
|||||||
m_num_int_buffers (traverse_res.m_mat_count),
|
m_num_int_buffers (traverse_res.m_mat_count),
|
||||||
m_scratch_users (traverse_res.m_scratch_users),
|
m_scratch_users (traverse_res.m_scratch_users),
|
||||||
m_id_map (traverse_res.m_id_map),
|
m_id_map (traverse_res.m_id_map),
|
||||||
m_all_gmat_ids (traverse_res.m_all_gmat_ids)
|
m_all_gmat_ids (traverse_res.m_all_gmat_ids),
|
||||||
|
m_buffers(m_num_int_buffers + m_scratch_users.size())
|
||||||
{
|
{
|
||||||
GConstFluidModel fg(m_g);
|
GConstFluidModel fg(m_g);
|
||||||
|
|
||||||
@ -857,9 +858,6 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
|
|||||||
// Actually initialize Fluid buffers
|
// Actually initialize Fluid buffers
|
||||||
GAPI_LOG_INFO(NULL, "Initializing " << m_num_int_buffers << " fluid buffer(s)" << std::endl);
|
GAPI_LOG_INFO(NULL, "Initializing " << m_num_int_buffers << " fluid buffer(s)" << std::endl);
|
||||||
|
|
||||||
const std::size_t num_scratch = m_scratch_users.size();
|
|
||||||
m_buffers.resize(m_num_int_buffers + num_scratch);
|
|
||||||
|
|
||||||
// After buffers are allocated, repack: ...
|
// After buffers are allocated, repack: ...
|
||||||
for (auto &agent : m_agents)
|
for (auto &agent : m_agents)
|
||||||
{
|
{
|
||||||
@ -882,10 +880,10 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
|
|||||||
auto inEdge = GModel::getInEdgeByPort(m_g, agent->op_handle, in_idx);
|
auto inEdge = GModel::getInEdgeByPort(m_g, agent->op_handle, in_idx);
|
||||||
auto ownStorage = fg.metadata(inEdge).get<FluidUseOwnBorderBuffer>().use;
|
auto ownStorage = fg.metadata(inEdge).get<FluidUseOwnBorderBuffer>().use;
|
||||||
|
|
||||||
gapi::fluid::View view = buffer.mkView(fu.border_size, ownStorage);
|
|
||||||
// NB: It is safe to keep ptr as view lifetime is buffer lifetime
|
// NB: It is safe to keep ptr as view lifetime is buffer lifetime
|
||||||
agent->in_views[in_idx] = view;
|
agent->in_views[in_idx] = buffer.mkView(fu.border_size, ownStorage);
|
||||||
agent->in_args[in_idx] = GArg(view);
|
agent->in_args[in_idx] = GArg(&agent->in_views[in_idx]);
|
||||||
|
buffer.addView(&agent->in_views[in_idx]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -905,6 +903,7 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
|
|||||||
}
|
}
|
||||||
|
|
||||||
// After parameters are there, initialize scratch buffers
|
// After parameters are there, initialize scratch buffers
|
||||||
|
const std::size_t num_scratch = m_scratch_users.size();
|
||||||
if (num_scratch)
|
if (num_scratch)
|
||||||
{
|
{
|
||||||
GAPI_LOG_INFO(NULL, "Initializing " << num_scratch << " scratch buffer(s)" << std::endl);
|
GAPI_LOG_INFO(NULL, "Initializing " << num_scratch << " scratch buffer(s)" << std::endl);
|
||||||
@ -932,8 +931,8 @@ std::size_t cv::gimpl::GFluidExecutable::total_buffers_size() const
|
|||||||
for (const auto &i : ade::util::indexed(m_buffers))
|
for (const auto &i : ade::util::indexed(m_buffers))
|
||||||
{
|
{
|
||||||
// Check that all internal and scratch buffers are allocated
|
// Check that all internal and scratch buffers are allocated
|
||||||
const auto idx = ade::util::index(i);
|
const auto idx = ade::util::index(i);
|
||||||
const auto b = ade::util::value(i);
|
const auto& b = ade::util::value(i);
|
||||||
if (idx >= m_num_int_buffers ||
|
if (idx >= m_num_int_buffers ||
|
||||||
fg.metadata(m_all_gmat_ids.at(idx)).get<FluidData>().internal == true)
|
fg.metadata(m_all_gmat_ids.at(idx)).get<FluidData>().internal == true)
|
||||||
{
|
{
|
||||||
|
@ -125,7 +125,6 @@ class GFluidExecutable final: public GIslandExecutable
|
|||||||
GModel::ConstGraph m_gm;
|
GModel::ConstGraph m_gm;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<FluidAgent>> m_agents;
|
std::vector<std::unique_ptr<FluidAgent>> m_agents;
|
||||||
std::vector<cv::gapi::fluid::Buffer> m_buffers;
|
|
||||||
|
|
||||||
std::vector<FluidAgent*> m_script;
|
std::vector<FluidAgent*> m_script;
|
||||||
|
|
||||||
@ -138,6 +137,8 @@ class GFluidExecutable final: public GIslandExecutable
|
|||||||
std::unordered_map<int, std::size_t> m_id_map; // GMat id -> buffer idx map
|
std::unordered_map<int, std::size_t> m_id_map; // GMat id -> buffer idx map
|
||||||
std::map<std::size_t, ade::NodeHandle> m_all_gmat_ids;
|
std::map<std::size_t, ade::NodeHandle> m_all_gmat_ids;
|
||||||
|
|
||||||
|
std::vector<cv::gapi::fluid::Buffer> m_buffers;
|
||||||
|
|
||||||
void bindInArg (const RcDesc &rc, const GRunArg &arg);
|
void bindInArg (const RcDesc &rc, const GRunArg &arg);
|
||||||
void bindOutArg(const RcDesc &rc, const GRunArgP &arg);
|
void bindOutArg(const RcDesc &rc, const GRunArgP &arg);
|
||||||
void packArg (GArg &in_arg, const GArg &op_arg);
|
void packArg (GArg &in_arg, const GArg &op_arg);
|
||||||
|
@ -576,7 +576,7 @@ bool fluid::Buffer::Priv::full() const
|
|||||||
{
|
{
|
||||||
// reset with maximum possible value and then find minimum
|
// reset with maximum possible value and then find minimum
|
||||||
slowest_y = m_desc.size.height;
|
slowest_y = m_desc.size.height;
|
||||||
for (const auto &v : m_views) slowest_y = std::min(slowest_y, v.y());
|
for (const auto &v : m_views) slowest_y = std::min(slowest_y, v->y());
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_write_caret + lpi() - slowest_y > m_storage->rows();
|
return m_write_caret + lpi() - slowest_y > m_storage->rows();
|
||||||
@ -608,7 +608,7 @@ void fluid::Buffer::Priv::reset()
|
|||||||
int fluid::Buffer::Priv::size() const
|
int fluid::Buffer::Priv::size() const
|
||||||
{
|
{
|
||||||
std::size_t view_sz = 0;
|
std::size_t view_sz = 0;
|
||||||
for (const auto &v : m_views) view_sz += v.priv().size();
|
for (const auto &v : m_views) view_sz += v->priv().size();
|
||||||
|
|
||||||
auto total = view_sz;
|
auto total = view_sz;
|
||||||
if (m_storage) total += m_storage->size();
|
if (m_storage) total += m_storage->size();
|
||||||
@ -679,6 +679,9 @@ fluid::Buffer::Buffer(const cv::gapi::own::Mat &data, bool is_input)
|
|||||||
m_priv->bindTo(data, is_input);
|
m_priv->bindTo(data, is_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fluid::Buffer::~Buffer() = default;
|
||||||
|
fluid::Buffer& fluid::Buffer::operator=(fluid::Buffer&&) = default;
|
||||||
|
|
||||||
int fluid::Buffer::linesReady() const
|
int fluid::Buffer::linesReady() const
|
||||||
{
|
{
|
||||||
return m_priv->linesReady();
|
return m_priv->linesReady();
|
||||||
@ -689,17 +692,24 @@ int fluid::Buffer::lpi() const
|
|||||||
return m_priv->lpi();
|
return m_priv->lpi();
|
||||||
}
|
}
|
||||||
|
|
||||||
fluid::View::View(Priv* p)
|
fluid::View::View(std::unique_ptr<Priv>&& p)
|
||||||
: m_priv(p), m_cache(&p->cache())
|
: m_priv(std::move(p)), m_cache(&m_priv->cache())
|
||||||
{ /* nothing */ }
|
{ /* nothing */ }
|
||||||
|
|
||||||
|
fluid::View::View(View&&) = default;
|
||||||
|
fluid::View& fluid::View::operator=(View&&) = default;
|
||||||
|
fluid::View::~View() = default;
|
||||||
|
|
||||||
fluid::View fluid::Buffer::mkView(int borderSize, bool ownStorage)
|
fluid::View fluid::Buffer::mkView(int borderSize, bool ownStorage)
|
||||||
{
|
{
|
||||||
// FIXME: logic outside of Priv (because View takes pointer to Buffer)
|
// FIXME: logic outside of Priv (because View takes pointer to Buffer)
|
||||||
auto view = ownStorage ? View(new ViewPrivWithOwnBorder(this, borderSize))
|
return ownStorage ? View(std::unique_ptr<ViewPrivWithOwnBorder>(new ViewPrivWithOwnBorder(this, borderSize)))
|
||||||
: View(new ViewPrivWithoutOwnBorder(this, borderSize));
|
: View(std::unique_ptr<ViewPrivWithoutOwnBorder>(new ViewPrivWithoutOwnBorder(this, borderSize)));
|
||||||
m_priv->addView(view);
|
}
|
||||||
return view;
|
|
||||||
|
void fluid::Buffer::addView(const View* v)
|
||||||
|
{
|
||||||
|
m_priv->addView(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
|
void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
|
||||||
@ -713,7 +723,7 @@ void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
|
|||||||
<<" (phys " << "[" << p.storage().cols() << " x " << p.storage().rows() << "]" << ") :"
|
<<" (phys " << "[" << p.storage().cols() << " x " << p.storage().rows() << "]" << ") :"
|
||||||
<< " w: " << p.m_write_caret
|
<< " w: " << p.m_write_caret
|
||||||
<< ", r: [";
|
<< ", r: [";
|
||||||
for (const auto &v : p.m_views) { os << &v.priv() << ":" << v.y() << " "; }
|
for (const auto &v : p.m_views) { os << &v->priv() << ":" << v->y() << " "; }
|
||||||
os << "], avail: " << buffer.linesReady()
|
os << "], avail: " << buffer.linesReady()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ class GAPI_EXPORTS Buffer::Priv
|
|||||||
|
|
||||||
int m_write_caret = -1;
|
int m_write_caret = -1;
|
||||||
|
|
||||||
std::vector<View> m_views;
|
std::vector<const View*> m_views;
|
||||||
|
|
||||||
std::unique_ptr<BufferStorage> m_storage;
|
std::unique_ptr<BufferStorage> m_storage;
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ public:
|
|||||||
void allocate(BorderOpt border, int border_size, int line_consumption, int skew);
|
void allocate(BorderOpt border, int border_size, int line_consumption, int skew);
|
||||||
void bindTo(const cv::gapi::own::Mat &data, bool is_input);
|
void bindTo(const cv::gapi::own::Mat &data, bool is_input);
|
||||||
|
|
||||||
inline void addView(const View& view) { m_views.push_back(view); }
|
inline void addView(const View* view) { m_views.emplace_back(view); }
|
||||||
|
|
||||||
inline const GMatDesc& meta() const { return m_desc; }
|
inline const GMatDesc& meta() const { return m_desc; }
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ namespace
|
|||||||
GAPI_FLUID_KERNEL(GClone, I::GClone, false)
|
GAPI_FLUID_KERNEL(GClone, I::GClone, false)
|
||||||
{
|
{
|
||||||
static const int Window = 1;
|
static const int Window = 1;
|
||||||
static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer)
|
static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer&)
|
||||||
{
|
{
|
||||||
HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_CLONE);
|
HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_CLONE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user