Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 1 | // |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NetworkExecutionUtils.hpp" |
| 7 | |
Rob Hughes | 9542f90 | 2021-07-14 09:48:54 +0100 | [diff] [blame] | 8 | #include <armnnUtils/Filesystem.hpp> |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 9 | #include <iterator> |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 10 | std::vector<std::string> ParseStringList(const std::string& inputString, const char* delimiter) |
| 11 | { |
| 12 | std::stringstream stream(inputString); |
| 13 | return ParseArrayImpl<std::string>(stream, [](const std::string& s) { |
| 14 | return armnn::stringUtils::StringTrimCopy(s); }, delimiter); |
| 15 | } |
| 16 | |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 17 | bool CheckInferenceTimeThreshold(const std::chrono::duration<double, std::milli>& duration, |
| 18 | const double& thresholdTime) |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 19 | { |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 20 | ARMNN_LOG(info) << "\nInference time: " << std::setprecision(2) |
| 21 | << std::fixed << duration.count() << " ms\n"; |
| 22 | // If thresholdTime == 0.0 (default), then it hasn't been supplied at command line |
| 23 | if (thresholdTime != 0.0) |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 24 | { |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 25 | ARMNN_LOG(info) << "Threshold time: " << std::setprecision(2) |
| 26 | << std::fixed << thresholdTime << " ms"; |
| 27 | auto thresholdMinusInference = thresholdTime - duration.count(); |
| 28 | ARMNN_LOG(info) << "Threshold time - Inference time: " << std::setprecision(2) |
| 29 | << std::fixed << thresholdMinusInference << " ms" << "\n"; |
| 30 | if (thresholdMinusInference < 0) |
Jan Eilers | 284b5d1 | 2021-09-07 12:46:15 +0100 | [diff] [blame] | 31 | { |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 32 | std::string errorMessage = "Elapsed inference time is greater than provided threshold time."; |
| 33 | ARMNN_LOG(fatal) << errorMessage; |
| 34 | return false; |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 35 | } |
| 36 | } |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 37 | return true; |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | bool ValidatePath(const std::string& file, const bool expectFile) |
| 41 | { |
| 42 | if (!fs::exists(file)) |
| 43 | { |
| 44 | std::cerr << "Given file path '" << file << "' does not exist" << std::endl; |
| 45 | return false; |
| 46 | } |
| 47 | if (!fs::is_regular_file(file) && expectFile) |
| 48 | { |
| 49 | std::cerr << "Given file path '" << file << "' is not a regular file" << std::endl; |
| 50 | return false; |
| 51 | } |
| 52 | return true; |
| 53 | } |
| 54 | |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 55 | std::vector<unsigned int> ParseArray(std::istream& stream) |
| 56 | { |
| 57 | return ParseArrayImpl<unsigned int>( |
| 58 | stream, |
| 59 | [](const std::string& s) { return armnn::numeric_cast<unsigned int>(std::stoi(s)); }); |
| 60 | } |
| 61 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 62 | bool ValidatePaths(const std::vector<std::string>& fileVec, const bool expectFile) |
| 63 | { |
| 64 | bool allPathsValid = true; |
| 65 | for (auto const& file : fileVec) |
| 66 | { |
| 67 | if(!ValidatePath(file, expectFile)) |
| 68 | { |
| 69 | allPathsValid = false; |
| 70 | } |
| 71 | } |
| 72 | return allPathsValid; |
| 73 | } |
| 74 | |
Finn Williams | 452c580 | 2022-06-20 13:48:20 +0100 | [diff] [blame^] | 75 | void LogAndThrow(std::string eMsg) |
| 76 | { |
| 77 | ARMNN_LOG(error) << eMsg; |
| 78 | throw armnn::Exception(eMsg); |
| 79 | } |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 80 | |