| 1784 | } |
| 1785 | |
| 1786 | EdgeStrategy CalculateEdgeStrategy(BackendsMap& backends, |
| 1787 | ITensorHandleFactory::FactoryId srcFactoryId, |
| 1788 | const Layer& layer, |
| 1789 | const Layer& connectedLayer, |
| 1790 | TensorHandleFactoryRegistry& registry, |
| 1791 | bool importEnabled) |
| 1792 | { |
| 1793 | auto toBackend = backends.find(connectedLayer.GetBackendId()); |
| 1794 | if (toBackend == backends.end()) |
| 1795 | { |
| 1796 | throw armnn::Exception("Backend id not found for the connected layer"); |
| 1797 | } |
| 1798 | |
| 1799 | auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences(); |
| 1800 | |
| 1801 | // Legacy API check for backward compatibility |
| 1802 | if (srcFactoryId == ITensorHandleFactory::LegacyFactoryId || dstPrefs.empty()) |
| 1803 | { |
| 1804 | if (layer.GetBackendId() != connectedLayer.GetBackendId()) |
| 1805 | { |
| 1806 | return EdgeStrategy::CopyToTarget; |
| 1807 | } |
| 1808 | else |
| 1809 | { |
| 1810 | return EdgeStrategy::DirectCompatibility; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | // TensorHandleFactory API present, so perform more sophisticated strategies. |
| 1815 | // Dst Output layers don't require copy because they use import or map/unmap |
| 1816 | if (connectedLayer.GetType() == LayerType::Output) |
| 1817 | { |
| 1818 | return EdgeStrategy::DirectCompatibility; |
| 1819 | } |
| 1820 | |
| 1821 | // Search for direct match in prefs |
| 1822 | for (auto&& pref : dstPrefs) |
| 1823 | { |
| 1824 | if (pref == srcFactoryId) |
| 1825 | { |
| 1826 | return EdgeStrategy::DirectCompatibility; |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | // Search for export/import options |
| 1831 | ITensorHandleFactory* srcFactory = registry.GetFactory(srcFactoryId); |
| 1832 | if (srcFactory->GetExportFlags() != 0 && importEnabled) |
| 1833 | { |
| 1834 | for (auto&& pref : dstPrefs) |
| 1835 | { |
| 1836 | ITensorHandleFactory* dstFactory = registry.GetFactory(pref); |
| 1837 | |
| 1838 | // Handles cases when a destPref is not listed in TensorHandleFactoryRegistry |
| 1839 | if (!dstFactory) { |
| 1840 | continue; |
| 1841 | } |
| 1842 | if ((dstFactory->GetImportFlags() & srcFactory->GetExportFlags()) != 0) |
| 1843 | { |
no test coverage detected