Skip to content

Commit

Permalink
Add param to execute infer requests at a fixed frequency
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Falkowski <[email protected]>
Signed-off-by: Ooi, Boon Sin <[email protected]>
  • Loading branch information
m-falkowski authored and boonsino committed Sep 27, 2024
1 parent 856b8b0 commit c962946
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/cpp/benchmark_app/benchmark_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ static const char cache_dir_message[] = "Optional. Enables caching of loaded mod
static const char load_from_file_message[] = "Optional. Loads model from file directly without read_model."
" All CNNNetwork options (like re-shape) will be ignored";

/// @brief message for run frequency
static const char run_frequency_message[] =
"Execute at a fixed frequency. Note if the targeted rate per second cannot be reached, "
"the benchmark would start the next run immediately, trying its best to catch up.";

/// @brief message for execution time
static const char execution_time_message[] = "Optional. Time in seconds to execute topology.";

Expand Down Expand Up @@ -307,6 +312,9 @@ DEFINE_string(api, "async", api_message);
/// @brief Number of infer requests in parallel
DEFINE_uint64(nireq, 0, infer_requests_count_message);

/// @brief Execute infer requests at a fixed frequency
DEFINE_double(rfreq, 0, run_frequency_message);

/// @brief Number of streams to use for inference on the CPU (also affects Hetero cases)
DEFINE_string(nstreams, "", infer_num_streams_message);

Expand Down Expand Up @@ -388,6 +396,7 @@ static void show_usage() {
std::cout << " -hint <performance hint> (latency or throughput or cumulative_throughput or none) "
<< hint_message << std::endl;
std::cout << " -niter <integer> " << iterations_count_message << std::endl;
std::cout << " -rfreq \"<float>\" " << run_frequency_message << std::endl;
std::cout << " -t " << execution_time_message << std::endl;
std::cout << std::endl;
std::cout << "Input shapes" << std::endl;
Expand Down
6 changes: 6 additions & 0 deletions samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <utility>
#include <vector>
#include <thread>

// clang-format off
#include "openvino/openvino.hpp"
Expand Down Expand Up @@ -1153,6 +1154,11 @@ int main(int argc, char* argv[]) {

execTime = std::chrono::duration_cast<ns>(Time::now() - startTime).count();
processedFramesN += batchSize;

if (FLAGS_rfreq > 0) {
int64_t nextRunFinishTime = 1/FLAGS_rfreq * processedFramesN * 1.0e9;
std::this_thread::sleep_for(std::chrono::nanoseconds(nextRunFinishTime - execTime));
}
}

// wait the latest inference executions
Expand Down

0 comments on commit c962946

Please sign in to comment.