From 63e0beb9fb9646407d123e830165546e9129e95d Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Fri, 24 Sep 2021 14:04:27 +0100 Subject: Add support for non-constant weights and biases in CpuFullyConnected Changing the approach for specifying that weights and biases tensors are non-constant by making it a member of TensorInfo rather than an option of the functions. Resolves: COMPMID-4222, COMPMID-4811 Signed-off-by: Giorgio Arena Change-Id: I9b0081ccbcf8271ce029ba6755563d64c59e1d32 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6313 Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez Tello Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- arm_compute/core/ITensorInfo.h | 12 ++++++++++++ arm_compute/core/SubTensorInfo.h | 11 +++++++++++ arm_compute/core/TensorInfo.h | 10 ++++++++++ arm_compute/core/Types.h | 19 +++---------------- 4 files changed, 36 insertions(+), 16 deletions(-) (limited to 'arm_compute/core') diff --git a/arm_compute/core/ITensorInfo.h b/arm_compute/core/ITensorInfo.h index 1f5cf30148..6839d697e3 100644 --- a/arm_compute/core/ITensorInfo.h +++ b/arm_compute/core/ITensorInfo.h @@ -240,6 +240,11 @@ public: * @return True if its dynamic else false */ virtual bool is_dynamic() const = 0; + /** Flag indicating whether the values of the tensor are constant, meaning that they can change on kernel/function execution. + * + * @return True if values are constant else false + */ + virtual bool are_values_constant() const = 0; /** Set the flag whether the tensor size can be changed. * * @param[in] is_resizable Flag that marks the tensor if it can be changed or not. @@ -247,6 +252,13 @@ public: * @return Reference to this ITensorInfo object */ virtual ITensorInfo &set_is_resizable(bool is_resizable) = 0; + /** Set the flag whether the tensor values can change during kernel/function execution. + * + * @param[in] are_values_constant Flag that marks the tensor values if they can be changed or not. + * + * @return Reference to this ITensorInfo object + */ + virtual ITensorInfo &set_are_values_constant(bool are_values_constant) = 0; /** Valid region of the tensor. All elements in the valid region have defined values, i.e. are not undefined. * * @return The valid region. diff --git a/arm_compute/core/SubTensorInfo.h b/arm_compute/core/SubTensorInfo.h index 1b2278d99b..54836d0528 100644 --- a/arm_compute/core/SubTensorInfo.h +++ b/arm_compute/core/SubTensorInfo.h @@ -196,12 +196,23 @@ public: ARM_COMPUTE_ERROR_ON(_parent == nullptr); return _parent->is_dynamic(); } + bool are_values_constant() const override + { + ARM_COMPUTE_ERROR_ON(_parent == nullptr); + return _parent->are_values_constant(); + } ITensorInfo &set_is_resizable(bool is_resizable) override { ARM_COMPUTE_ERROR_ON(_parent == nullptr); _parent->set_is_resizable(is_resizable); return *this; } + ITensorInfo &set_are_values_constant(bool are_values_constant) override + { + ARM_COMPUTE_ERROR_ON(_parent == nullptr); + _parent->set_are_values_constant(are_values_constant); + return *this; + } ValidRegion valid_region() const override { return _valid_region; diff --git a/arm_compute/core/TensorInfo.h b/arm_compute/core/TensorInfo.h index a4330849bf..9bc86806fb 100644 --- a/arm_compute/core/TensorInfo.h +++ b/arm_compute/core/TensorInfo.h @@ -267,6 +267,10 @@ public: { return std::find(std::cbegin(_dims_state), std::cend(_dims_state), get_dynamic_state_value()) != std::cend(_dims_state); } + bool are_values_constant() const override + { + return _are_values_constant; + } ITensorInfo &set_is_resizable(bool is_resizable) override { _is_resizable = is_resizable; @@ -288,6 +292,11 @@ public: { return _data_layout; } + ITensorInfo &set_are_values_constant(bool are_values_constant) override + { + _are_values_constant = are_values_constant; + return *this; + } private: /** Calculates strides, offset and total size resulting from the specified padding around the XY plane. @@ -309,6 +318,7 @@ private: PaddingSize _padding; QuantizationInfo _quantization_info; DataLayout _data_layout; + bool _are_values_constant; }; } // namespace arm_compute #endif /*ARM_COMPUTE_TENSORINFO_H */ diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h index 0acbb3f59e..31199e138b 100644 --- a/arm_compute/core/Types.h +++ b/arm_compute/core/Types.h @@ -1557,7 +1557,6 @@ struct FullyConnectedLayerInfo bool transpose_weights{ true }; /**< Transpose weights if true. */ bool are_weights_reshaped{ false }; /**< Reshape the weights tensor if false. */ bool retain_internal_weights{ false }; /**< Retain internal reshaped weights. */ - bool constant_weights{ true }; /**< If false, weights can vary between runs. */ /* Other parameters */ bool fp_mixed_precision{ false }; /**< Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. */ @@ -1965,8 +1964,7 @@ public: _fp_mixed_precision(false), _broadcast_bias(false), _pretranspose_B(true), - _activation_info(), - _constant_weights(true) + _activation_info() { } /** Constructor @@ -1984,11 +1982,10 @@ public: * @param[in] fast_math (Optional) Use a data type of shorter width to improve performance * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix. * @param[in] activation_info (Optional) Activation to apply after the matrix multiplication - * @param[in] constant_weights (Optional) Weights have constant values throughout multiple executions */ GEMMInfo(bool is_a_reshaped, bool is_b_reshaped, bool reshape_b_only_on_first_run, int depth_output_gemm3d = 0, bool reinterpret_input_as_3d = false, bool retain_internal_weights = false, GEMMLowpOutputStageInfo gemmlowp_output_stage = GEMMLowpOutputStageInfo(), bool fp_mixed_precision = false, bool fast_math = false, bool broadcast_bias = false, - const ActivationLayerInfo &activation_info = ActivationLayerInfo(), bool constant_weights = true) noexcept + const ActivationLayerInfo &activation_info = ActivationLayerInfo()) noexcept : _is_a_reshaped(is_a_reshaped), _is_b_reshaped(is_b_reshaped), _reshape_b_only_on_first_run(reshape_b_only_on_first_run), @@ -2000,8 +1997,7 @@ public: _fp_mixed_precision(fp_mixed_precision), _broadcast_bias(broadcast_bias), _pretranspose_B(reshape_b_only_on_first_run), - _activation_info(activation_info), - _constant_weights(constant_weights) + _activation_info(activation_info) { } /** Flag which specifies if the matrix A has been reshaped @@ -2126,14 +2122,6 @@ public: { _activation_info = activation_info; } - /** Flag which specifies if the values of the weights tensor are constant throughout multiple executions or not - * - * @return True if the weights tensor is constant - */ - bool constant_weights() const - { - return _constant_weights; - }; private: bool _is_a_reshaped; @@ -2148,7 +2136,6 @@ private: bool _broadcast_bias; bool _pretranspose_B; ActivationLayerInfo _activation_info; - bool _constant_weights; }; /** Winograd information */ -- cgit v1.2.1