From d64444ba197c2f95dcf4d205f50a196d5a29cdeb Mon Sep 17 00:00:00 2001 From: thecha01 Date: Mon, 7 Sep 2020 14:50:21 +0100 Subject: Add Reduction operation layer node to graph API Signed-off-by: thecha01 Change-Id: Ida819fb8c33790cc9da6d69eeb51e0599269197a Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3931 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- arm_compute/graph/backends/FunctionHelpers.h | 44 ++++++++++++++++++++++++++++ arm_compute/graph/backends/ValidateHelpers.h | 24 +++++++++++++++ 2 files changed, 68 insertions(+) (limited to 'arm_compute/graph/backends') diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h index d8873c0363..e8395e4e92 100644 --- a/arm_compute/graph/backends/FunctionHelpers.h +++ b/arm_compute/graph/backends/FunctionHelpers.h @@ -1478,6 +1478,50 @@ std::unique_ptr create_quantization_layer(QuantizationLayerNode &node return RETURN_UNIQUE_PTR(func); } +/** Create a backend reduction operation layer function + * + * @tparam ReductionOperationFunction Backend reduction operation function + * @tparam TargetInfo Target-specific information + * + * @param[in] node Node to create the backend function for + * @param[in] ctx Graph context + * + * @return Backend reduction sum layer function + */ +template +std::unique_ptr create_reduction_operation_layer(ReductionLayerNode &node, GraphContext &ctx) +{ + validate_node(node, 1 /* expected inputs */, 1 /* expected outputs */); + + // Extract IO and info + typename TargetInfo::TensorType *input = get_backing_tensor(node.input(0)); + typename TargetInfo::TensorType *output = get_backing_tensor(node.output(0)); + ReductionOperation op = node.op(); + int axis = node.axis(); + bool keep_dims = node.keep_dims(); + ARM_COMPUTE_ERROR_ON(input == nullptr); + ARM_COMPUTE_ERROR_ON(output == nullptr); + + // Create and configure function + auto func = support::cpp14::make_unique(get_memory_manager(ctx, TargetInfo::TargetType)); + func->configure(input, output, axis, op, keep_dims); + + // Log info + ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " + << node.name() + << " Type: " << node.type() + << " Target: " << TargetInfo::TargetType + << " Data Type: " << input->info()->data_type() + << " Input shape: " << input->info()->tensor_shape() + << " Output shape: " << output->info()->tensor_shape() + << " Operation: " << op + << " Axis: " << axis + << " Keep dimensions:" << keep_dims + << std::endl); + + return RETURN_UNIQUE_PTR(func); +} + /** Create a backend reorg layer function * * @tparam ReorgLayerFunction Backend reorg function diff --git a/arm_compute/graph/backends/ValidateHelpers.h b/arm_compute/graph/backends/ValidateHelpers.h index 1d5fd92838..dd519fbd5e 100644 --- a/arm_compute/graph/backends/ValidateHelpers.h +++ b/arm_compute/graph/backends/ValidateHelpers.h @@ -509,6 +509,30 @@ Status validate_quantization_layer(QuantizationLayerNode &node) return QuantizationLayer::validate(input, output); } +/** Validates a Reduction operation layer node + * + * @tparam ReductionLayer Reduction layer type + * + * @param[in] node Node to validate + * + * @return Status + */ +template +Status validate_reduction_operation_layer(ReductionLayerNode &node) +{ + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReductionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); + + ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); + ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); + + // Extract input and output + arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); + arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); + + // Validate function + return ReductionLayer::validate(input, output, node.axis(), node.op(), node.keep_dims()); +} + /** Validates a Reorg layer node * * @tparam ReorgLayer Reorg layer type -- cgit v1.2.1