| 48 | } |
| 49 | |
| 50 | void SplitLayerSubTensorMutator::mutate(Graph &g) |
| 51 | { |
| 52 | // Early exit if no Split layers exist in graph |
| 53 | if (g.nodes(NodeType::SplitLayer).empty()) |
| 54 | { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // Perform topological sort |
| 59 | std::vector<NodeID> topological_sorted_node_ids = dfs(g); |
| 60 | |
| 61 | // Should be in reverse order of execution |
| 62 | for (auto &node_id : arm_compute::utils::iterable::reverse_iterate(topological_sorted_node_ids)) |
| 63 | { |
| 64 | INode *node = g.node(node_id); |
| 65 | if (node != nullptr && node->type() == NodeType::SplitLayer && node->input(0) != nullptr) |
| 66 | { |
| 67 | // Get output tensor |
| 68 | Tensor *input_tensor = node->input(0); |
| 69 | |
| 70 | // Check that all tensor have the same target and are valid |
| 71 | bool is_valid = std::all_of(node->outputs().cbegin(), node->outputs().cend(), |
| 72 | [&](const TensorID &tid) { |
| 73 | return (g.tensor(tid) != nullptr) && |
| 74 | (g.tensor(tid)->desc().target == input_tensor->desc().target); |
| 75 | }); |
| 76 | |
| 77 | // Create subtensors |
| 78 | if (is_valid && is_target_supported(input_tensor->desc().target)) |
| 79 | { |
| 80 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Using sub-tensors for the node with ID : " |
| 81 | << node->id() << " and name : " << node->name() << std::endl); |
| 82 | |
| 83 | auto *split_node = arm_compute::utils::cast::polymorphic_downcast<SplitLayerNode *>(node); |
| 84 | |
| 85 | const int axis = split_node->axis(); |
| 86 | const unsigned int num_splits = split_node->num_splits(); |
| 87 | const bool extend_parent = (axis < 2); |
| 88 | |
| 89 | // Create sub-tensor handles |
| 90 | for (unsigned int i = 0; i < node->outputs().size(); ++i) |
| 91 | { |
| 92 | Tensor *output_tensor = node->output(i); |
| 93 | const TensorShape output_shape = output_tensor->desc().shape; |
| 94 | Coordinates coords; |
| 95 | std::tie(std::ignore, coords) = |
| 96 | split_node->compute_output_descriptor(input_tensor->desc(), num_splits, axis, i); |
| 97 | |
| 98 | backends::IDeviceBackend &backend = |
| 99 | backends::BackendRegistry::get().get_backend(output_tensor->desc().target); |
| 100 | std::unique_ptr<ITensorHandle> handle = |
| 101 | backend.create_subtensor(input_tensor->handle(), output_shape, coords, extend_parent); |
| 102 | output_tensor->set_handle(std::move(handle)); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
nothing calls this directly
no test coverage detected