Criteria -> Criterion

pull/22596/head
TolyaTalamanov 2 years ago
parent e92716a1b6
commit 5f50e7bafe
  1. 10
      modules/gapi/samples/pipeline_modeling_tool.cpp
  2. 20
      modules/gapi/samples/pipeline_modeling_tool/pipeline.hpp
  3. 38
      modules/gapi/samples/pipeline_modeling_tool/pipeline_builder.hpp
  4. 2
      modules/gapi/samples/pipeline_modeling_tool/test_pipeline_modeling_tool.py

@ -373,20 +373,20 @@ int main(int argc, char* argv[]) {
for (const auto& name : exec_list) { for (const auto& name : exec_list) {
const auto& pl_fn = check_and_get_fn(pipelines_fn, name, "Pipelines"); const auto& pl_fn = check_and_get_fn(pipelines_fn, name, "Pipelines");
builder.setName(name); builder.setName(name);
StopCriteria::Ptr stop_criteria; StopCriterion::Ptr stop_criterion;
auto opt_num_iters = readOpt<int>(pl_fn["num_iters"]); auto opt_num_iters = readOpt<int>(pl_fn["num_iters"]);
// NB: num_iters for specific pipeline takes priority over global work_time. // NB: num_iters for specific pipeline takes priority over global work_time.
if (opt_num_iters) { if (opt_num_iters) {
stop_criteria.reset(new NumItersCriteria(opt_num_iters.value())); stop_criterion.reset(new NumItersCriterion(opt_num_iters.value()));
} else if (opt_work_time_mcs) { } else if (opt_work_time_mcs) {
stop_criteria.reset(new ElapsedTimeCriteria(opt_work_time_mcs.value())); stop_criterion.reset(new ElapsedTimeCriterion(opt_work_time_mcs.value()));
} else { } else {
throw std::logic_error( throw std::logic_error(
"Failed: Pipeline " + name + " doesn't have stop criteria!\n" "Failed: Pipeline " + name + " doesn't have stop criterion!\n"
"Please specify either work_time: <value> in the config root" "Please specify either work_time: <value> in the config root"
" or num_iters: <value> for specific pipeline."); " or num_iters: <value> for specific pipeline.");
} }
builder.setStopCriteria(std::move(stop_criteria)); builder.setStopCriterion(std::move(stop_criterion));
// NB: Set source // NB: Set source
{ {

@ -40,14 +40,14 @@ std::string PerfReport::toStr(bool expand) const {
return ss.str(); return ss.str();
} }
class StopCriteria { class StopCriterion {
public: public:
using Ptr = std::unique_ptr<StopCriteria>; using Ptr = std::unique_ptr<StopCriterion>;
virtual void start() = 0; virtual void start() = 0;
virtual void iter() = 0; virtual void iter() = 0;
virtual bool done() = 0; virtual bool done() = 0;
virtual ~StopCriteria() = default; virtual ~StopCriterion() = default;
}; };
class Pipeline { class Pipeline {
@ -57,7 +57,7 @@ public:
Pipeline(std::string&& name, Pipeline(std::string&& name,
cv::GComputation&& comp, cv::GComputation&& comp,
std::shared_ptr<DummySource>&& src, std::shared_ptr<DummySource>&& src,
StopCriteria::Ptr stop_criteria, StopCriterion::Ptr stop_criterion,
cv::GCompileArgs&& args, cv::GCompileArgs&& args,
const size_t num_outputs); const size_t num_outputs);
@ -78,7 +78,7 @@ protected:
std::string m_name; std::string m_name;
cv::GComputation m_comp; cv::GComputation m_comp;
std::shared_ptr<DummySource> m_src; std::shared_ptr<DummySource> m_src;
StopCriteria::Ptr m_stop_criteria; StopCriterion::Ptr m_stop_criterion;
cv::GCompileArgs m_args; cv::GCompileArgs m_args;
size_t m_num_outputs; size_t m_num_outputs;
PerfReport m_perf; PerfReport m_perf;
@ -87,13 +87,13 @@ protected:
Pipeline::Pipeline(std::string&& name, Pipeline::Pipeline(std::string&& name,
cv::GComputation&& comp, cv::GComputation&& comp,
std::shared_ptr<DummySource>&& src, std::shared_ptr<DummySource>&& src,
StopCriteria::Ptr stop_criteria, StopCriterion::Ptr stop_criterion,
cv::GCompileArgs&& args, cv::GCompileArgs&& args,
const size_t num_outputs) const size_t num_outputs)
: m_name(std::move(name)), : m_name(std::move(name)),
m_comp(std::move(comp)), m_comp(std::move(comp)),
m_src(std::move(src)), m_src(std::move(src)),
m_stop_criteria(std::move(stop_criteria)), m_stop_criterion(std::move(stop_criterion)),
m_args(std::move(args)), m_args(std::move(args)),
m_num_outputs(num_outputs) { m_num_outputs(num_outputs) {
m_perf.name = m_name; m_perf.name = m_name;
@ -111,13 +111,13 @@ void Pipeline::run() {
init(); init();
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
m_stop_criteria->start(); m_stop_criterion->start();
while (true) { while (true) {
m_perf.latencies.push_back(run_iter()); m_perf.latencies.push_back(run_iter());
m_perf.elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - start).count(); m_perf.elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - start).count();
m_stop_criteria->iter(); m_stop_criterion->iter();
if (m_stop_criteria->done()) { if (m_stop_criterion->done()) {
deinit(); deinit();
break; break;
} }

@ -262,9 +262,9 @@ struct InferParams {
cv::util::optional<int> out_precision; cv::util::optional<int> out_precision;
}; };
class ElapsedTimeCriteria : public StopCriteria { class ElapsedTimeCriterion : public StopCriterion {
public: public:
ElapsedTimeCriteria(int64_t work_time_mcs); ElapsedTimeCriterion(int64_t work_time_mcs);
void start() override; void start() override;
void iter() override; void iter() override;
@ -276,25 +276,25 @@ private:
int64_t m_curr_ts = -1; int64_t m_curr_ts = -1;
}; };
ElapsedTimeCriteria::ElapsedTimeCriteria(int64_t work_time_mcs) ElapsedTimeCriterion::ElapsedTimeCriterion(int64_t work_time_mcs)
: m_work_time_mcs(work_time_mcs) { : m_work_time_mcs(work_time_mcs) {
}; };
void ElapsedTimeCriteria::start() { void ElapsedTimeCriterion::start() {
m_start_ts = m_curr_ts = utils::timestamp<std::chrono::microseconds>(); m_start_ts = m_curr_ts = utils::timestamp<std::chrono::microseconds>();
} }
void ElapsedTimeCriteria::iter() { void ElapsedTimeCriterion::iter() {
m_curr_ts = utils::timestamp<std::chrono::microseconds>(); m_curr_ts = utils::timestamp<std::chrono::microseconds>();
} }
bool ElapsedTimeCriteria::done() { bool ElapsedTimeCriterion::done() {
return (m_curr_ts - m_start_ts) >= m_work_time_mcs; return (m_curr_ts - m_start_ts) >= m_work_time_mcs;
} }
class NumItersCriteria : public StopCriteria { class NumItersCriterion : public StopCriterion {
public: public:
NumItersCriteria(int64_t num_iters); NumItersCriterion(int64_t num_iters);
void start() override; void start() override;
void iter() override; void iter() override;
@ -305,19 +305,19 @@ private:
int64_t m_curr_iters = 0; int64_t m_curr_iters = 0;
}; };
NumItersCriteria::NumItersCriteria(int64_t num_iters) NumItersCriterion::NumItersCriterion(int64_t num_iters)
: m_num_iters(num_iters) { : m_num_iters(num_iters) {
} }
void NumItersCriteria::start() { void NumItersCriterion::start() {
m_curr_iters = 0; m_curr_iters = 0;
} }
void NumItersCriteria::iter() { void NumItersCriterion::iter() {
++m_curr_iters; ++m_curr_iters;
} }
bool NumItersCriteria::done() { bool NumItersCriterion::done() {
return m_curr_iters == m_num_iters; return m_curr_iters == m_num_iters;
} }
@ -338,7 +338,7 @@ public:
void setDumpFilePath(const std::string& dump); void setDumpFilePath(const std::string& dump);
void setQueueCapacity(const size_t qc); void setQueueCapacity(const size_t qc);
void setName(const std::string& name); void setName(const std::string& name);
void setStopCriteria(StopCriteria::Ptr stop_criteria); void setStopCriterion(StopCriterion::Ptr stop_criterion);
Pipeline::Ptr build(); Pipeline::Ptr build();
@ -366,7 +366,7 @@ private:
std::shared_ptr<DummySource> src; std::shared_ptr<DummySource> src;
PLMode mode = PLMode::STREAMING; PLMode mode = PLMode::STREAMING;
std::string name; std::string name;
StopCriteria::Ptr stop_criteria; StopCriterion::Ptr stop_criterion;
}; };
std::unique_ptr<State> m_state; std::unique_ptr<State> m_state;
@ -493,8 +493,8 @@ void PipelineBuilder::setName(const std::string& name) {
m_state->name = name; m_state->name = name;
} }
void PipelineBuilder::setStopCriteria(StopCriteria::Ptr stop_criteria) { void PipelineBuilder::setStopCriterion(StopCriterion::Ptr stop_criterion) {
m_state->stop_criteria = std::move(stop_criteria); m_state->stop_criterion = std::move(stop_criterion);
} }
static bool visit(Node::Ptr node, static bool visit(Node::Ptr node,
@ -655,7 +655,7 @@ Pipeline::Ptr PipelineBuilder::construct() {
} }
} }
GAPI_Assert(m_state->stop_criteria); GAPI_Assert(m_state->stop_criterion);
if (m_state->mode == PLMode::STREAMING) { if (m_state->mode == PLMode::STREAMING) {
GAPI_Assert(graph_inputs.size() == 1); GAPI_Assert(graph_inputs.size() == 1);
GAPI_Assert(cv::util::holds_alternative<cv::GMat>(graph_inputs[0])); GAPI_Assert(cv::util::holds_alternative<cv::GMat>(graph_inputs[0]));
@ -671,7 +671,7 @@ Pipeline::Ptr PipelineBuilder::construct() {
cv::GProtoInputArgs{graph_inputs}, cv::GProtoInputArgs{graph_inputs},
cv::GProtoOutputArgs{graph_outputs}), cv::GProtoOutputArgs{graph_outputs}),
std::move(m_state->src), std::move(m_state->src),
std::move(m_state->stop_criteria), std::move(m_state->stop_criterion),
std::move(m_state->compile_args), std::move(m_state->compile_args),
graph_outputs.size()); graph_outputs.size());
} }
@ -681,7 +681,7 @@ Pipeline::Ptr PipelineBuilder::construct() {
cv::GProtoInputArgs{graph_inputs}, cv::GProtoInputArgs{graph_inputs},
cv::GProtoOutputArgs{graph_outputs}), cv::GProtoOutputArgs{graph_outputs}),
std::move(m_state->src), std::move(m_state->src),
std::move(m_state->stop_criteria), std::move(m_state->stop_criterion),
std::move(m_state->compile_args), std::move(m_state->compile_args),
graph_outputs.size()); graph_outputs.size());
} }

@ -1000,4 +1000,4 @@ Pipelines:
exec_str = '{} --cfg={}'.format(pipeline_modeling_tool, cfg_file) exec_str = '{} --cfg={}'.format(pipeline_modeling_tool, cfg_file)
out = get_output(exec_str) out = get_output(exec_str)
assert out.startswith('Failed: Pipeline PL1 doesn\'t have stop criteria!') assert out.startswith('Failed: Pipeline PL1 doesn\'t have stop criterion!')

Loading…
Cancel
Save