From 7e8f508765632c42cc44fd8ad704c9d90943ab32 Mon Sep 17 00:00:00 2001 From: Davide Grohmann Date: Wed, 23 Mar 2022 12:48:45 +0100 Subject: Add support for inference cancellation Send cancel inference messages to the ethosu subsystem to abort inference execution there. Also mark inference as aborted in the linux driver stack itself, so pending inference messages are not resent when resetting the firmware. Change-Id: I244c2b119fd7995d14e3859815abf2a00c7f0583 --- utils/inference_runner/inference_runner.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'utils') diff --git a/utils/inference_runner/inference_runner.cpp b/utils/inference_runner/inference_runner.cpp index 21e133c..9df67ed 100644 --- a/utils/inference_runner/inference_runner.cpp +++ b/utils/inference_runner/inference_runner.cpp @@ -259,22 +259,29 @@ int main(int argc, char *argv[]) { /* make sure the wait completes ok */ try { cout << "Wait for inference" << endl; - inference->wait(timeout); + bool timedout = inference->wait(timeout); + if (timedout) { + cout << "Inference timed out, cancelling it" << endl; + bool aborted = inference->cancel(); + if (!aborted || inference->status() != InferenceStatus::ABORTED) { + cout << "Inference cancellation failed" << endl; + } + } } catch (std::exception &e) { - cout << "Failed to wait for inference completion: " << e.what() << endl; + cout << "Failed to wait for or to cancel inference: " << e.what() << endl; exit(1); } cout << "Inference status: " << inference->status() << endl; - string ofmFilename = ofmArg + "." + to_string(ofmIndex); - ofstream ofmStream(ofmFilename, ios::binary); - if (!ofmStream.is_open()) { - cerr << "Error: Failed to open '" << ofmFilename << "'" << endl; - exit(1); - } - if (inference->status() == InferenceStatus::OK) { + string ofmFilename = ofmArg + "." + to_string(ofmIndex); + ofstream ofmStream(ofmFilename, ios::binary); + if (!ofmStream.is_open()) { + cerr << "Error: Failed to open '" << ofmFilename << "'" << endl; + exit(1); + } + /* The inference completed and has ok status */ for (auto &ofmBuffer : inference->getOfmBuffers()) { cout << "OFM size: " << ofmBuffer->size() << endl; @@ -286,6 +293,8 @@ int main(int argc, char *argv[]) { ofmStream.write(ofmBuffer->data(), ofmBuffer->size()); } + ofmStream.flush(); + /* Read out PMU counters if configured */ if (std::count(enabledCounters.begin(), enabledCounters.end(), 0) < Inference::getMaxPmuEventCounters()) { -- cgit v1.2.1