For all handle factories supported on the source backend, we wish to find the one which requires the fewest copies when considering all connections.
| 1631 | // For all handle factories supported on the source backend, we wish to find the one which requires the fewest copies |
| 1632 | // when considering all connections. |
| 1633 | ITensorHandleFactory::FactoryId CalculateSlotOption(BackendsMap& backends, |
| 1634 | OutputSlot& outputSlot, |
| 1635 | TensorHandleFactoryRegistry& registry, |
| 1636 | bool exportEnabled) |
| 1637 | { |
| 1638 | // First ensure the from backends can support the TensorHandeAPI |
| 1639 | Layer& layer = outputSlot.GetOwningLayer(); |
| 1640 | auto frmBackend = backends.find(layer.GetBackendId()); |
| 1641 | if (frmBackend == backends.end() || |
| 1642 | !frmBackend->second->SupportsTensorAllocatorAPI()) |
| 1643 | { |
| 1644 | return ITensorHandleFactory::LegacyFactoryId; |
| 1645 | } |
| 1646 | |
| 1647 | bool outputConnection = false; |
| 1648 | for (auto&& connection : outputSlot.GetConnections()) |
| 1649 | { |
| 1650 | const Layer& connectedLayer = connection->GetOwningLayer(); |
| 1651 | if (connectedLayer.GetType() == LayerType::Output) |
| 1652 | { |
| 1653 | outputConnection = true; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | IBackendInternal* srcBackend = frmBackend->second.get(); |
| 1658 | auto srcPrefs = srcBackend->GetHandleFactoryPreferences(); |
| 1659 | |
| 1660 | // Initialize the scores |
| 1661 | std::map<ITensorHandleFactory::FactoryId, int> factoryScores; |
| 1662 | for (auto&& pref : srcPrefs) |
| 1663 | { |
| 1664 | if (exportEnabled) |
| 1665 | { |
| 1666 | ITensorHandleFactory* factory = registry.GetFactory(pref); |
| 1667 | if (outputConnection) |
| 1668 | { |
| 1669 | // Check if this is fallback case |
| 1670 | bool fallbackConnection = false; |
| 1671 | for (auto&& inputSlot : layer.GetInputSlots()) |
| 1672 | { |
| 1673 | if (inputSlot.GetConnectedOutputSlot()->GetOwningLayer().GetBackendId() != layer.GetBackendId()) |
| 1674 | { |
| 1675 | fallbackConnection = true; |
| 1676 | } |
| 1677 | } |
| 1678 | if (fallbackConnection) |
| 1679 | { |
| 1680 | auto factoryCap = factory->GetCapabilities(&layer, &layer, CapabilityClass::FallbackImportDisabled); |
| 1681 | // Cannot use factory import if fallback import is not supported. |
| 1682 | if (!factoryCap.empty()) |
| 1683 | { |
| 1684 | continue; |
| 1685 | } |
| 1686 | } |
| 1687 | else if (factory->GetExportFlags() == 0) |
| 1688 | { |
| 1689 | continue; |
| 1690 | } |
no test coverage detected