From 4a6d9e85a9cb2e199d20b06e5450036c3b83b91d Mon Sep 17 00:00:00 2001 From: ramelg01 Date: Sat, 2 Oct 2021 14:34:36 +0100 Subject: Provide logging for configure functions in all CPP functions - Moving impl of CPPSplit template to src/runtime/CPP to allow including of Log.h from src/common. - Fix logging of vector to print contained tensor's info not their ptrs. Partially-Resovles: COMPMID-4718 Signed-off-by: Ramy Elgammal Change-Id: Idec81665b2a7c0cfae5248803109c6e2edc520a1 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6362 Comments-Addressed: Arm Jenkins Reviewed-by: Pablo Marquez Tello Tested-by: Arm Jenkins --- .../CPPBoxWithNonMaximaSuppressionLimit.cpp | 10 +- .../CPP/functions/CPPDetectionOutputLayer.cpp | 9 +- .../CPP/functions/CPPDetectionPostProcessLayer.cpp | 12 +- .../CPP/functions/CPPNonMaximumSuppression.cpp | 6 +- src/runtime/CPP/functions/CPPPermute.cpp | 6 +- src/runtime/CPP/functions/CPPSplit.cpp | 186 +++++++++++++++++++++ src/runtime/CPP/functions/CPPTopKV.cpp | 6 +- src/runtime/CPP/functions/CPPUpsample.cpp | 6 +- 8 files changed, 229 insertions(+), 12 deletions(-) create mode 100644 src/runtime/CPP/functions/CPPSplit.cpp (limited to 'src/runtime/CPP/functions') diff --git a/src/runtime/CPP/functions/CPPBoxWithNonMaximaSuppressionLimit.cpp b/src/runtime/CPP/functions/CPPBoxWithNonMaximaSuppressionLimit.cpp index b6803d0d37..dccbe4045d 100644 --- a/src/runtime/CPP/functions/CPPBoxWithNonMaximaSuppressionLimit.cpp +++ b/src/runtime/CPP/functions/CPPBoxWithNonMaximaSuppressionLimit.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 Arm Limited. + * Copyright (c) 2018-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -26,6 +26,8 @@ #include "arm_compute/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.h" #include "arm_compute/runtime/Scheduler.h" +#include "src/common/utils/Log.h" + namespace arm_compute { namespace @@ -130,10 +132,12 @@ CPPBoxWithNonMaximaSuppressionLimit::CPPBoxWithNonMaximaSuppressionLimit(std::sh { } -void CPPBoxWithNonMaximaSuppressionLimit::configure(const ITensor *scores_in, const ITensor *boxes_in, const ITensor *batch_splits_in, ITensor *scores_out, ITensor *boxes_out, ITensor *classes, - ITensor *batch_splits_out, ITensor *keeps, ITensor *keeps_size, const BoxNMSLimitInfo info) +void CPPBoxWithNonMaximaSuppressionLimit::configure(const ITensor *scores_in, const ITensor *boxes_in, const ITensor *batch_splits_in, + ITensor *scores_out, ITensor *boxes_out, ITensor *classes, ITensor *batch_splits_out, + ITensor *keeps, ITensor *keeps_size, const BoxNMSLimitInfo info) { ARM_COMPUTE_ERROR_ON_NULLPTR(scores_in, boxes_in, scores_out, boxes_out, classes); + ARM_COMPUTE_LOG_PARAMS(scores_in, boxes_in, batch_splits_in, scores_out, boxes_out, classes, batch_splits_out, keeps, keeps_size, info); _is_qasymm8 = scores_in->info()->data_type() == DataType::QASYMM8 || scores_in->info()->data_type() == DataType::QASYMM8_SIGNED; diff --git a/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp b/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp index fdb4c9f0f6..41d875eb97 100644 --- a/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp +++ b/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 Arm Limited. + * Copyright (c) 2018-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -28,6 +28,8 @@ #include "arm_compute/core/Validate.h" #include "src/core/helpers/AutoConfiguration.h" +#include "src/common/utils/Log.h" + #include namespace arm_compute @@ -388,9 +390,12 @@ CPPDetectionOutputLayer::CPPDetectionOutputLayer() { } -void CPPDetectionOutputLayer::configure(const ITensor *input_loc, const ITensor *input_conf, const ITensor *input_priorbox, ITensor *output, DetectionOutputLayerInfo info) +void CPPDetectionOutputLayer::configure(const ITensor *input_loc, const ITensor *input_conf, const ITensor *input_priorbox, + ITensor *output, DetectionOutputLayerInfo info) { ARM_COMPUTE_ERROR_ON_NULLPTR(input_loc, input_conf, input_priorbox, output); + ARM_COMPUTE_LOG_PARAMS(input_loc, input_conf, input_priorbox, output, info); + // Output auto initialization if not yet initialized // Since the number of bboxes to kept is unknown before nms, the shape is set to the maximum // The maximum is keep_top_k * input_loc_size[1] diff --git a/src/runtime/CPP/functions/CPPDetectionPostProcessLayer.cpp b/src/runtime/CPP/functions/CPPDetectionPostProcessLayer.cpp index 31f1fafd69..ecbc49b3c1 100644 --- a/src/runtime/CPP/functions/CPPDetectionPostProcessLayer.cpp +++ b/src/runtime/CPP/functions/CPPDetectionPostProcessLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -28,6 +28,8 @@ #include "arm_compute/core/Validate.h" #include "src/core/helpers/AutoConfiguration.h" +#include "src/common/utils/Log.h" + #include #include #include @@ -213,10 +215,14 @@ CPPDetectionPostProcessLayer::CPPDetectionPostProcessLayer(std::shared_ptrinfo(), TensorInfo(TensorShape(_kNumCoordBox, _num_max_detected_boxes, _kBatchSize), 1, DataType::F32)); diff --git a/src/runtime/CPP/functions/CPPNonMaximumSuppression.cpp b/src/runtime/CPP/functions/CPPNonMaximumSuppression.cpp index d0d0b1e98b..6d01b127c0 100644 --- a/src/runtime/CPP/functions/CPPNonMaximumSuppression.cpp +++ b/src/runtime/CPP/functions/CPPNonMaximumSuppression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,12 +25,16 @@ #include "arm_compute/core/CPP/kernels/CPPNonMaximumSuppressionKernel.h" +#include "src/common/utils/Log.h" + namespace arm_compute { void CPPNonMaximumSuppression::configure( const ITensor *bboxes, const ITensor *scores, ITensor *indices, unsigned int max_output_size, const float score_threshold, const float nms_threshold) { + ARM_COMPUTE_LOG_PARAMS(bboxes, scores, indices, max_output_size, score_threshold, nms_threshold); + auto k = std::make_unique(); k->configure(bboxes, scores, indices, max_output_size, score_threshold, nms_threshold); _kernel = std::move(k); diff --git a/src/runtime/CPP/functions/CPPPermute.cpp b/src/runtime/CPP/functions/CPPPermute.cpp index 76fa09f12b..83941f1dc1 100644 --- a/src/runtime/CPP/functions/CPPPermute.cpp +++ b/src/runtime/CPP/functions/CPPPermute.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Arm Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,10 +25,14 @@ #include "arm_compute/core/CPP/kernels/CPPPermuteKernel.h" +#include "src/common/utils/Log.h" + using namespace arm_compute; void CPPPermute::configure(const ITensor *input, ITensor *output, const PermutationVector &perm) { + ARM_COMPUTE_LOG_PARAMS(input, output, perm); + auto k = std::make_unique(); k->configure(input, output, perm); _kernel = std::move(k); diff --git a/src/runtime/CPP/functions/CPPSplit.cpp b/src/runtime/CPP/functions/CPPSplit.cpp new file mode 100644 index 0000000000..98af8ad971 --- /dev/null +++ b/src/runtime/CPP/functions/CPPSplit.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2021 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 OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/runtime/CPP/functions/CPPSplit.h" + +#ifdef ARM_COMPUTE_CPU_ENABLED // NEON Build is activated +#include "arm_compute/runtime/NEON/functions/NESlice.h" +#endif /* ARM_COMPUTE_CPU_ENABLED */ + +#ifdef ARM_COMPUTE_OPENCL_ENABLED // OPENCL build is activated +#include "arm_compute/runtime/CL/functions/CLSlice.h" +#endif /* ARM_COMPUTE_OPENCL_ENABLED */ + +#include "src/common/utils/Log.h" + +namespace arm_compute +{ +/** Basic function to split a tensor along a given axis */ + +template +CPPSplit::CPPSplit() + : _outputs_vector(), _slice_functions(), _num_outputs(0) +{ +} + +template +Status CPPSplit::validate(const ITensorInfo *input, const std::vector &outputs, unsigned int axis) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); + ARM_COMPUTE_RETURN_ERROR_ON(axis >= input->num_dimensions()); + ARM_COMPUTE_RETURN_ERROR_ON(outputs.size() < 2); + + // Get output shape + TensorShape output_shape{}; + unsigned int total_output_shape_size = 0; + + // Sum the output sizes and fall back to evenly-sized splits if any are zero + const bool using_split_shapes = std::none_of(outputs.begin(), outputs.end(), [&total_output_shape_size](ITensorInfo * info) + { + unsigned int output_shape_size = info->tensor_shape().total_size(); + total_output_shape_size += output_shape_size; + return output_shape_size == 0; + }); + + if(using_split_shapes) + { + ARM_COMPUTE_RETURN_ERROR_ON(input->tensor_shape().total_size() != total_output_shape_size); + } + else + { + output_shape = arm_compute::misc::shape_calculator::compute_split_shape(input, axis, outputs.size()); + ARM_COMPUTE_RETURN_ERROR_ON(output_shape.total_size() == 0); + } + + // Validate output tensors + unsigned int axis_offset = 0; + for(const auto &output : outputs) + { + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); + if(using_split_shapes) + { + output_shape = output->tensor_shape(); + ARM_COMPUTE_RETURN_ERROR_ON(output_shape.total_size() == 0); + } + + const size_t axis_split_step = output_shape[axis]; + + // Start/End coordinates + Coordinates start_coords; + Coordinates end_coords; + for(unsigned int d = 0; d < output_shape.num_dimensions(); ++d) + { + end_coords.set(d, -1); + } + + // Output auto inizialitation if not yet initialized + TensorInfo tmp_output_info = *output->clone(); + if(tmp_output_info.tensor_shape().total_size() == 0) + { + tmp_output_info = input->clone()->set_is_resizable(true).set_tensor_shape(output_shape); + } + + // Update coordinate on axis + start_coords.set(axis, axis_offset); + end_coords.set(axis, axis_offset + axis_split_step); + + ARM_COMPUTE_RETURN_ON_ERROR(SliceType::validate(input, output, start_coords, end_coords)); + axis_offset += axis_split_step; + } + + return Status{}; +} + +template +void CPPSplit::configure(const TensorInterfaceType *input, const std::vector &outputs, unsigned int axis) +{ + // (TensorInterfaceType*) + ARM_COMPUTE_LOG_PARAMS(input, outputs, axis); + + // Create Slice functions + _num_outputs = outputs.size(); + _slice_functions.resize(_num_outputs); + + // Extract output tensor info + std::vector outputs_info; + for(auto &output : outputs) + { + ARM_COMPUTE_ERROR_ON_NULLPTR(output); + outputs_info.emplace_back(output->info()); + } + + // If any of the outputs have a zero size, fall-back to using evenly-sized output splits + const bool outputs_have_sizes = std::none_of(outputs_info.begin(), outputs_info.end(), [](ITensorInfo * info) + { + return info->tensor_shape().total_size() == 0; + }); + + // Validate + ARM_COMPUTE_ERROR_THROW_ON(CPPSplit::validate(input->info(), outputs_info, axis)); + + unsigned int axis_offset = 0; + unsigned int i = 0; + + for(const auto &output_info : outputs_info) + { + // Get output shape + TensorShape output_shape = (outputs_have_sizes ? + output_info->tensor_shape() : + arm_compute::misc::shape_calculator::compute_split_shape(input->info(), axis, _num_outputs)); + + const size_t axis_split_step = output_shape[axis]; + + // Start/End coordinates + Coordinates start_coords; + Coordinates end_coords; + + for(unsigned int d = 0; d < output_shape.num_dimensions(); ++d) + { + end_coords.set(d, -1); + } + + // Update coordinate on axis + start_coords.set(axis, axis_offset); + end_coords.set(axis, axis_offset + axis_split_step); + + // Configure slice function + _slice_functions[i].configure(input, outputs[i], start_coords, end_coords); + + // Set valid region from shape + outputs[i]->info()->set_valid_region(ValidRegion(Coordinates(), output_shape)); + + // Update axis offset + axis_offset += axis_split_step; + ++i; + } +} + +// Instantiate CPPSplit for NESlice and CLSlice types to enable linking to the above templated CPPSplit's methods +#ifdef ARM_COMPUTE_CPU_ENABLED // NEON Build is activated +template class CPPSplit; +#endif /* ARM_COMPUTE_CPU_ENABLED */ + +#ifdef ARM_COMPUTE_OPENCL_ENABLED // OPENCL build is activated +template class CPPSplit; +#endif /* ARM_COMPUTE_OPENCL_ENABLED */ +} // namespace arm_compute diff --git a/src/runtime/CPP/functions/CPPTopKV.cpp b/src/runtime/CPP/functions/CPPTopKV.cpp index 2547e56a1d..62a74735a2 100644 --- a/src/runtime/CPP/functions/CPPTopKV.cpp +++ b/src/runtime/CPP/functions/CPPTopKV.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,10 +25,14 @@ #include "arm_compute/core/CPP/kernels/CPPTopKVKernel.h" +#include "src/common/utils/Log.h" + namespace arm_compute { void CPPTopKV::configure(const ITensor *predictions, const ITensor *targets, ITensor *output, const unsigned int k) { + ARM_COMPUTE_LOG_PARAMS(predictions, targets, output, k); + auto kernel = std::make_unique(); kernel->configure(predictions, targets, output, k); _kernel = std::move(kernel); diff --git a/src/runtime/CPP/functions/CPPUpsample.cpp b/src/runtime/CPP/functions/CPPUpsample.cpp index 3b4ba2ba42..8f72473aeb 100644 --- a/src/runtime/CPP/functions/CPPUpsample.cpp +++ b/src/runtime/CPP/functions/CPPUpsample.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Arm Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,10 +25,14 @@ #include "arm_compute/core/CPP/kernels/CPPUpsampleKernel.h" +#include "src/common/utils/Log.h" + using namespace arm_compute; void CPPUpsample::configure(const ITensor *input, ITensor *output, const PadStrideInfo &info) { + ARM_COMPUTE_LOG_PARAMS(input, output, info); + auto k = std::make_unique(); k->configure(input, output, info); _kernel = std::move(k); -- cgit v1.2.1