* This function performs a sanity check to ensure that the combination of input and output memory source matches the * values for importEnabled and exportEnabled that were specified during optimization. During optimization the tensor * handle factories are chosen based on whether import and export are enabled. If the user then specifies something * incompatible here it can lead to problems. *
| 96 | * @param networkProperties |
| 97 | */ |
| 98 | void ValidateSourcesMatchOptimizedNetwork(std::vector<BackendOptions> optimizedOptions, |
| 99 | const INetworkProperties& networkProperties) |
| 100 | { |
| 101 | // Find the "Global" backend options. During the optimize phase the values of importEnabled and exportEnabled are |
| 102 | // added as backend options. |
| 103 | const vector<BackendOptions>::iterator& backendItr = |
| 104 | find_if(optimizedOptions.begin(), optimizedOptions.end(), [](const BackendOptions& backend) { |
| 105 | if (backend.GetBackendId().Get() == "Global") |
| 106 | { |
| 107 | return true; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | return false; |
| 112 | } |
| 113 | }); |
| 114 | bool importEnabled = false; |
| 115 | bool exportEnabled = false; |
| 116 | if (backendItr != optimizedOptions.end()) |
| 117 | { |
| 118 | // Find the importEnabled and exportEnabled values. |
| 119 | for (size_t i = 0; i < backendItr->GetOptionCount(); i++) |
| 120 | { |
| 121 | const BackendOptions::BackendOption& option = backendItr->GetOption(i); |
| 122 | if (option.GetName() == "ImportEnabled") |
| 123 | { |
| 124 | importEnabled = option.GetValue().AsBool(); |
| 125 | } |
| 126 | if (option.GetName() == "ExportEnabled") |
| 127 | { |
| 128 | exportEnabled = option.GetValue().AsBool(); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Now that we have values for import and export compare them to the MemorySource variables. |
| 134 | // Any value of MemorySource that's not "Undefined" implies that we need to do an import of some kind. |
| 135 | if ((networkProperties.m_InputSource == MemorySource::Undefined && importEnabled) || |
| 136 | (networkProperties.m_InputSource != MemorySource::Undefined && !importEnabled)) |
| 137 | { |
| 138 | auto message = fmt::format("The input memory source specified, '{0}',", networkProperties.m_InputSource); |
| 139 | if (!importEnabled) |
| 140 | { |
| 141 | message.append(" requires that memory import be enabled. However, " |
| 142 | "it was disabled when this network was optimized."); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | message.append(" requires that memory import be disabled. However, " |
| 147 | "it was enabled when this network was optimized."); |
| 148 | } |
| 149 | throw InvalidArgumentException(message); |
| 150 | } |
| 151 | |
| 152 | if ((networkProperties.m_OutputSource == MemorySource::Undefined && exportEnabled) || |
| 153 | (networkProperties.m_OutputSource != MemorySource::Undefined && !exportEnabled)) |
| 154 | { |
| 155 | auto message = fmt::format("The output memory source specified, '{0}',", networkProperties.m_OutputSource); |
no test coverage detected