| 110 | TfLiteStatus BenchmarkModel::ResetInputsAndOutputs() { return kTfLiteOk; } |
| 111 | |
| 112 | Stat<int64_t> BenchmarkModel::Run(int min_num_times, float min_secs, |
| 113 | float max_secs, RunType run_type, |
| 114 | TfLiteStatus* invoke_status) { |
| 115 | Stat<int64_t> run_stats; |
| 116 | TFLITE_LOG(INFO) << "Running benchmark for at least " << min_num_times |
| 117 | << " iterations and at least " << min_secs << " seconds but" |
| 118 | << " terminate if exceeding " << max_secs << " seconds."; |
| 119 | int64_t now_us = profiling::time::NowMicros(); |
| 120 | int64_t min_finish_us = now_us + static_cast<int64_t>(min_secs * 1.e6f); |
| 121 | int64_t max_finish_us = now_us + static_cast<int64_t>(max_secs * 1.e6f); |
| 122 | |
| 123 | *invoke_status = kTfLiteOk; |
| 124 | for (int run = 0; (run < min_num_times || now_us < min_finish_us) && |
| 125 | now_us <= max_finish_us; |
| 126 | run++) { |
| 127 | ResetInputsAndOutputs(); |
| 128 | listeners_.OnSingleRunStart(run_type); |
| 129 | int64_t start_us = profiling::time::NowMicros(); |
| 130 | TfLiteStatus status = RunImpl(); |
| 131 | int64_t end_us = profiling::time::NowMicros(); |
| 132 | listeners_.OnSingleRunEnd(); |
| 133 | |
| 134 | run_stats.UpdateStat(end_us - start_us); |
| 135 | util::SleepForSeconds(params_.Get<float>("run_delay")); |
| 136 | now_us = profiling::time::NowMicros(); |
| 137 | |
| 138 | if (status != kTfLiteOk) { |
| 139 | *invoke_status = status; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | std::stringstream stream; |
| 144 | run_stats.OutputToStream(&stream); |
| 145 | TFLITE_LOG(INFO) << stream.str() << std::endl; |
| 146 | |
| 147 | return run_stats; |
| 148 | } |
| 149 | |
| 150 | TfLiteStatus BenchmarkModel::ValidateParams() { return kTfLiteOk; } |
| 151 | |