diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2018-07-20 13:23:44 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:54:54 +0000 |
commit | e2220551b7a64b929650ba9a60529c31e70c13c5 (patch) | |
tree | 5d609887f15b4392cdade7bb388710ceafc62260 /arm_compute/core | |
parent | eff8d95991205e874091576e2d225f63246dd0bb (diff) | |
download | ComputeLibrary-e2220551b7a64b929650ba9a60529c31e70c13c5.tar.gz |
COMPMID-1367: Enable NHWC in graph examples
Change-Id: Iabc54a3a1bdcd46a9a921cda39c7c85fef672b72
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/141449
Reviewed-by: Giorgio Arena <giorgio.arena@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core')
-rw-r--r-- | arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h | 2 | ||||
-rw-r--r-- | arm_compute/core/Helpers.h | 60 | ||||
-rw-r--r-- | arm_compute/core/utils/misc/ShapeCalculator.h | 30 |
3 files changed, 53 insertions, 39 deletions
diff --git a/arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h b/arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h index f2d37a781c..beeb8b838e 100644 --- a/arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h +++ b/arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h @@ -72,7 +72,7 @@ private: const ICLTensor *_input; ICLTensor *_output; BorderSize _border_size; - bool _is_in_map; + bool _is_norm_across_width; }; } // namespace arm_compute #endif /*__ARM_COMPUTE_CLNORMALIZATIONLAYERKERNEL_H__ */ diff --git a/arm_compute/core/Helpers.h b/arm_compute/core/Helpers.h index 374e36442b..ef59323073 100644 --- a/arm_compute/core/Helpers.h +++ b/arm_compute/core/Helpers.h @@ -111,28 +111,6 @@ struct is_contained<T, std::tuple<U, Ts...>> : is_contained<T, std::tuple<Ts...> }; } -/** Calculate the number of output tiles required by Winograd Convolution layer. This utility function can be used by the Winograd input transform - * to know the number of tiles on the x and y direction - * - * @param[in] in_dims Spatial dimensions of the input tensor of convolution layer - * @param[in] kernel_size Kernel size - * @param[in] output_tile_size Size of a single output tile - * @param[in] conv_info Convolution info (i.e. pad, stride,...) - * - * @return the number of output tiles along the x and y directions of size "output_tile_size" - */ -inline Size2D compute_winograd_convolution_tiles(const Size2D &in_dims, const Size2D &kernel_size, const Size2D &output_tile_size, const PadStrideInfo &conv_info) -{ - int num_tiles_x = std::ceil((in_dims.width - (kernel_size.width - 1) + conv_info.pad_left() + conv_info.pad_right()) / static_cast<float>(output_tile_size.width)); - int num_tiles_y = std::ceil((in_dims.height - (kernel_size.height - 1) + conv_info.pad_top() + conv_info.pad_bottom()) / static_cast<float>(output_tile_size.height)); - - // Clamp in case we provide paddings but we have 1D convolution - num_tiles_x = std::min(num_tiles_x, static_cast<int>(in_dims.width)); - num_tiles_y = std::min(num_tiles_y, static_cast<int>(in_dims.height)); - - return Size2D(num_tiles_x, num_tiles_y); -} - /** Computes bilinear interpolation using the pointer to the top-left pixel and the pixel's distance between * the real coordinates and the smallest following integer coordinates. Input must be in single channel format. * @@ -694,6 +672,44 @@ inline int coords2index(const TensorShape &shape, const Coordinates &coord); * @return The int conversion of the requested data layout index. */ inline size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension); + +/** Calculate the normalization dimension index for a given normalization type + * + * @param[in] layout Data layout of the input and output tensor + * @param[in] info Normalization info + * + * @return Normalization dimension index + */ +inline unsigned int get_normalization_dimension_index(DataLayout layout, const NormalizationLayerInfo &info) +{ + const unsigned int width_idx = get_data_layout_dimension_index(layout, DataLayoutDimension::WIDTH); + const unsigned int channel_idx = get_data_layout_dimension_index(layout, DataLayoutDimension::CHANNEL); + + return info.is_in_map() ? width_idx : channel_idx; +} + +/** Calculate the number of output tiles required by Winograd Convolution layer. This utility function can be used by the Winograd input transform + * to know the number of tiles on the x and y direction + * + * @param[in] in_dims Spatial dimensions of the input tensor of convolution layer + * @param[in] kernel_size Kernel size + * @param[in] output_tile_size Size of a single output tile + * @param[in] conv_info Convolution info (i.e. pad, stride,...) + * + * @return the number of output tiles along the x and y directions of size "output_tile_size" + */ +inline Size2D compute_winograd_convolution_tiles(const Size2D &in_dims, const Size2D &kernel_size, const Size2D &output_tile_size, const PadStrideInfo &conv_info) +{ + int num_tiles_x = std::ceil((in_dims.width - (kernel_size.width - 1) + conv_info.pad_left() + conv_info.pad_right()) / static_cast<float>(output_tile_size.width)); + int num_tiles_y = std::ceil((in_dims.height - (kernel_size.height - 1) + conv_info.pad_top() + conv_info.pad_bottom()) / static_cast<float>(output_tile_size.height)); + + // Clamp in case we provide paddings but we have 1D convolution + num_tiles_x = std::min(num_tiles_x, static_cast<int>(in_dims.width)); + num_tiles_y = std::min(num_tiles_y, static_cast<int>(in_dims.height)); + + return Size2D(num_tiles_x, num_tiles_y); +} + } // namespace arm_compute #include "arm_compute/core/Helpers.inl" diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index e5516ba154..dbf26a423d 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -201,15 +201,8 @@ inline TensorShape compute_im2col_fc_shape(const ITensorInfo *input, const int n inline TensorShape compute_im2col_flatten_shape(const ITensorInfo *input) { // The output shape will be the flatten version of the input (i.e. [ width * height * channels, 1, 1, ... ] ). Used for FlattenLayer. - - ARM_COMPUTE_ERROR_ON(input->num_dimensions() < 3); - TensorShape output_shape{ input->tensor_shape() }; - - const size_t flatten_shape = input->dimension(0) * input->dimension(1) * input->dimension(2); - output_shape.set(0, flatten_shape); - output_shape.remove_dimension(1); - output_shape.remove_dimension(1); + output_shape.collapse(3, 0); return output_shape; } @@ -403,20 +396,25 @@ inline TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo } template <typename T> -inline TensorShape get_shape_from_info(T *info) +inline TensorShape extract_shape(T *data) +{ + return data->info()->tensor_shape(); +} + +inline TensorShape extract_shape(ITensorInfo *data) { - return info->info()->tensor_shape(); + return data->tensor_shape(); } -inline TensorShape get_shape_from_info(ITensorInfo *info) +inline TensorShape extract_shape(const TensorShape *data) { - return info->tensor_shape(); + return *data; } template <typename T> inline TensorShape calculate_depth_concatenate_shape(const std::vector<T *> &inputs_vector) { - TensorShape out_shape = get_shape_from_info(inputs_vector[0]); + TensorShape out_shape = extract_shape(inputs_vector[0]); size_t max_x = 0; size_t max_y = 0; @@ -425,7 +423,7 @@ inline TensorShape calculate_depth_concatenate_shape(const std::vector<T *> &inp for(const auto &tensor : inputs_vector) { ARM_COMPUTE_ERROR_ON(tensor == nullptr); - const TensorShape shape = get_shape_from_info(tensor); + const TensorShape shape = extract_shape(tensor); max_x = std::max(shape.x(), max_x); max_y = std::max(shape.y(), max_y); depth += shape.z(); @@ -441,13 +439,13 @@ inline TensorShape calculate_depth_concatenate_shape(const std::vector<T *> &inp template <typename T> inline TensorShape calculate_width_concatenate_shape(const std::vector<T *> &inputs_vector) { - TensorShape out_shape = get_shape_from_info(inputs_vector[0]); + TensorShape out_shape = extract_shape(inputs_vector[0]); size_t width = 0; for(const auto &tensor : inputs_vector) { ARM_COMPUTE_ERROR_ON(tensor == nullptr); - const TensorShape shape = get_shape_from_info(tensor); + const TensorShape shape = extract_shape(tensor); width += shape.x(); } |