From d3a78ab634d3047bcb1615512b1b290dbfbca5f4 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 18 Jun 2018 15:35:09 +0100 Subject: COMPMID-1283: (GitHub issue) after convolution output data is zero During the mutating passes accessors of optimized nodes were dropped instead of being transfered to appropriate tensors. Change-Id: I29183984d94806bdfb5c92af3acefd928c0fd171 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/136036 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- arm_compute/graph/Tensor.h | 7 ++++ src/graph/Tensor.cpp | 5 +++ src/graph/Utils.cpp | 2 +- src/graph/mutators/InPlaceOperationMutator.cpp | 25 +++++++++++--- src/graph/mutators/NodeFusionMutator.cpp | 47 ++++++++++++++++++-------- 5 files changed, 65 insertions(+), 21 deletions(-) diff --git a/arm_compute/graph/Tensor.h b/arm_compute/graph/Tensor.h index 5199ac2328..54fb2583e7 100644 --- a/arm_compute/graph/Tensor.h +++ b/arm_compute/graph/Tensor.h @@ -82,6 +82,13 @@ public: * @return Backend tensor accessor */ ITensorAccessor *accessor(); + /** Extracts accessor from the tensor + * + * @warning Accessor gets unbound from the tensor + * + * @return The accessor of the tensor + */ + std::unique_ptr extract_accessor(); /** Calls accessor on tensor * * @return True if the accessor was called else false diff --git a/src/graph/Tensor.cpp b/src/graph/Tensor.cpp index 287e783c26..ef253feb2c 100644 --- a/src/graph/Tensor.cpp +++ b/src/graph/Tensor.cpp @@ -67,6 +67,11 @@ ITensorAccessor *Tensor::accessor() return _accessor.get(); } +std::unique_ptr Tensor::extract_accessor() +{ + return std::move(_accessor); +} + bool Tensor::call_accessor() { // Early exit guard diff --git a/src/graph/Utils.cpp b/src/graph/Utils.cpp index 030fa2df59..d5ca77db1c 100644 --- a/src/graph/Utils.cpp +++ b/src/graph/Utils.cpp @@ -80,8 +80,8 @@ PassManager create_default_pass_manager(Target target) if(target != Target::GC) { - pm.append(support::cpp14::make_unique()); pm.append(support::cpp14::make_unique()); + pm.append(support::cpp14::make_unique()); pm.append(support::cpp14::make_unique()); pm.append(support::cpp14::make_unique()); } diff --git a/src/graph/mutators/InPlaceOperationMutator.cpp b/src/graph/mutators/InPlaceOperationMutator.cpp index bd3f098965..31921b328e 100644 --- a/src/graph/mutators/InPlaceOperationMutator.cpp +++ b/src/graph/mutators/InPlaceOperationMutator.cpp @@ -50,11 +50,26 @@ void InPlaceOperationMutator::mutate(Graph &g) // Check if parent has a single output if yes then force in place calculation else not if((input_edge != nullptr) && (input_edge->producer() != nullptr) && (input_edge->producer()->output_edges().size() == 1)) { - ARM_COMPUTE_LOG_GRAPH_VERBOSE("Switching to in-place computation for the node with ID : " - << node->id() << " and name : " << node->name() << std::endl); - // Update output - auto tensor = input_edge->tensor(); - node->set_output_tensor(tensor->id(), 0); + // Get current and new output tensors + auto current_output_tensor = node->output(0); + auto new_output_tensor = input_edge->tensor(); + + ARM_COMPUTE_ERROR_ON(current_output_tensor == nullptr || new_output_tensor == nullptr); + + // Prevent in-place operation if there is an accessor bound to the in-place tensor + if(new_output_tensor->accessor() == nullptr) + { + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Switching to in-place computation for the node with ID : " + << node->id() << " and name : " << node->name() << std::endl); + // Update accessor + new_output_tensor->set_accessor(current_output_tensor->extract_accessor()); + // Update output + node->set_output_tensor(new_output_tensor->id(), 0); + } + else + { + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Prevented in-place operation as there is an accessor bound to the input tensor\n"); + } } } } diff --git a/src/graph/mutators/NodeFusionMutator.cpp b/src/graph/mutators/NodeFusionMutator.cpp index 2e893c2e07..39209d2f49 100644 --- a/src/graph/mutators/NodeFusionMutator.cpp +++ b/src/graph/mutators/NodeFusionMutator.cpp @@ -54,28 +54,45 @@ void fuse_batch_norm_with_activation(Graph &g) auto *bn_node = arm_compute::utils::cast::polymorphic_downcast(output_edge->producer()); auto *act_node = arm_compute::utils::cast::polymorphic_downcast(output_edge->consumer()); - // Get driving nodes of activation node - std::vector act_driving_nodes; - for(auto &act_output_edge_id : act_node->output_edges()) + ARM_COMPUTE_ERROR_ON(act_node->output(0) == nullptr || bn_node->output(0) == nullptr); + + // Prevent fusion if batch normalization node has an output accessor + if(bn_node->output(0)->accessor() == nullptr) { - auto act_output_edge = g.edge(act_output_edge_id); - if(act_output_edge != nullptr) + // Get driving nodes of activation node + std::vector act_driving_nodes; + for(auto &act_output_edge_id : act_node->output_edges()) { - ARM_COMPUTE_ERROR_ON(act_output_edge->consumer() == nullptr); - act_driving_nodes.push_back({ act_output_edge->consumer_id(), act_output_edge->consumer_idx() }); + auto act_output_edge = g.edge(act_output_edge_id); + if(act_output_edge != nullptr) + { + ARM_COMPUTE_ERROR_ON(act_output_edge->consumer() == nullptr); + act_driving_nodes.push_back( + { act_output_edge->consumer_id(), act_output_edge->consumer_idx() }); + } } - } - // Set activation info to batch normalization - bn_node->set_fused_activation(act_node->activation_info()); + // Set activation info to batch normalization + bn_node->set_fused_activation(act_node->activation_info()); - // Remove activation node - g.remove_node(act_node->id()); + // Extract activation node accessor if any + auto act_node_accessor = act_node->output(0)->extract_accessor(); - // Update batch normalization node outputs - for(auto &driving_node : act_driving_nodes) + // Remove activation node + g.remove_node(act_node->id()); + + // Update batch normalization node outputs + for(auto &driving_node : act_driving_nodes) + { + g.add_connection(bn_node->id(), 0, driving_node.node_id, driving_node.index); + } + + // Update accessor to batch normalization node + bn_node->output(0)->set_accessor(std::move(act_node_accessor)); + } + else { - g.add_connection(bn_node->id(), 0, driving_node.node_id, driving_node.index); + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Prevented fusion as batch normalization node has an output accessor\n"); } } } -- cgit v1.2.1