diff options
author | Davide Grohmann <davide.grohmann@arm.com> | 2022-03-23 12:48:45 +0100 |
---|---|---|
committer | Davide Grohmann <davide.grohmann@arm.com> | 2022-05-05 11:13:04 +0200 |
commit | 7e8f508765632c42cc44fd8ad704c9d90943ab32 (patch) | |
tree | 42dcfb929accf5470d6aa61810da20356c39eb75 /utils | |
parent | 82d225899bd3d4fd07d70cac80f50c1b288dc4a3 (diff) | |
download | ethos-u-linux-driver-stack-7e8f508765632c42cc44fd8ad704c9d90943ab32.tar.gz |
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
Diffstat (limited to 'utils')
-rw-r--r-- | utils/inference_runner/inference_runner.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
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()) { |