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) {
const auto& pl_fn = check_and_get_fn(pipelines_fn, name, "Pipelines");
builder.setName(name);
StopCriteria::Ptr stop_criteria;
StopCriterion::Ptr stop_criterion;
auto opt_num_iters = readOpt<int>(pl_fn["num_iters"]);
// NB: num_iters for specific pipeline takes priority over global work_time.
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) {
stop_criteria.reset(new ElapsedTimeCriteria(opt_work_time_mcs.value()));
stop_criterion.reset(new ElapsedTimeCriterion(opt_work_time_mcs.value()));
} else {
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"
" or num_iters: <value> for specific pipeline.");
}
builder.setStopCriteria(std::move(stop_criteria));
builder.setStopCriterion(std::move(stop_criterion));
// NB: Set source
{

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

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

@ -1000,4 +1000,4 @@ Pipelines:
exec_str = '{} --cfg={}'.format(pipeline_modeling_tool, cfg_file)
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