From 7234ed8c3d07c76963eb3bce9530994421ad7e67 Mon Sep 17 00:00:00 2001 From: Isabella Gottardi Date: Tue, 27 Nov 2018 08:51:10 +0000 Subject: COMPMID-1808: Add Detection Output Layer to the GraphAPI COMPMID-1710: Integrate Detection ouput in MobilenetSSD graph example Change-Id: I384d1eb492ef14ece58f2023ad7bbc16f834450b Reviewed-on: https://review.mlplatform.org/356 Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez Reviewed-by: Georgios Pinitas --- src/graph/backends/CL/CLFunctionsFactory.cpp | 91 ++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'src/graph/backends/CL/CLFunctionsFactory.cpp') diff --git a/src/graph/backends/CL/CLFunctionsFactory.cpp b/src/graph/backends/CL/CLFunctionsFactory.cpp index c37a137cf7..5b329c04be 100644 --- a/src/graph/backends/CL/CLFunctionsFactory.cpp +++ b/src/graph/backends/CL/CLFunctionsFactory.cpp @@ -27,6 +27,7 @@ #include "arm_compute/graph/Graph.h" #include "arm_compute/graph/backends/FunctionHelpers.h" #include "arm_compute/runtime/CL/CLFunctions.h" +#include "arm_compute/runtime/CPP/CPPFunctions.h" using namespace arm_compute::utils::cast; @@ -68,6 +69,94 @@ struct CLEltwiseFunctions using Subtraction = CLArithmeticSubtraction; using Multiplication = CLPixelWiseMultiplication; }; +// TODO (isagot01): Remove once we support heterogeneous scheduling at function level +/** Wrapper for the CPP Function in the OpenCL backend **/ +class CPPWrapperFunction : public IFunction +{ +public: + /* Default constructor */ + CPPWrapperFunction() + : _tensors(), _func(nullptr) + { + } + + void run() override + { + for(auto &tensor : _tensors) + { + tensor->map(CLScheduler::get().queue()); + } + _func->run(); + + for(auto &tensor : _tensors) + { + tensor->unmap(CLScheduler::get().queue()); + } + } + + void register_tensor(ICLTensor *tensor) + { + _tensors.push_back(tensor); + } + + void register_function(std::unique_ptr function) + { + _func = std::move(function); + } + +private: + std::vector _tensors; + std::unique_ptr _func; +}; + +namespace detail +{ +// Specialized functions +template <> +std::unique_ptr create_detection_output_layer(DetectionOutputLayerNode &node) +{ + validate_node(node, 3 /* expected inputs */, 1 /* expected outputs */); + + // Extract IO and info + CLTargetInfo::TensorType *input0 = get_backing_tensor(node.input(0)); + CLTargetInfo::TensorType *input1 = get_backing_tensor(node.input(1)); + CLTargetInfo::TensorType *input2 = get_backing_tensor(node.input(2)); + CLTargetInfo::TensorType *output = get_backing_tensor(node.output(0)); + const DetectionOutputLayerInfo detect_info = node.detection_output_info(); + + ARM_COMPUTE_ERROR_ON(input0 == nullptr); + ARM_COMPUTE_ERROR_ON(input1 == nullptr); + ARM_COMPUTE_ERROR_ON(input2 == nullptr); + ARM_COMPUTE_ERROR_ON(output == nullptr); + + // Create and configure function + auto func = support::cpp14::make_unique(); + func->configure(input0, input1, input2, output, detect_info); + + // Log info + ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " + << node.name() + << " Type: " << node.type() + << " Target: " << CLTargetInfo::TargetType + << " Data Type: " << input0->info()->data_type() + << " Input0 shape: " << input0->info()->tensor_shape() + << " Input1 shape: " << input1->info()->tensor_shape() + << " Input2 shape: " << input2->info()->tensor_shape() + << " Output shape: " << output->info()->tensor_shape() + << " DetectionOutputLayer info: " << detect_info + << std::endl); + + auto wrap_function = support::cpp14::make_unique(); + ; + wrap_function->register_function(std::move(func)); + wrap_function->register_tensor(input0); + wrap_function->register_tensor(input1); + wrap_function->register_tensor(input2); + wrap_function->register_tensor(output); + + return std::move(wrap_function); +} +} // namespace detail std::unique_ptr CLFunctionFactory::create(INode *node, GraphContext &ctx) { @@ -95,6 +184,8 @@ std::unique_ptr CLFunctionFactory::create(INode *node, GraphContext & return detail::create_concatenate_layer(*polymorphic_downcast(node)); case NodeType::DepthwiseConvolutionLayer: return detail::create_depthwise_convolution_layer(*polymorphic_downcast(node)); + case NodeType::DetectionOutputLayer: + return detail::create_detection_output_layer(*polymorphic_downcast(node)); case NodeType::EltwiseLayer: return detail::create_eltwise_layer(*polymorphic_downcast(node)); case NodeType::FlattenLayer: -- cgit v1.2.1