| 41 | |
| 42 | #if defined(ETHOS_U_NPU_ENABLED) |
| 43 | int PmuStrToInt(const char* str, size_t maxVal, const std::string& errorPrefix) |
| 44 | { |
| 45 | int value = 0; |
| 46 | |
| 47 | try { |
| 48 | value = std::stoi(str); |
| 49 | } catch (const std::out_of_range&) { |
| 50 | throw std::runtime_error("Error: " + errorPrefix + " out of range value " + str); |
| 51 | } catch (const std::exception&) { |
| 52 | throw std::runtime_error("Error: " + errorPrefix + " non-numeric value " + str); |
| 53 | } |
| 54 | |
| 55 | if (value < 0 || static_cast<size_t>(value) > maxVal) { |
| 56 | throw std::runtime_error("Error: " + errorPrefix + " " + str + " is out of range [0 - " + |
| 57 | std::to_string(maxVal) + "]"); |
| 58 | } |
| 59 | |
| 60 | return value; |
| 61 | } |
| 62 | |
| 63 | bool ParsePmuArg(const char* counterIdxArg, |
| 64 | const char* eventIdArg, |