MCPcopy Create free account
hub / github.com/ARM-software/armnn / SelectTensorHandleStrategy

Function SelectTensorHandleStrategy

src/armnn/Network.cpp:1878–1947  ·  view source on GitHub ↗

Select the TensorHandleFactories and the corresponding memory strategy

Source from the content-addressed store, hash-verified

1876
1877// Select the TensorHandleFactories and the corresponding memory strategy
1878OptimizationResult SelectTensorHandleStrategy(Graph& optGraph,
1879 BackendsMap& backends,
1880 TensorHandleFactoryRegistry& registry,
1881 bool importEnabled,
1882 bool exportEnabled,
1883 Optional<std::vector<std::string>&> errMessages)
1884{
1885 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Optimizer_SelectTensorHandleStrategy");
1886 OptimizationResult result;
1887
1888 optGraph.ForEachLayer([&backends, &registry, &result, &errMessages, importEnabled, exportEnabled](Layer* layer)
1889 {
1890 // Lets make sure the backend is in our list of supported backends. Something went wrong during backend
1891 // assignment if this check fails
1892 if (backends.find(layer->GetBackendId()) == backends.end())
1893 {
1894 throw armnn::Exception("Backend id not found for the layer");
1895 }
1896
1897 // Check each output separately
1898 for (unsigned int slotIdx = 0; slotIdx < layer->GetNumOutputSlots(); slotIdx++)
1899 {
1900 OutputSlot& outputSlot = layer->GetOutputSlot(slotIdx);
1901
1902 ITensorHandleFactory::FactoryId slotOption = ITensorHandleFactory::LegacyFactoryId;
1903
1904 // Calculate the factory to use which results in the fewest copies being made.
1905 switch(layer->GetType())
1906 {
1907 case LayerType::Input:
1908 slotOption = CalculateSlotOptionForInput(backends, outputSlot, registry, importEnabled);
1909 break;
1910 case LayerType::Output:
1911 slotOption = CalculateSlotOptionForOutput(backends, outputSlot, registry);
1912 break;
1913 default:
1914 slotOption = CalculateSlotOption(backends, outputSlot, registry, exportEnabled);
1915 break;
1916 }
1917 outputSlot.SetTensorHandleFactory(slotOption);
1918
1919 // Now determine the "best" edge strategy for each connection given the slotOption.
1920 unsigned int connectionIdx = 0;
1921 for (auto&& connection : outputSlot.GetConnections())
1922 {
1923 const Layer& connectedLayer = connection->GetOwningLayer();
1924
1925 EdgeStrategy strategy = CalculateEdgeStrategy(backends, slotOption, *layer, connectedLayer,
1926 registry, importEnabled);
1927
1928 if (strategy == EdgeStrategy::Undefined)
1929 {
1930 result.m_Error = true;
1931 if (errMessages)
1932 {
1933 errMessages.value().emplace_back("Could not find valid strategy required for compatibility"
1934 " between backends.");
1935 }

Callers 3

OptimizeFunction · 0.85

Calls 14

CalculateSlotOptionFunction · 0.85
CalculateEdgeStrategyFunction · 0.85
ForEachLayerMethod · 0.80
GetOutputSlotMethod · 0.80
SetEdgeStrategyMethod · 0.80
ExceptionClass · 0.50
GetBackendIdMethod · 0.45
endMethod · 0.45
GetNumOutputSlotsMethod · 0.45

Tested by

no test coverage detected