| 68 | ArmnnDelegatePlugin::New); |
| 69 | |
| 70 | armnnDelegate::DelegateOptions ParseArmNNSettings(const tflite::TFLiteSettings* tfLiteSettings) |
| 71 | { |
| 72 | const tflite::ArmNNSettings* settings = tfLiteSettings->armnn_settings(); |
| 73 | ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(settings, |
| 74 | "The passed TFLiteSettings did not contain a valid ArmNNSettings"); |
| 75 | |
| 76 | // Extract settings fields |
| 77 | bool fastmath = settings->fastmath(); |
| 78 | std::string backends_str = (settings->backends()) ? settings->backends()->str() : ""; |
| 79 | const ::flatbuffers::String* additional_parameters = settings->additional_parameters(); |
| 80 | |
| 81 | // Build additional parameters string |
| 82 | std::string additional_parameters_str; |
| 83 | if (additional_parameters) |
| 84 | { |
| 85 | additional_parameters_str = additional_parameters->str(); |
| 86 | |
| 87 | // Apply a regex to remove spaces around the = and , signs |
| 88 | std::regex regex_equals_str("[ ]*=[ ]*"); |
| 89 | std::regex regex_comma_str("[ ]*,[ ]*"); |
| 90 | additional_parameters_str = std::regex_replace(additional_parameters_str, regex_equals_str, "="); |
| 91 | additional_parameters_str = std::regex_replace(additional_parameters_str, regex_comma_str, ","); |
| 92 | } |
| 93 | |
| 94 | // Build a std::pair list of option names and values |
| 95 | std::vector<std::pair<std::string, std::string>> options; |
| 96 | options.emplace_back(std::pair<std::string, std::string>("backends", backends_str)); |
| 97 | options.emplace_back(std::pair<std::string, std::string>("enable-fast-math", (fastmath) ? "true" : "false")); |
| 98 | |
| 99 | std::stringstream additional_parameters_ss(additional_parameters_str); |
| 100 | while (additional_parameters_ss.good()) |
| 101 | { |
| 102 | std::string option_str; |
| 103 | getline( additional_parameters_ss, option_str, ',' ); |
| 104 | size_t n = option_str.find("="); |
| 105 | if (n != std::string::npos) |
| 106 | { |
| 107 | std::string name = option_str.substr(0, n); |
| 108 | std::string value = option_str.substr(n + 1, std::string::npos); |
| 109 | options.emplace_back(std::pair<std::string, std::string>(name, value)); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Build the key and value lists to pass into the constructor of the DelegateOptions |
| 114 | size_t num_options = options.size(); |
| 115 | std::unique_ptr<const char*[]> options_keys = std::unique_ptr<const char*[]>(new const char*[num_options + 1]); |
| 116 | std::unique_ptr<const char*[]> options_values = std::unique_ptr<const char*[]>(new const char*[num_options + 1]); |
| 117 | |
| 118 | for (size_t i=0; i<num_options; ++i) |
| 119 | { |
| 120 | options_keys.get()[i] = options[i].first.c_str(); |
| 121 | options_values.get()[i] = options[i].second.c_str(); |
| 122 | } |
| 123 | |
| 124 | // Finally call the constructor |
| 125 | armnnDelegate::DelegateOptions delegateOptions = armnnDelegate::DelegateOptions(options_keys.get(), |
| 126 | options_values.get(), |
| 127 | num_options, |