| 160 | } |
| 161 | |
| 162 | OptimizationViews MockBackend::OptimizeSubgraphView(const SubgraphView& subgraph) const |
| 163 | { |
| 164 | // Prepare the optimization views |
| 165 | OptimizationViews optimizationViews; |
| 166 | |
| 167 | // Get the layers of the input sub-graph |
| 168 | const SubgraphView::IConnectableLayers& subgraphLayers = subgraph.GetIConnectableLayers(); |
| 169 | |
| 170 | // Parse the layers |
| 171 | SubgraphView::IConnectableLayers supportedLayers; |
| 172 | SubgraphView::IConnectableLayers unsupportedLayers; |
| 173 | SubgraphView::IConnectableLayers untouchedLayers; |
| 174 | std::for_each(subgraphLayers.begin(), |
| 175 | subgraphLayers.end(), |
| 176 | [&](IConnectableLayer* layer) |
| 177 | { |
| 178 | bool supported = IsLayerSupported(PolymorphicDowncast<Layer*>(layer)); |
| 179 | if (supported) |
| 180 | { |
| 181 | // Layer supported, check if it's optimizable |
| 182 | bool optimizable = IsLayerOptimizable(PolymorphicDowncast<Layer*>(layer)); |
| 183 | if (optimizable) |
| 184 | { |
| 185 | // Layer fully supported |
| 186 | supportedLayers.push_back(layer); |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | // Layer supported but not optimizable |
| 191 | untouchedLayers.push_back(layer); |
| 192 | } |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | // Layer unsupported |
| 197 | unsupportedLayers.push_back(layer); |
| 198 | } |
| 199 | }); |
| 200 | |
| 201 | // Check if there are supported layers |
| 202 | if (!supportedLayers.empty()) |
| 203 | { |
| 204 | // Select the layers that are neither inputs or outputs, but that are optimizable |
| 205 | auto supportedSubgraphSelector = [](const Layer& layer) |
| 206 | { |
| 207 | return layer.GetType() != LayerType::Input && |
| 208 | layer.GetType() != LayerType::Output && |
| 209 | IsLayerSupported(layer) && |
| 210 | IsLayerOptimizable(layer); |
| 211 | }; |
| 212 | |
| 213 | // Apply the subgraph selector to the supported layers to group them into sub-graphs were appropriate |
| 214 | SubgraphView mutableSubgraph(subgraph); |
| 215 | SubgraphViewSelector::Subgraphs supportedSubgraphs = |
| 216 | SubgraphViewSelector::SelectSubgraphs(mutableSubgraph, supportedSubgraphSelector); |
| 217 | |
| 218 | // Create a substitution pair for each supported sub-graph |
| 219 | std::for_each(supportedSubgraphs.begin(), |
no test coverage detected