From e357a254a830bf4d66f235813fac021d61cf225d Mon Sep 17 00:00:00 2001 From: SiCong Li Date: Sun, 9 Aug 2020 20:05:52 +0100 Subject: COMPMID-3454 Patch1: Relocate data_type_from_name to core/Utils Change-Id: I33436dab77a47868fbd9872e0b4cf54b3a173e65 Signed-off-by: SiCong Li Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3694 Tested-by: Arm Jenkins Reviewed-by: Manuel Bottini Comments-Addressed: Arm Jenkins --- src/core/Utils.cpp | 92 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 33 deletions(-) (limited to 'src/core/Utils.cpp') diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp index cec7a1b4ba..3c8e735c40 100644 --- a/src/core/Utils.cpp +++ b/src/core/Utils.cpp @@ -33,9 +33,9 @@ #include #include -using namespace arm_compute; - -std::string arm_compute::read_file(const std::string &filename, bool binary) +namespace arm_compute +{ +std::string read_file(const std::string &filename, bool binary) { std::string out; std::ifstream fs; @@ -73,7 +73,7 @@ std::string arm_compute::read_file(const std::string &filename, bool binary) return out; } -const std::string &arm_compute::string_from_format(Format format) +const std::string &string_from_format(Format format) { static std::map formats_map = { @@ -99,7 +99,7 @@ const std::string &arm_compute::string_from_format(Format format) return formats_map[format]; } -const std::string &arm_compute::string_from_channel(Channel channel) +const std::string &string_from_channel(Channel channel) { static std::map channels_map = { @@ -120,7 +120,7 @@ const std::string &arm_compute::string_from_channel(Channel channel) return channels_map[channel]; } -const std::string &arm_compute::string_from_data_layout(DataLayout dl) +const std::string &string_from_data_layout(DataLayout dl) { static std::map dl_map = { @@ -132,7 +132,7 @@ const std::string &arm_compute::string_from_data_layout(DataLayout dl) return dl_map[dl]; } -const std::string &arm_compute::string_from_data_type(DataType dt) +const std::string &string_from_data_type(DataType dt) { static std::map dt_map = { @@ -160,7 +160,7 @@ const std::string &arm_compute::string_from_data_type(DataType dt) return dt_map[dt]; } -const std::string &arm_compute::string_from_activation_func(ActivationLayerInfo::ActivationFunction act) +const std::string &string_from_activation_func(ActivationLayerInfo::ActivationFunction act) { static std::map act_map = { @@ -184,7 +184,7 @@ const std::string &arm_compute::string_from_activation_func(ActivationLayerInfo: return act_map[act]; } -const std::string &arm_compute::string_from_matrix_pattern(MatrixPattern pattern) +const std::string &string_from_matrix_pattern(MatrixPattern pattern) { static std::map pattern_map = { @@ -197,7 +197,7 @@ const std::string &arm_compute::string_from_matrix_pattern(MatrixPattern pattern return pattern_map[pattern]; } -const std::string &arm_compute::string_from_non_linear_filter_function(NonLinearFilterFunction function) +const std::string &string_from_non_linear_filter_function(NonLinearFilterFunction function) { static std::map func_map = { @@ -209,7 +209,7 @@ const std::string &arm_compute::string_from_non_linear_filter_function(NonLinear return func_map[function]; } -const std::string &arm_compute::string_from_interpolation_policy(InterpolationPolicy policy) +const std::string &string_from_interpolation_policy(InterpolationPolicy policy) { static std::map interpolation_policy_map = { @@ -221,7 +221,7 @@ const std::string &arm_compute::string_from_interpolation_policy(InterpolationPo return interpolation_policy_map[policy]; } -const std::string &arm_compute::string_from_border_mode(BorderMode border_mode) +const std::string &string_from_border_mode(BorderMode border_mode) { static std::map border_mode_map = { @@ -233,7 +233,7 @@ const std::string &arm_compute::string_from_border_mode(BorderMode border_mode) return border_mode_map[border_mode]; } -const std::string &arm_compute::string_from_norm_type(NormType type) +const std::string &string_from_norm_type(NormType type) { static std::map norm_type_map = { @@ -245,7 +245,7 @@ const std::string &arm_compute::string_from_norm_type(NormType type) return norm_type_map[type]; } -const std::string &arm_compute::string_from_pooling_type(PoolingType type) +const std::string &string_from_pooling_type(PoolingType type) { static std::map pool_type_map = { @@ -257,7 +257,7 @@ const std::string &arm_compute::string_from_pooling_type(PoolingType type) return pool_type_map[type]; } -const std::string &arm_compute::string_from_gemmlowp_output_stage(GEMMLowpOutputStageType output_stage) +const std::string &string_from_gemmlowp_output_stage(GEMMLowpOutputStageType output_stage) { static std::map output_stage_map = { @@ -270,7 +270,7 @@ const std::string &arm_compute::string_from_gemmlowp_output_stage(GEMMLowpOutput return output_stage_map[output_stage]; } -std::string arm_compute::string_from_pixel_value(const PixelValue &value, const DataType data_type) +std::string string_from_pixel_value(const PixelValue &value, const DataType data_type) { std::stringstream ss; std::string converted_string; @@ -323,21 +323,45 @@ std::string arm_compute::string_from_pixel_value(const PixelValue &value, const return converted_string; } -std::string arm_compute::lower_string(const std::string &val) +DataType data_type_from_name(const std::string &name) +{ + static const std::map data_types = + { + { "f16", DataType::F16 }, + { "f32", DataType::F32 }, + { "qasymm8", DataType::QASYMM8 }, + }; + +#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED + try + { +#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ + return data_types.at(utility::tolower(name)); + +#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED + } + catch(const std::out_of_range &) + { + ARM_COMPUTE_ERROR_VAR("Invalid data type name: %s", name.c_str()); + } +#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ +} + +std::string lower_string(const std::string &val) { std::string res = val; std::transform(res.begin(), res.end(), res.begin(), ::tolower); return res; } -PadStrideInfo arm_compute::calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout, const Size2D &dilation, - const DimensionRoundingType &rounding_type) +PadStrideInfo calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout, const Size2D &dilation, + const DimensionRoundingType &rounding_type) { const auto &strides = conv_info.stride(); ARM_COMPUTE_ERROR_ON_MSG((strides.first < 1 || strides.second < 1), "Stride values should be greater than or equal to 1."); - const unsigned int width_idx = arm_compute::get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); - const unsigned int height_idx = arm_compute::get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); + const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); + const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); const unsigned int in_width = input_shape[width_idx]; const unsigned int in_height = input_shape[height_idx]; const unsigned int kernel_width = weights_shape[width_idx]; @@ -372,9 +396,9 @@ PadStrideInfo arm_compute::calculate_same_pad(TensorShape input_shape, TensorSha return same_info; } -std::pair arm_compute::deconvolution_output_dimensions(unsigned int in_width, unsigned int in_height, - unsigned int kernel_width, unsigned int kernel_height, - const PadStrideInfo &pad_stride_info) +std::pair deconvolution_output_dimensions(unsigned int in_width, unsigned int in_height, + unsigned int kernel_width, unsigned int kernel_height, + const PadStrideInfo &pad_stride_info) { const unsigned int pad_left = pad_stride_info.pad_left(); const unsigned int pad_top = pad_stride_info.pad_top(); @@ -392,10 +416,10 @@ std::pair arm_compute::deconvolution_output_dimensio return std::make_pair(w, h); } -std::pair arm_compute::scaled_dimensions(int width, int height, - int kernel_width, int kernel_height, - const PadStrideInfo &pad_stride_info, - const Size2D &dilation) +std::pair scaled_dimensions(int width, int height, + int kernel_width, int kernel_height, + const PadStrideInfo &pad_stride_info, + const Size2D &dilation) { const int dilation_x = dilation.x(); const int dilation_y = dilation.y(); @@ -426,7 +450,7 @@ std::pair arm_compute::scaled_dimensions(int width, return std::make_pair(static_cast(w), static_cast(h)); } -bool arm_compute::needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis) +bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis) { const bool is_min_max = (op == ReductionOperation::MAX || op == ReductionOperation::MIN); const bool is_quantized_type = is_data_type_quantized(dt); @@ -435,7 +459,7 @@ bool arm_compute::needs_serialized_reduction(ReductionOperation op, DataType dt, return !is_first_dim || is_min_max || is_quantized_type; } -QuantizationInfo arm_compute::get_softmax_output_quantization_info(DataType input_type, bool is_log) +QuantizationInfo get_softmax_output_quantization_info(DataType input_type, bool is_log) { // Note: Output quantization info for softmax should always have // * Softmax with QASYMM8: scale = 1/256, offset = 0 @@ -456,7 +480,7 @@ QuantizationInfo arm_compute::get_softmax_output_quantization_info(DataType inpu return QuantizationInfo(1.f / 256, 0); } -std::pair arm_compute::get_quantized_activation_min_max(ActivationLayerInfo act_info, DataType data_type, UniformQuantizationInfo oq_info) +std::pair get_quantized_activation_min_max(ActivationLayerInfo act_info, DataType data_type, UniformQuantizationInfo oq_info) { const bool is_qasymm8_signed = is_data_type_quantized_asymmetric_signed(data_type); const auto a = act_info.a(); @@ -472,7 +496,7 @@ std::pair arm_compute::get_quantized_activation_min_max(Activa } #ifdef ARM_COMPUTE_ASSERTS_ENABLED -void arm_compute::print_consecutive_elements(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n, int stream_width, const std::string &element_delim) +void print_consecutive_elements(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n, int stream_width, const std::string &element_delim) { switch(dt) { @@ -514,7 +538,7 @@ void arm_compute::print_consecutive_elements(std::ostream &s, DataType dt, const } } -int arm_compute::max_consecutive_elements_display_width(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n) +int max_consecutive_elements_display_width(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n) { switch(dt) { @@ -548,3 +572,5 @@ int arm_compute::max_consecutive_elements_display_width(std::ostream &s, DataTyp return 0; } #endif /* ARM_COMPUTE_ASSERTS_ENABLED */ + +} // namespace arm_compute \ No newline at end of file -- cgit v1.2.1