From 12be7ab4876f77fecfab903df70791623219b3da Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Tue, 3 Jul 2018 12:06:23 +0100 Subject: COMPMID-1310: Create graph validation executables. Change-Id: I9e0b57b1b83fe5a95777cdaeddba6ecef650bafc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/138697 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- src/graph/Graph.cpp | 10 ++-- src/graph/GraphManager.cpp | 33 +++++++++---- src/graph/Tensor.cpp | 4 +- src/graph/TypeLoader.cpp | 89 +++++++++++++++++++++++++++++++++++ src/graph/detail/ExecutionHelpers.cpp | 25 +++++----- 5 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 src/graph/TypeLoader.cpp (limited to 'src/graph') diff --git a/src/graph/Graph.cpp b/src/graph/Graph.cpp index e1ffeed668..ed24f18943 100644 --- a/src/graph/Graph.cpp +++ b/src/graph/Graph.cpp @@ -41,9 +41,9 @@ bool Graph::remove_node(NodeID nid) std::unique_ptr &node = _nodes[nid]; - // Remove node connections if(node) { + // Remove node connections for(auto &input_eid : node->_input_edges) { remove_connection(input_eid); @@ -52,6 +52,10 @@ bool Graph::remove_node(NodeID nid) { remove_connection(outpud_eid); } + + // Remove nid from tagged nodes + std::vector &tnodes = _tagged_nodes.at(node->type()); + tnodes.erase(std::remove(tnodes.begin(), tnodes.end(), nid), tnodes.end()); } node = nullptr; @@ -164,9 +168,9 @@ GraphID Graph::id() const return _id; } -const std::vector &Graph::inputs() +const std::vector &Graph::nodes(NodeType type) { - return _tagged_nodes[NodeType::Input]; + return _tagged_nodes[type]; } std::vector> &Graph::nodes() diff --git a/src/graph/GraphManager.cpp b/src/graph/GraphManager.cpp index 10661ea275..db6650cf69 100644 --- a/src/graph/GraphManager.cpp +++ b/src/graph/GraphManager.cpp @@ -27,6 +27,7 @@ #include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/Logger.h" #include "arm_compute/graph/PassManager.h" +#include "arm_compute/graph/TypePrinter.h" #include "arm_compute/graph/Utils.h" #include "arm_compute/graph/detail/CrossLayerMemoryManagerHelpers.h" #include "arm_compute/graph/detail/ExecutionHelpers.h" @@ -53,7 +54,12 @@ void GraphManager::finalize_graph(Graph &graph, GraphContext &ctx, PassManager & // Force target to all graph construct // TODO (geopin01) : Support heterogeneous execution - Target forced_target = is_target_supported(target) ? target : get_default_target(); + Target forced_target = target; + if(!is_target_supported(target)) + { + forced_target = get_default_target(); + ARM_COMPUTE_LOG_GRAPH_INFO("Switching target from " << target << " to " << forced_target << std::endl); + } force_target_to_graph(graph, forced_target); // Configure all tensors @@ -103,14 +109,23 @@ void GraphManager::execute_graph(Graph &graph) auto it = _workloads.find(graph.id()); ARM_COMPUTE_ERROR_ON_MSG(it == std::end(_workloads), "Graph is not registered!"); - // Call input accessors - detail::call_all_input_node_accessors(it->second); - - // Run graph - detail::call_all_tasks(it->second); - - // Call output accessors - detail::call_all_output_node_accessors(it->second); + while(true) + { + // Call input accessors + if(!detail::call_all_input_node_accessors(it->second)) + { + return; + } + + // Run graph + detail::call_all_tasks(it->second); + + // Call output accessors + if(!detail::call_all_output_node_accessors(it->second)) + { + return; + } + } } void GraphManager::invalidate_graph(Graph &graph) diff --git a/src/graph/Tensor.cpp b/src/graph/Tensor.cpp index ef253feb2c..98501280af 100644 --- a/src/graph/Tensor.cpp +++ b/src/graph/Tensor.cpp @@ -90,12 +90,12 @@ bool Tensor::call_accessor() } // Call accessor - _accessor->access_tensor(_handle->tensor()); + bool retval = _accessor->access_tensor(_handle->tensor()); // Unmap tensor _handle->unmap(); - return true; + return retval; } void Tensor::bind_edge(EdgeID eid) diff --git a/src/graph/TypeLoader.cpp b/src/graph/TypeLoader.cpp new file mode 100644 index 0000000000..30a3546821 --- /dev/null +++ b/src/graph/TypeLoader.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWNISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/graph/TypeLoader.h" + +#include "arm_compute/core/utils/misc/Utility.h" + +#include + +namespace arm_compute +{ +arm_compute::DataType data_type_from_name(const std::string &name) +{ + static const std::map data_types = + { + { "f16", DataType::F16 }, + { "f32", DataType::F32 }, + { "qasymm8", DataType::QASYMM8 }, + }; + + try + { + return data_types.at(arm_compute::utility::tolower(name)); + } + catch(const std::out_of_range &) + { + throw std::invalid_argument(name); + } +} + +arm_compute::DataLayout data_layout_from_name(const std::string &name) +{ + static const std::map data_layouts = + { + { "nhwc", DataLayout::NHWC }, + { "nchw", DataLayout::NCHW }, + }; + + try + { + return data_layouts.at(arm_compute::utility::tolower(name)); + } + catch(const std::out_of_range &) + { + throw std::invalid_argument(name); + } +} +namespace graph +{ +Target target_from_name(const std::string &name) +{ + static const std::map targets = + { + { "neon", Target::NEON }, + { "cl", Target::CL }, + { "gles", Target::GC }, + }; + + try + { + return targets.at(arm_compute::utility::tolower(name)); + } + catch(const std::out_of_range &) + { + throw std::invalid_argument(name); + } +} +} // namespace graph +} // namespace arm_compute diff --git a/src/graph/detail/ExecutionHelpers.cpp b/src/graph/detail/ExecutionHelpers.cpp index d68092a2e7..6df67fcfec 100644 --- a/src/graph/detail/ExecutionHelpers.cpp +++ b/src/graph/detail/ExecutionHelpers.cpp @@ -206,15 +206,12 @@ void call_all_const_node_accessors(Graph &g) } } -void call_all_input_node_accessors(ExecutionWorkload &workload) +bool call_all_input_node_accessors(ExecutionWorkload &workload) { - for(auto &input : workload.inputs) + return !std::any_of(std::begin(workload.inputs), std::end(workload.inputs), [](Tensor * input_tensor) { - if(input != nullptr) - { - input->call_accessor(); - } - } + return (input_tensor == nullptr) || !input_tensor->call_accessor(); + }); } void prepare_all_tasks(ExecutionWorkload &workload) @@ -256,15 +253,15 @@ void call_all_tasks(ExecutionWorkload &workload) } } -void call_all_output_node_accessors(ExecutionWorkload &workload) +bool call_all_output_node_accessors(ExecutionWorkload &workload) { - for(auto &output : workload.outputs) + bool is_valid = true; + std::for_each(std::begin(workload.outputs), std::end(workload.outputs), [&](Tensor * output_tensor) { - if(output != nullptr) - { - output->call_accessor(); - } - } + is_valid = is_valid && (output_tensor != nullptr) && output_tensor->call_accessor(); + }); + + return is_valid; } } // namespace detail } // namespace graph -- cgit v1.2.1