From afd38f0c617d6f89b2b4532c6c44f116617e2b6f Mon Sep 17 00:00:00 2001 From: Felix Thomasmathibalan Date: Wed, 27 Sep 2023 17:46:17 +0100 Subject: Apply clang-format on repository Code is formatted as per a revised clang format configuration file(not part of this delivery). Version 14.0.6 is used. Exclusion List: - files with .cl extension - files that are not strictly C/C++ (e.g. Android.bp, Sconscript ...) And the following directories - compute_kernel_writer/validation/ - tests/ - include/ - src/core/NEON/kernels/convolution/ - src/core/NEON/kernels/arm_gemm/ - src/core/NEON/kernels/arm_conv/ - data/ There will be a follow up for formatting of .cl files and the files under tests/ and compute_kernel_writer/validation/. Signed-off-by: Felix Thomasmathibalan Change-Id: Ib7eb1fcf4e7537b9feaefcfc15098a804a3fde0a Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10391 Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Gunes Bayir --- src/graph/backends/BackendRegistry.cpp | 3 +- src/graph/backends/CL/CLDeviceBackend.cpp | 37 ++++--- src/graph/backends/CL/CLFunctionsFactory.cpp | 151 +++++++++++++++----------- src/graph/backends/CL/CLNodeValidator.cpp | 60 ++++++---- src/graph/backends/CL/CLSubTensorHandle.cpp | 7 +- src/graph/backends/CL/CLTensorHandle.cpp | 9 +- src/graph/backends/NEON/NEDeviceBackend.cpp | 29 +++-- src/graph/backends/NEON/NEFunctionFactory.cpp | 119 ++++++++++++-------- src/graph/backends/NEON/NENodeValidator.cpp | 64 +++++++---- src/graph/backends/NEON/NESubTensorHandle.cpp | 7 +- src/graph/backends/NEON/NETensorHandle.cpp | 10 +- 11 files changed, 296 insertions(+), 200 deletions(-) (limited to 'src/graph/backends') diff --git a/src/graph/backends/BackendRegistry.cpp b/src/graph/backends/BackendRegistry.cpp index 46b4f99e23..bb6af79f8b 100644 --- a/src/graph/backends/BackendRegistry.cpp +++ b/src/graph/backends/BackendRegistry.cpp @@ -31,8 +31,7 @@ namespace graph { namespace backends { -BackendRegistry::BackendRegistry() - : _registered_backends() +BackendRegistry::BackendRegistry() : _registered_backends() { } diff --git a/src/graph/backends/CL/CLDeviceBackend.cpp b/src/graph/backends/CL/CLDeviceBackend.cpp index 01e5ab1730..e27a4109d1 100644 --- a/src/graph/backends/CL/CLDeviceBackend.cpp +++ b/src/graph/backends/CL/CLDeviceBackend.cpp @@ -23,18 +23,17 @@ */ #include "arm_compute/graph/backends/CL/CLDeviceBackend.h" -#include "arm_compute/graph/Graph.h" -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/Logger.h" -#include "arm_compute/graph/Tensor.h" +#include "arm_compute/core/TensorInfo.h" #include "arm_compute/graph/backends/BackendRegistrar.h" #include "arm_compute/graph/backends/CL/CLFunctionFactory.h" #include "arm_compute/graph/backends/CL/CLNodeValidator.h" #include "arm_compute/graph/backends/CL/CLSubTensorHandle.h" #include "arm_compute/graph/backends/CL/CLTensorHandle.h" - -#include "arm_compute/core/TensorInfo.h" +#include "arm_compute/graph/Graph.h" +#include "arm_compute/graph/GraphContext.h" +#include "arm_compute/graph/INode.h" +#include "arm_compute/graph/Logger.h" +#include "arm_compute/graph/Tensor.h" #include "arm_compute/runtime/BlobLifetimeManager.h" #include "arm_compute/runtime/CL/CLBufferAllocator.h" #include "arm_compute/runtime/CL/CLScheduler.h" @@ -64,7 +63,12 @@ bool file_exists(const std::string &filename) static detail::BackendRegistrar CLDeviceBackend_registrar(Target::CL); CLDeviceBackend::CLDeviceBackend() - : _context_count(0), _tuner(), _gemm_heuristics(), _allocator(nullptr), _tuner_file(), _backend_type(CLBackendType::Native) + : _context_count(0), + _tuner(), + _gemm_heuristics(), + _allocator(nullptr), + _tuner_file(), + _backend_type(CLBackendType::Native) { } @@ -95,7 +99,7 @@ void CLDeviceBackend::release_backend_context(GraphContext &ctx) { ARM_COMPUTE_UNUSED(ctx); _context_count--; - if(_context_count == 0) // No more context using the backend: free resources + if (_context_count == 0) // No more context using the backend: free resources { _allocator = nullptr; } @@ -105,7 +109,7 @@ void CLDeviceBackend::setup_backend_context(GraphContext &ctx) { // Force backend initialization _context_count++; - if(_context_count == 1) + if (_context_count == 1) { _backend_type = ctx.config().backend_type; initialize_backend(); @@ -115,7 +119,7 @@ void CLDeviceBackend::setup_backend_context(GraphContext &ctx) _tuner_file = ctx.config().tuner_file; // Load tuner data if available - if(file_exists(_tuner_file)) + if (file_exists(_tuner_file)) { _tuner.load_from_file(_tuner_file); } @@ -128,7 +132,7 @@ void CLDeviceBackend::setup_backend_context(GraphContext &ctx) CLScheduler::get().gemm_heuristics()->reload_from_file(ctx.config().mlgo_file); // Setup a management backend - if(ctx.memory_management_ctx(Target::CL) == nullptr) + if (ctx.memory_management_ctx(Target::CL) == nullptr) { MemoryManagerContext mm_ctx; mm_ctx.target = Target::CL; @@ -141,7 +145,7 @@ void CLDeviceBackend::setup_backend_context(GraphContext &ctx) } // Create function level weights manager - if(ctx.weights_management_ctx(Target::CL) == nullptr) + if (ctx.weights_management_ctx(Target::CL) == nullptr) { WeightsManagerContext wm_ctx; wm_ctx.target = Target::CL; @@ -174,9 +178,10 @@ std::unique_ptr CLDeviceBackend::create_tensor(const Tensor &tens return std::make_unique(info); } -std::unique_ptr CLDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) +std::unique_ptr +CLDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) { - if(parent == nullptr) + if (parent == nullptr) { return nullptr; } @@ -203,7 +208,7 @@ arm_compute::Status CLDeviceBackend::validate_node(INode &node) std::shared_ptr CLDeviceBackend::create_memory_manager(MemoryManagerAffinity affinity) { - if(affinity == MemoryManagerAffinity::Offset) + if (affinity == MemoryManagerAffinity::Offset) { ARM_COMPUTE_LOG_GRAPH_WARNING("CL Backend does not support offset affinity memory management!"); return nullptr; diff --git a/src/graph/backends/CL/CLFunctionsFactory.cpp b/src/graph/backends/CL/CLFunctionsFactory.cpp index 882810474e..d4e1aa880f 100644 --- a/src/graph/backends/CL/CLFunctionsFactory.cpp +++ b/src/graph/backends/CL/CLFunctionsFactory.cpp @@ -22,12 +22,12 @@ * SOFTWARE. */ #include "arm_compute/graph/backends/CL/CLFunctionFactory.h" - +#include "arm_compute/graph/backends/FunctionHelpers.h" #include "arm_compute/graph/Graph.h" #include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/backends/FunctionHelpers.h" #include "arm_compute/runtime/CL/CLFunctions.h" #include "arm_compute/runtime/CPP/CPPFunctions.h" + #include "src/core/CL/CLKernels.h" #include "support/Cast.h" @@ -89,20 +89,19 @@ class CPPWrapperFunction : public IFunction { public: /* Default constructor */ - CPPWrapperFunction() - : _tensors(), _func(nullptr) + CPPWrapperFunction() : _tensors(), _func(nullptr) { } void run() override { - for(auto &tensor : _tensors) + for (auto &tensor : _tensors) { tensor->map(CLScheduler::get().queue()); } _func->run(); - for(auto &tensor : _tensors) + for (auto &tensor : _tensors) { tensor->unmap(CLScheduler::get().queue()); } @@ -127,7 +126,8 @@ namespace detail { // Specialized functions template <> -std::unique_ptr create_detection_output_layer(DetectionOutputLayerNode &node) +std::unique_ptr +create_detection_output_layer(DetectionOutputLayerNode &node) { validate_node(node, 3 /* expected inputs */, 1 /* expected outputs */); @@ -149,16 +149,12 @@ std::unique_ptr create_detection_output_layerinfo()->data_type() - << " Input0 shape: " << input0->info()->tensor_shape() - << " Input1 shape: " << input1->info()->tensor_shape() + << 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); + << " DetectionOutputLayer info: " << detect_info << std::endl); auto wrap_function = std::make_unique(); @@ -171,7 +167,8 @@ std::unique_ptr create_detection_output_layer -std::unique_ptr create_detection_post_process_layer(DetectionPostProcessLayerNode &node) +std::unique_ptr +create_detection_post_process_layer(DetectionPostProcessLayerNode &node) { validate_node(node, 3 /* expected inputs */, 4 /* expected outputs */); @@ -199,19 +196,15 @@ std::unique_ptr create_detection_post_process_layerinfo()->data_type() - << " Input0 shape: " << input0->info()->tensor_shape() - << " Input1 shape: " << input1->info()->tensor_shape() + << 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() << " Output0 shape: " << output0->info()->tensor_shape() << " Output1 shape: " << output1->info()->tensor_shape() << " Output2 shape: " << output2->info()->tensor_shape() << " Output3 shape: " << output3->info()->tensor_shape() - << " DetectionPostProcessLayer info: " << detect_info - << std::endl); + << " DetectionPostProcessLayer info: " << detect_info << std::endl); auto wrap_function = std::make_unique(); @@ -230,92 +223,128 @@ std::unique_ptr create_detection_post_process_layer CLFunctionFactory::create(INode *node, GraphContext &ctx) { - if(node == nullptr) + if (node == nullptr) { return nullptr; } NodeType type = node->type(); - switch(type) + switch (type) { case NodeType::ActivationLayer: - return detail::create_activation_layer(*polymorphic_downcast(node)); + return detail::create_activation_layer( + *polymorphic_downcast(node)); case NodeType::ArgMinMaxLayer: - return detail::create_arg_min_max_layer(*polymorphic_downcast(node)); + return detail::create_arg_min_max_layer( + *polymorphic_downcast(node)); case NodeType::BatchNormalizationLayer: - return detail::create_batch_normalization_layer(*polymorphic_downcast(node)); + return detail::create_batch_normalization_layer( + *polymorphic_downcast(node)); case NodeType::BoundingBoxTransformLayer: - return detail::create_bounding_box_transform_layer(*polymorphic_downcast(node)); + return detail::create_bounding_box_transform_layer( + *polymorphic_downcast(node)); case NodeType::ChannelShuffleLayer: - return detail::create_channel_shuffle_layer(*polymorphic_downcast(node)); + return detail::create_channel_shuffle_layer( + *polymorphic_downcast(node)); case NodeType::ConvolutionLayer: - return detail::create_convolution_layer(*polymorphic_downcast(node), ctx); + return detail::create_convolution_layer( + *polymorphic_downcast(node), ctx); case NodeType::DeconvolutionLayer: - return detail::create_deconvolution_layer(*polymorphic_downcast(node), ctx); + return detail::create_deconvolution_layer( + *polymorphic_downcast(node), ctx); case NodeType::ConcatenateLayer: - return detail::create_concatenate_layer(*polymorphic_downcast(node)); + return detail::create_concatenate_layer( + *polymorphic_downcast(node)); case NodeType::DepthToSpaceLayer: - return detail::create_depth_to_space_layer(*polymorphic_downcast(node)); + return detail::create_depth_to_space_layer( + *polymorphic_downcast(node)); case NodeType::DepthwiseConvolutionLayer: - return detail::create_depthwise_convolution_layer(*polymorphic_downcast(node)); + return detail::create_depthwise_convolution_layer( + *polymorphic_downcast(node)); case NodeType::DequantizationLayer: - return detail::create_dequantization_layer(*polymorphic_downcast(node)); + return detail::create_dequantization_layer( + *polymorphic_downcast(node)); case NodeType::DetectionOutputLayer: - return detail::create_detection_output_layer(*polymorphic_downcast(node)); + return detail::create_detection_output_layer( + *polymorphic_downcast(node)); case NodeType::DetectionPostProcessLayer: - return detail::create_detection_post_process_layer(*polymorphic_downcast(node)); + return detail::create_detection_post_process_layer( + *polymorphic_downcast(node)); case NodeType::EltwiseLayer: - return detail::create_eltwise_layer(*polymorphic_downcast(node)); + return detail::create_eltwise_layer( + *polymorphic_downcast(node)); case NodeType::UnaryEltwiseLayer: - return detail::create_unary_eltwise_layer(*polymorphic_downcast(node)); + return detail::create_unary_eltwise_layer( + *polymorphic_downcast(node)); case NodeType::FlattenLayer: - return detail::create_flatten_layer(*polymorphic_downcast(node)); + return detail::create_flatten_layer( + *polymorphic_downcast(node)); case NodeType::FullyConnectedLayer: - return detail::create_fully_connected_layer(*polymorphic_downcast(node), ctx); + return detail::create_fully_connected_layer( + *polymorphic_downcast(node), ctx); case NodeType::FusedConvolutionBatchNormalizationLayer: - return detail::create_fused_convolution_batch_normalization_layer(*polymorphic_downcast(node), ctx); + return detail::create_fused_convolution_batch_normalization_layer( + *polymorphic_downcast(node), ctx); case NodeType::FusedDepthwiseConvolutionBatchNormalizationLayer: - return detail::create_fused_depthwise_convolution_batch_normalization_layer(*polymorphic_downcast(node), ctx); + return detail::create_fused_depthwise_convolution_batch_normalization_layer( + *polymorphic_downcast(node), ctx); case NodeType::GenerateProposalsLayer: - return detail::create_generate_proposals_layer(*polymorphic_downcast(node), ctx); + return detail::create_generate_proposals_layer( + *polymorphic_downcast(node), ctx); case NodeType::L2NormalizeLayer: - return detail::create_l2_normalize_layer(*polymorphic_downcast(node), ctx); + return detail::create_l2_normalize_layer( + *polymorphic_downcast(node), ctx); case NodeType::NormalizationLayer: - return detail::create_normalization_layer(*polymorphic_downcast(node), ctx); + return detail::create_normalization_layer( + *polymorphic_downcast(node), ctx); case NodeType::NormalizePlanarYUVLayer: - return detail::create_normalize_planar_yuv_layer(*polymorphic_downcast(node)); + return detail::create_normalize_planar_yuv_layer( + *polymorphic_downcast(node)); case NodeType::PadLayer: return detail::create_pad_layer(*polymorphic_downcast(node)); case NodeType::PermuteLayer: - return detail::create_permute_layer(*polymorphic_downcast(node)); + return detail::create_permute_layer( + *polymorphic_downcast(node)); case NodeType::PoolingLayer: - return detail::create_pooling_layer(*polymorphic_downcast(node)); + return detail::create_pooling_layer( + *polymorphic_downcast(node)); case NodeType::PReluLayer: - return detail::create_prelu_layer(*polymorphic_downcast(node)); + return detail::create_prelu_layer( + *polymorphic_downcast(node)); case NodeType::PrintLayer: return detail::create_print_layer(*polymorphic_downcast(node)); case NodeType::PriorBoxLayer: - return detail::create_priorbox_layer(*polymorphic_downcast(node)); + return detail::create_priorbox_layer( + *polymorphic_downcast(node)); case NodeType::QuantizationLayer: - return detail::create_quantization_layer(*polymorphic_downcast(node)); + return detail::create_quantization_layer( + *polymorphic_downcast(node)); case NodeType::ReductionOperationLayer: - return detail::create_reduction_operation_layer(*polymorphic_downcast(node), ctx); + return detail::create_reduction_operation_layer( + *polymorphic_downcast(node), ctx); case NodeType::ReorgLayer: - return detail::create_reorg_layer(*polymorphic_downcast(node)); + return detail::create_reorg_layer( + *polymorphic_downcast(node)); case NodeType::ReshapeLayer: - return detail::create_reshape_layer(*polymorphic_downcast(node)); + return detail::create_reshape_layer( + *polymorphic_downcast(node)); case NodeType::ResizeLayer: return detail::create_resize_layer(*polymorphic_downcast(node)); case NodeType::ROIAlignLayer: - return detail::create_roi_align_layer(*polymorphic_downcast(node)); + return detail::create_roi_align_layer( + *polymorphic_downcast(node)); case NodeType::SliceLayer: return detail::create_slice_layer(*polymorphic_downcast(node)); case NodeType::SoftmaxLayer: - return detail::create_softmax_layer(*polymorphic_downcast(node), ctx); + return detail::create_softmax_layer( + *polymorphic_downcast(node), ctx); case NodeType::StackLayer: - return detail::create_stack_layer(*polymorphic_downcast(node)); + return detail::create_stack_layer( + *polymorphic_downcast(node)); case NodeType::StridedSliceLayer: - return detail::create_strided_slice_layer(*polymorphic_downcast(node)); + return detail::create_strided_slice_layer( + *polymorphic_downcast(node)); default: return nullptr; } diff --git a/src/graph/backends/CL/CLNodeValidator.cpp b/src/graph/backends/CL/CLNodeValidator.cpp index 8fd8c14f63..510eda7935 100644 --- a/src/graph/backends/CL/CLNodeValidator.cpp +++ b/src/graph/backends/CL/CLNodeValidator.cpp @@ -25,7 +25,6 @@ #include "arm_compute/graph/backends/ValidateHelpers.h" #include "arm_compute/graph/nodes/Nodes.h" - #include "arm_compute/runtime/CL/CLFunctions.h" #include "arm_compute/runtime/CPP/CPPFunctions.h" @@ -57,41 +56,51 @@ struct CLUnaryEltwiseLayerFunctions Status CLNodeValidator::validate(INode *node) { - if(node == nullptr) + if (node == nullptr) { return Status{}; } NodeType type = node->type(); - switch(type) + switch (type) { case NodeType::ArgMinMaxLayer: - return detail::validate_arg_min_max_layer(*polymorphic_downcast(node)); + return detail::validate_arg_min_max_layer( + *polymorphic_downcast(node)); case NodeType::BoundingBoxTransformLayer: - return detail::validate_bounding_box_transform_layer(*polymorphic_downcast(node)); + return detail::validate_bounding_box_transform_layer( + *polymorphic_downcast(node)); case NodeType::ChannelShuffleLayer: - return detail::validate_channel_shuffle_layer(*polymorphic_downcast(node)); + return detail::validate_channel_shuffle_layer( + *polymorphic_downcast(node)); case NodeType::ConvolutionLayer: - return detail::validate_convolution_layer(*polymorphic_downcast(node)); + return detail::validate_convolution_layer( + *polymorphic_downcast(node)); case NodeType::DepthToSpaceLayer: - return detail::validate_depth_to_space_layer(*polymorphic_downcast(node)); + return detail::validate_depth_to_space_layer( + *polymorphic_downcast(node)); case NodeType::DepthwiseConvolutionLayer: - return detail::validate_depthwise_convolution_layer(*polymorphic_downcast(node)); + return detail::validate_depthwise_convolution_layer( + *polymorphic_downcast(node)); case NodeType::DequantizationLayer: - return detail::validate_dequantization_layer(*polymorphic_downcast(node)); + return detail::validate_dequantization_layer( + *polymorphic_downcast(node)); case NodeType::DetectionOutputLayer: - return detail::validate_detection_output_layer(*polymorphic_downcast(node)); + return detail::validate_detection_output_layer( + *polymorphic_downcast(node)); case NodeType::DetectionPostProcessLayer: - return detail::validate_detection_post_process_layer(*polymorphic_downcast(node)); + return detail::validate_detection_post_process_layer( + *polymorphic_downcast(node)); case NodeType::GenerateProposalsLayer: - return detail::validate_generate_proposals_layer(*polymorphic_downcast(node)); + return detail::validate_generate_proposals_layer( + *polymorphic_downcast(node)); case NodeType::L2NormalizeLayer: - return detail::validate_l2_normalize_layer(*polymorphic_downcast(node)); + return detail::validate_l2_normalize_layer( + *polymorphic_downcast(node)); case NodeType::NormalizePlanarYUVLayer: - return detail::validate_normalize_planar_yuv_layer(*polymorphic_downcast(node)); + return detail::validate_normalize_planar_yuv_layer( + *polymorphic_downcast(node)); case NodeType::PadLayer: return detail::validate_pad_layer(*polymorphic_downcast(node)); case NodeType::PermuteLayer: @@ -101,9 +110,11 @@ Status CLNodeValidator::validate(INode *node) case NodeType::PriorBoxLayer: return detail::validate_priorbox_layer(*polymorphic_downcast(node)); case NodeType::QuantizationLayer: - return detail::validate_quantization_layer(*polymorphic_downcast(node)); + return detail::validate_quantization_layer( + *polymorphic_downcast(node)); case NodeType::ReductionOperationLayer: - return detail::validate_reduction_operation_layer(*polymorphic_downcast(node)); + return detail::validate_reduction_operation_layer( + *polymorphic_downcast(node)); case NodeType::ReorgLayer: return detail::validate_reorg_layer(*polymorphic_downcast(node)); case NodeType::ReshapeLayer: @@ -113,11 +124,14 @@ Status CLNodeValidator::validate(INode *node) case NodeType::SliceLayer: return detail::validate_slice_layer(*polymorphic_downcast(node)); case NodeType::StridedSliceLayer: - return detail::validate_strided_slice_layer(*polymorphic_downcast(node)); + return detail::validate_strided_slice_layer( + *polymorphic_downcast(node)); case NodeType::EltwiseLayer: - return detail::validate_eltwise_Layer(*polymorphic_downcast(node)); + return detail::validate_eltwise_Layer( + *polymorphic_downcast(node)); case NodeType::UnaryEltwiseLayer: - return detail::validate_unary_eltwise_layer(*polymorphic_downcast(node)); + return detail::validate_unary_eltwise_layer( + *polymorphic_downcast(node)); default: return Status{}; } diff --git a/src/graph/backends/CL/CLSubTensorHandle.cpp b/src/graph/backends/CL/CLSubTensorHandle.cpp index b97d25890a..ccdc877a18 100644 --- a/src/graph/backends/CL/CLSubTensorHandle.cpp +++ b/src/graph/backends/CL/CLSubTensorHandle.cpp @@ -31,7 +31,10 @@ namespace graph { namespace backends { -CLSubTensorHandle::CLSubTensorHandle(ITensorHandle *parent_handle, const TensorShape &shape, const Coordinates &coords, bool extend_parent) +CLSubTensorHandle::CLSubTensorHandle(ITensorHandle *parent_handle, + const TensorShape &shape, + const Coordinates &coords, + bool extend_parent) : _sub_tensor(), _parent_handle(nullptr) { ARM_COMPUTE_ERROR_ON(!parent_handle); @@ -98,4 +101,4 @@ Target CLSubTensorHandle::target() const } } // namespace backends } // namespace graph -} // namespace arm_compute \ No newline at end of file +} // namespace arm_compute diff --git a/src/graph/backends/CL/CLTensorHandle.cpp b/src/graph/backends/CL/CLTensorHandle.cpp index a496c2ce47..1b69f9dede 100644 --- a/src/graph/backends/CL/CLTensorHandle.cpp +++ b/src/graph/backends/CL/CLTensorHandle.cpp @@ -31,8 +31,7 @@ namespace graph { namespace backends { -CLTensorHandle::CLTensorHandle(const ITensorInfo &info) - : _tensor() +CLTensorHandle::CLTensorHandle(const ITensorInfo &info) : _tensor() { _tensor.allocator()->init(info); } @@ -49,7 +48,7 @@ void CLTensorHandle::free() void CLTensorHandle::manage(IMemoryGroup *mg) { - if(mg != nullptr) + if (mg != nullptr) { mg->manage(&_tensor); } @@ -68,7 +67,7 @@ void CLTensorHandle::unmap() void CLTensorHandle::release_if_unused() { // TODO (geopin01): Release tensor only if all sub-tensors are marked as not used - if(!_tensor.is_used()) + if (!_tensor.is_used()) { _tensor.allocator()->free(); } @@ -100,4 +99,4 @@ Target CLTensorHandle::target() const } } // namespace backends } // namespace graph -} // namespace arm_compute \ No newline at end of file +} // namespace arm_compute diff --git a/src/graph/backends/NEON/NEDeviceBackend.cpp b/src/graph/backends/NEON/NEDeviceBackend.cpp index 18456538da..fc7b309803 100644 --- a/src/graph/backends/NEON/NEDeviceBackend.cpp +++ b/src/graph/backends/NEON/NEDeviceBackend.cpp @@ -23,18 +23,17 @@ */ #include "arm_compute/graph/backends/NEON/NEDeviceBackend.h" -#include "arm_compute/graph/Graph.h" -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/Logger.h" -#include "arm_compute/graph/Tensor.h" +#include "arm_compute/core/TensorInfo.h" #include "arm_compute/graph/backends/BackendRegistrar.h" #include "arm_compute/graph/backends/NEON/NEFunctionFactory.h" #include "arm_compute/graph/backends/NEON/NENodeValidator.h" #include "arm_compute/graph/backends/NEON/NESubTensorHandle.h" #include "arm_compute/graph/backends/NEON/NETensorHandle.h" - -#include "arm_compute/core/TensorInfo.h" +#include "arm_compute/graph/Graph.h" +#include "arm_compute/graph/GraphContext.h" +#include "arm_compute/graph/INode.h" +#include "arm_compute/graph/Logger.h" +#include "arm_compute/graph/Tensor.h" #include "arm_compute/runtime/Allocator.h" #include "arm_compute/runtime/BlobLifetimeManager.h" #include "arm_compute/runtime/IWeightsManager.h" @@ -53,8 +52,7 @@ namespace backends /** Register CPU backend */ static detail::BackendRegistrar NEDeviceBackend_registrar(Target::NEON); -NEDeviceBackend::NEDeviceBackend() - : _allocator() +NEDeviceBackend::NEDeviceBackend() : _allocator() { } @@ -72,13 +70,13 @@ void NEDeviceBackend::release_backend_context(GraphContext &ctx) void NEDeviceBackend::setup_backend_context(GraphContext &ctx) { // Set number of threads - if(ctx.config().num_threads >= 0) + if (ctx.config().num_threads >= 0) { Scheduler::get().set_num_threads(ctx.config().num_threads); } // Create function level memory manager - if(ctx.memory_management_ctx(Target::NEON) == nullptr) + if (ctx.memory_management_ctx(Target::NEON) == nullptr) { MemoryManagerContext mm_ctx; mm_ctx.target = Target::NEON; @@ -91,7 +89,7 @@ void NEDeviceBackend::setup_backend_context(GraphContext &ctx) } // Create function level weights manager - if(ctx.weights_management_ctx(Target::NEON) == nullptr) + if (ctx.weights_management_ctx(Target::NEON) == nullptr) { WeightsManagerContext wm_ctx; wm_ctx.target = Target::NEON; @@ -124,9 +122,10 @@ std::unique_ptr NEDeviceBackend::create_tensor(const Tensor &tens return std::make_unique(info); } -std::unique_ptr NEDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) +std::unique_ptr +NEDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) { - if(parent == nullptr) + if (parent == nullptr) { return nullptr; } @@ -154,7 +153,7 @@ arm_compute::Status NEDeviceBackend::validate_node(INode &node) std::shared_ptr NEDeviceBackend::create_memory_manager(MemoryManagerAffinity affinity) { std::shared_ptr lifetime_mgr = nullptr; - if(affinity == MemoryManagerAffinity::Buffer) + if (affinity == MemoryManagerAffinity::Buffer) { lifetime_mgr = std::make_shared(); } diff --git a/src/graph/backends/NEON/NEFunctionFactory.cpp b/src/graph/backends/NEON/NEFunctionFactory.cpp index d7ed5f9ecb..fe15d4cec1 100644 --- a/src/graph/backends/NEON/NEFunctionFactory.cpp +++ b/src/graph/backends/NEON/NEFunctionFactory.cpp @@ -23,13 +23,13 @@ */ #include "arm_compute/graph/backends/NEON/NEFunctionFactory.h" +#include "arm_compute/graph/backends/FunctionHelpers.h" +#include "arm_compute/graph/backends/Utils.h" #include "arm_compute/graph/Graph.h" #include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/Logger.h" -#include "arm_compute/graph/TypePrinter.h" -#include "arm_compute/graph/backends/FunctionHelpers.h" -#include "arm_compute/graph/backends/Utils.h" #include "arm_compute/graph/nodes/Nodes.h" +#include "arm_compute/graph/TypePrinter.h" #include "arm_compute/runtime/CPP/CPPFunctions.h" #include "arm_compute/runtime/NEON/NEFunctions.h" @@ -88,7 +88,8 @@ struct NEFusedLayerTypes namespace detail { template <> -std::unique_ptr create_normalization_layer(NormalizationLayerNode &node, GraphContext &ctx) +std::unique_ptr create_normalization_layer(NormalizationLayerNode &node, + GraphContext &ctx) { validate_node(node, 1 /* expected inputs */, 1 /* expected outputs */); @@ -105,14 +106,10 @@ std::unique_ptr create_normalization_layerinfo()->data_type() - << " Input shape: " << input->info()->tensor_shape() - << " Output shape: " << output->info()->tensor_shape() - << " Normalization info: " << norm_info.type() - << std::endl); + << node.name() << " Type: " << node.type() << " Target: " << NETargetInfo::TargetType + << " Data Type: " << input->info()->data_type() << " Input shape: " + << input->info()->tensor_shape() << " Output shape: " << output->info()->tensor_shape() + << " Normalization info: " << norm_info.type() << std::endl); return func; } @@ -120,84 +117,116 @@ std::unique_ptr create_normalization_layer NEFunctionFactory::create(INode *node, GraphContext &ctx) { - if(node == nullptr) + if (node == nullptr) { return nullptr; } NodeType type = node->type(); - switch(type) + switch (type) { case NodeType::ActivationLayer: - return detail::create_activation_layer(*polymorphic_downcast(node)); + return detail::create_activation_layer( + *polymorphic_downcast(node)); case NodeType::ArgMinMaxLayer: - return detail::create_arg_min_max_layer(*polymorphic_downcast(node)); + return detail::create_arg_min_max_layer( + *polymorphic_downcast(node)); case NodeType::BatchNormalizationLayer: - return detail::create_batch_normalization_layer(*polymorphic_downcast(node)); + return detail::create_batch_normalization_layer( + *polymorphic_downcast(node)); case NodeType::ChannelShuffleLayer: - return detail::create_channel_shuffle_layer(*polymorphic_downcast(node)); + return detail::create_channel_shuffle_layer( + *polymorphic_downcast(node)); case NodeType::ConvolutionLayer: - return detail::create_convolution_layer(*polymorphic_downcast(node), ctx); + return detail::create_convolution_layer( + *polymorphic_downcast(node), ctx); case NodeType::DepthToSpaceLayer: - return detail::create_depth_to_space_layer(*polymorphic_downcast(node)); + return detail::create_depth_to_space_layer( + *polymorphic_downcast(node)); case NodeType::DeconvolutionLayer: - return detail::create_deconvolution_layer(*polymorphic_downcast(node), ctx); + return detail::create_deconvolution_layer( + *polymorphic_downcast(node), ctx); case NodeType::ConcatenateLayer: - return detail::create_concatenate_layer(*polymorphic_downcast(node)); + return detail::create_concatenate_layer( + *polymorphic_downcast(node)); case NodeType::DepthwiseConvolutionLayer: - return detail::create_depthwise_convolution_layer(*polymorphic_downcast(node)); + return detail::create_depthwise_convolution_layer( + *polymorphic_downcast(node)); case NodeType::DequantizationLayer: - return detail::create_dequantization_layer(*polymorphic_downcast(node)); + return detail::create_dequantization_layer( + *polymorphic_downcast(node)); case NodeType::DetectionOutputLayer: - return detail::create_detection_output_layer(*polymorphic_downcast(node)); + return detail::create_detection_output_layer( + *polymorphic_downcast(node)); case NodeType::DetectionPostProcessLayer: - return detail::create_detection_post_process_layer(*polymorphic_downcast(node)); + return detail::create_detection_post_process_layer( + *polymorphic_downcast(node)); case NodeType::EltwiseLayer: - return detail::create_eltwise_layer(*polymorphic_downcast(node)); + return detail::create_eltwise_layer( + *polymorphic_downcast(node)); case NodeType::UnaryEltwiseLayer: - return detail::create_unary_eltwise_layer(*polymorphic_downcast(node)); + return detail::create_unary_eltwise_layer( + *polymorphic_downcast(node)); case NodeType::FlattenLayer: - return detail::create_flatten_layer(*polymorphic_downcast(node)); + return detail::create_flatten_layer( + *polymorphic_downcast(node)); case NodeType::FullyConnectedLayer: - return detail::create_fully_connected_layer(*polymorphic_downcast(node), ctx); + return detail::create_fully_connected_layer( + *polymorphic_downcast(node), ctx); case NodeType::FusedConvolutionBatchNormalizationLayer: - return detail::create_fused_convolution_batch_normalization_layer(*polymorphic_downcast(node), ctx); + return detail::create_fused_convolution_batch_normalization_layer( + *polymorphic_downcast(node), ctx); case NodeType::FusedDepthwiseConvolutionBatchNormalizationLayer: - return detail::create_fused_depthwise_convolution_batch_normalization_layer(*polymorphic_downcast(node), ctx); + return detail::create_fused_depthwise_convolution_batch_normalization_layer( + *polymorphic_downcast(node), ctx); case NodeType::L2NormalizeLayer: - return detail::create_l2_normalize_layer(*polymorphic_downcast(node), ctx); + return detail::create_l2_normalize_layer( + *polymorphic_downcast(node), ctx); case NodeType::NormalizationLayer: - return detail::create_normalization_layer(*polymorphic_downcast(node), ctx); + return detail::create_normalization_layer( + *polymorphic_downcast(node), ctx); case NodeType::PadLayer: return detail::create_pad_layer(*polymorphic_downcast(node)); case NodeType::PermuteLayer: - return detail::create_permute_layer(*polymorphic_downcast(node)); + return detail::create_permute_layer( + *polymorphic_downcast(node)); case NodeType::PoolingLayer: - return detail::create_pooling_layer(*polymorphic_downcast(node)); + return detail::create_pooling_layer( + *polymorphic_downcast(node)); case NodeType::PReluLayer: - return detail::create_prelu_layer(*polymorphic_downcast(node)); + return detail::create_prelu_layer( + *polymorphic_downcast(node)); case NodeType::PrintLayer: return detail::create_print_layer(*polymorphic_downcast(node)); case NodeType::PriorBoxLayer: - return detail::create_priorbox_layer(*polymorphic_downcast(node)); + return detail::create_priorbox_layer( + *polymorphic_downcast(node)); case NodeType::QuantizationLayer: - return detail::create_quantization_layer(*polymorphic_downcast(node)); + return detail::create_quantization_layer( + *polymorphic_downcast(node)); case NodeType::ReductionOperationLayer: - return detail::create_reduction_operation_layer(*polymorphic_downcast(node), ctx); + return detail::create_reduction_operation_layer( + *polymorphic_downcast(node), ctx); case NodeType::ReorgLayer: - return detail::create_reorg_layer(*polymorphic_downcast(node)); + return detail::create_reorg_layer( + *polymorphic_downcast(node)); case NodeType::ReshapeLayer: - return detail::create_reshape_layer(*polymorphic_downcast(node)); + return detail::create_reshape_layer( + *polymorphic_downcast(node)); case NodeType::ResizeLayer: return detail::create_resize_layer(*polymorphic_downcast(node)); case NodeType::SliceLayer: return detail::create_slice_layer(*polymorphic_downcast(node)); case NodeType::SoftmaxLayer: - return detail::create_softmax_layer(*polymorphic_downcast(node), ctx); + return detail::create_softmax_layer( + *polymorphic_downcast(node), ctx); case NodeType::StackLayer: - return detail::create_stack_layer(*polymorphic_downcast(node)); + return detail::create_stack_layer( + *polymorphic_downcast(node)); case NodeType::StridedSliceLayer: - return detail::create_strided_slice_layer(*polymorphic_downcast(node)); + return detail::create_strided_slice_layer( + *polymorphic_downcast(node)); default: return nullptr; } diff --git a/src/graph/backends/NEON/NENodeValidator.cpp b/src/graph/backends/NEON/NENodeValidator.cpp index a485e5d235..a97806f92c 100644 --- a/src/graph/backends/NEON/NENodeValidator.cpp +++ b/src/graph/backends/NEON/NENodeValidator.cpp @@ -25,9 +25,9 @@ #include "arm_compute/graph/backends/ValidateHelpers.h" #include "arm_compute/graph/nodes/Nodes.h" - #include "arm_compute/runtime/CPP/CPPFunctions.h" #include "arm_compute/runtime/NEON/NEFunctions.h" + #include "support/Cast.h" using namespace arm_compute::utils::cast; @@ -56,41 +56,51 @@ struct NEUnaryEltwiseLayerFunctions Status NENodeValidator::validate(INode *node) { - if(node == nullptr) + if (node == nullptr) { return Status{}; } NodeType type = node->type(); - switch(type) + switch (type) { case NodeType::ArgMinMaxLayer: - return detail::validate_arg_min_max_layer(*polymorphic_downcast(node)); + return detail::validate_arg_min_max_layer( + *polymorphic_downcast(node)); case NodeType::BoundingBoxTransformLayer: - return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : BoundingBoxTransformLayer"); + return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, + "Unsupported operation : BoundingBoxTransformLayer"); case NodeType::ChannelShuffleLayer: - return detail::validate_channel_shuffle_layer(*polymorphic_downcast(node)); + return detail::validate_channel_shuffle_layer( + *polymorphic_downcast(node)); case NodeType::ConvolutionLayer: - return detail::validate_convolution_layer(*polymorphic_downcast(node)); + return detail::validate_convolution_layer( + *polymorphic_downcast(node)); case NodeType::DepthToSpaceLayer: - return detail::validate_depth_to_space_layer(*polymorphic_downcast(node)); + return detail::validate_depth_to_space_layer( + *polymorphic_downcast(node)); case NodeType::DepthwiseConvolutionLayer: - return detail::validate_depthwise_convolution_layer(*polymorphic_downcast(node)); + return detail::validate_depthwise_convolution_layer( + *polymorphic_downcast(node)); case NodeType::DequantizationLayer: - return detail::validate_dequantization_layer(*polymorphic_downcast(node)); + return detail::validate_dequantization_layer( + *polymorphic_downcast(node)); case NodeType::DetectionOutputLayer: - return detail::validate_detection_output_layer(*polymorphic_downcast(node)); + return detail::validate_detection_output_layer( + *polymorphic_downcast(node)); case NodeType::DetectionPostProcessLayer: - return detail::validate_detection_post_process_layer(*polymorphic_downcast(node)); + return detail::validate_detection_post_process_layer( + *polymorphic_downcast(node)); case NodeType::GenerateProposalsLayer: - return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer"); + return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, + "Unsupported operation : GenerateProposalsLayer"); case NodeType::L2NormalizeLayer: - return detail::validate_l2_normalize_layer(*polymorphic_downcast(node)); + return detail::validate_l2_normalize_layer( + *polymorphic_downcast(node)); case NodeType::NormalizePlanarYUVLayer: - return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : NormalizePlanarYUVLayer"); + return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, + "Unsupported operation : NormalizePlanarYUVLayer"); case NodeType::PadLayer: return detail::validate_pad_layer(*polymorphic_downcast(node)); case NodeType::PermuteLayer: @@ -100,23 +110,29 @@ Status NENodeValidator::validate(INode *node) case NodeType::PriorBoxLayer: return detail::validate_priorbox_layer(*polymorphic_downcast(node)); case NodeType::QuantizationLayer: - return detail::validate_quantization_layer(*polymorphic_downcast(node)); + return detail::validate_quantization_layer( + *polymorphic_downcast(node)); case NodeType::ReductionOperationLayer: - return detail::validate_reduction_operation_layer(*polymorphic_downcast(node)); + return detail::validate_reduction_operation_layer( + *polymorphic_downcast(node)); case NodeType::ReorgLayer: return detail::validate_reorg_layer(*polymorphic_downcast(node)); case NodeType::ReshapeLayer: return detail::validate_reshape_layer(*polymorphic_downcast(node)); case NodeType::ROIAlignLayer: - return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ROIAlignLayer"); + return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, + "Unsupported operation : ROIAlignLayer"); case NodeType::SliceLayer: return detail::validate_slice_layer(*polymorphic_downcast(node)); case NodeType::StridedSliceLayer: - return detail::validate_strided_slice_layer(*polymorphic_downcast(node)); + return detail::validate_strided_slice_layer( + *polymorphic_downcast(node)); case NodeType::EltwiseLayer: - return detail::validate_eltwise_Layer(*polymorphic_downcast(node)); + return detail::validate_eltwise_Layer( + *polymorphic_downcast(node)); case NodeType::UnaryEltwiseLayer: - return detail::validate_unary_eltwise_layer(*polymorphic_downcast(node)); + return detail::validate_unary_eltwise_layer( + *polymorphic_downcast(node)); default: return Status{}; } diff --git a/src/graph/backends/NEON/NESubTensorHandle.cpp b/src/graph/backends/NEON/NESubTensorHandle.cpp index 36f29d0d10..8964a00c5e 100644 --- a/src/graph/backends/NEON/NESubTensorHandle.cpp +++ b/src/graph/backends/NEON/NESubTensorHandle.cpp @@ -29,7 +29,10 @@ namespace graph { namespace backends { -NESubTensorHandle::NESubTensorHandle(ITensorHandle *parent_handle, const TensorShape &shape, const Coordinates &coords, bool extend_parent) +NESubTensorHandle::NESubTensorHandle(ITensorHandle *parent_handle, + const TensorShape &shape, + const Coordinates &coords, + bool extend_parent) : _sub_tensor(), _parent_handle(nullptr) { ARM_COMPUTE_ERROR_ON(!parent_handle); @@ -95,4 +98,4 @@ Target NESubTensorHandle::target() const } } // namespace backends } // namespace graph -} // namespace arm_compute \ No newline at end of file +} // namespace arm_compute diff --git a/src/graph/backends/NEON/NETensorHandle.cpp b/src/graph/backends/NEON/NETensorHandle.cpp index 4393156e8a..dabf67060d 100644 --- a/src/graph/backends/NEON/NETensorHandle.cpp +++ b/src/graph/backends/NEON/NETensorHandle.cpp @@ -24,6 +24,7 @@ #include "arm_compute/graph/backends/NEON/NETensorHandle.h" #include "arm_compute/runtime/MemoryGroup.h" + #include "support/Cast.h" namespace arm_compute @@ -32,8 +33,7 @@ namespace graph { namespace backends { -NETensorHandle::NETensorHandle(const ITensorInfo &info) - : _tensor() +NETensorHandle::NETensorHandle(const ITensorInfo &info) : _tensor() { _tensor.allocator()->init(info); } @@ -50,7 +50,7 @@ void NETensorHandle::free() void NETensorHandle::manage(IMemoryGroup *mg) { - if(mg != nullptr) + if (mg != nullptr) { mg->manage(&_tensor); } @@ -68,7 +68,7 @@ void NETensorHandle::unmap() void NETensorHandle::release_if_unused() { // TODO (geopin01): Release tensor only if all sub-tensors are marked as not used - if(!_tensor.is_used()) + if (!_tensor.is_used()) { _tensor.allocator()->free(); } @@ -100,4 +100,4 @@ Target NETensorHandle::target() const } } // namespace backends } // namespace graph -} // namespace arm_compute \ No newline at end of file +} // namespace arm_compute -- cgit v1.2.1