| 67 | } |
| 68 | |
| 69 | EdgeID Graph::add_connection(NodeID source, size_t source_idx, NodeID sink, size_t sink_idx) |
| 70 | { |
| 71 | arm_compute::lock_guard<arm_compute::Mutex> lock(_mtx); |
| 72 | |
| 73 | // Check if node index is valid, if node exists and finally if the connection index is valid |
| 74 | ARM_COMPUTE_ERROR_ON((source >= _nodes.size()) || (_nodes[source] == nullptr) || |
| 75 | (source_idx >= _nodes[source]->num_outputs())); |
| 76 | ARM_COMPUTE_ERROR_ON((sink >= _nodes.size()) || (_nodes[sink] == nullptr) || |
| 77 | (sink_idx >= _nodes[sink]->num_inputs())); |
| 78 | |
| 79 | // Get nodes |
| 80 | std::unique_ptr<INode> &source_node = _nodes[source]; |
| 81 | std::unique_ptr<INode> &sink_node = _nodes[sink]; |
| 82 | |
| 83 | // Check for duplicate connections (Check only sink node) |
| 84 | Edge *sink_node_edge = sink_node->input_edge(sink_idx); |
| 85 | if ((sink_node_edge != nullptr) && (sink_node_edge->producer_id() == source) && |
| 86 | (sink_node_edge->producer_idx() == source_idx) && (sink_node_edge->consumer_id() == sink) && |
| 87 | (sink_node_edge->consumer_idx() == sink_idx)) |
| 88 | { |
| 89 | return sink_node_edge->id(); |
| 90 | } |
| 91 | |
| 92 | // Check if there is already a tensor associated with output if not create one |
| 93 | TensorID tid = source_node->output_id(source_idx); |
| 94 | if (tid == NullTensorID) |
| 95 | { |
| 96 | tid = create_tensor(); |
| 97 | } |
| 98 | std::unique_ptr<Tensor> &tensor = _tensors[tid]; |
| 99 | |
| 100 | // Create connections |
| 101 | EdgeID eid = _edges.size(); |
| 102 | auto connection = |
| 103 | std::make_unique<Edge>(eid, source_node.get(), source_idx, sink_node.get(), sink_idx, tensor.get()); |
| 104 | _edges.push_back(std::move(connection)); |
| 105 | |
| 106 | // Add connections to source and sink nodes |
| 107 | source_node->_output_edges.insert(eid); |
| 108 | sink_node->_input_edges[sink_idx] = eid; |
| 109 | |
| 110 | // Set tensor output node |
| 111 | source_node->_outputs[source_idx] = tid; |
| 112 | |
| 113 | // Bind tensor to the edge |
| 114 | tensor->bind_edge(eid); |
| 115 | |
| 116 | // Try and propagate shapes in sink node |
| 117 | sink_node->forward_descriptors(); |
| 118 | |
| 119 | return eid; |
| 120 | } |
| 121 | |
| 122 | bool Graph::remove_connection(EdgeID eid) |
| 123 | { |
no test coverage detected