Compute Library
 23.11
arm_compute::utils::info_helpers Namespace Reference

Functions

bool is_relu (ActivationLayerInfo activation_info)
 Checks if activation information correspond to a relu activation function. More...
 
bool is_relu6 (ActivationLayerInfo activation_info)
 Checks if activation information correspond to a relu6 activation function. More...
 
template<typename T >
void build_lstm_params_tensor_info (const LSTMParams< T > &lstm_params, LSTMParams< ITensorInfo > *lstm_params_info)
 Build LSTMParams<ITensorInfo> object by extracting the metadata from each tensor. More...
 

Function Documentation

◆ build_lstm_params_tensor_info()

void arm_compute::utils::info_helpers::build_lstm_params_tensor_info ( const LSTMParams< T > &  lstm_params,
LSTMParams< ITensorInfo > *  lstm_params_info 
)
inline

Build LSTMParams<ITensorInfo> object by extracting the metadata from each tensor.

Parameters
[in]lstm_paramsThe LSTMParams<T> object containing the tensors.
[out]lstm_params_infoThe LSTMParams<ITensorInfo> to be constructed.

Definition at line 73 of file InfoHelpers.h.

74 {
75  if (lstm_params.has_peephole_opt())
76  {
77  ARM_COMPUTE_ERROR_ON_NULLPTR(lstm_params.cell_to_forget_weights(), lstm_params.cell_to_output_weights());
78  lstm_params_info->set_peephole_params(lstm_params.cell_to_forget_weights()->info(),
79  lstm_params.cell_to_output_weights()->info());
80  }
81  if (lstm_params.has_projection())
82  {
83  ARM_COMPUTE_ERROR_ON_NULLPTR(lstm_params.projection_weights());
84  lstm_params_info->set_projection_params(
85  lstm_params.projection_weights()->info(),
86  lstm_params.projection_bias() != nullptr ? lstm_params.projection_bias()->info() : nullptr);
87  }
88  if (!lstm_params.has_cifg_opt())
89  {
90  ARM_COMPUTE_ERROR_ON_NULLPTR(lstm_params.input_to_input_weights(), lstm_params.recurrent_to_input_weights(),
91  lstm_params.input_gate_bias());
92 
93  ITensorInfo *cell_to_input_weights_info =
94  (lstm_params.has_peephole_opt()) ? lstm_params.cell_to_input_weights()->info() : nullptr;
95  lstm_params_info->set_cifg_params(lstm_params.input_to_input_weights()->info(),
96  lstm_params.recurrent_to_input_weights()->info(), cell_to_input_weights_info,
97  lstm_params.input_gate_bias()->info());
98  }
99  if (lstm_params.use_layer_norm())
100  {
101  ARM_COMPUTE_ERROR_ON_NULLPTR(lstm_params.forget_layer_norm_weights(), lstm_params.output_layer_norm_weights(),
102  lstm_params.cell_layer_norm_weights());
103  if (!lstm_params.has_cifg_opt())
104  {
105  ARM_COMPUTE_ERROR_ON_NULLPTR(lstm_params.input_layer_norm_weights());
106  }
107 
108  ITensorInfo *forget_info = lstm_params.forget_layer_norm_weights()->info();
109  ITensorInfo *cell_info = lstm_params.cell_layer_norm_weights()->info();
110  ITensorInfo *output_info = lstm_params.output_layer_norm_weights()->info();
111  ITensorInfo *input_info = lstm_params.has_cifg_opt() ? nullptr : lstm_params.input_layer_norm_weights()->info();
112 
113  lstm_params_info->set_layer_normalization_params(input_info, forget_info, cell_info, output_info);
114  }
115 
116  lstm_params_info->set_matmul_scale_params(
117  lstm_params.input_intermediate_scale(), lstm_params.forget_intermediate_scale(),
118  lstm_params.cell_intermediate_scale(), lstm_params.output_intermediate_scale());
119 
120  lstm_params_info->set_hidden_state_params(lstm_params.hidden_state_zero(), lstm_params.hidden_state_scale());
121 }

References ARM_COMPUTE_ERROR_ON_NULLPTR, LSTMParams< T >::cell_intermediate_scale(), LSTMParams< T >::cell_layer_norm_weights(), LSTMParams< T >::cell_to_forget_weights(), LSTMParams< T >::cell_to_input_weights(), LSTMParams< T >::cell_to_output_weights(), LSTMParams< T >::forget_intermediate_scale(), LSTMParams< T >::forget_layer_norm_weights(), LSTMParams< T >::has_cifg_opt(), LSTMParams< T >::has_peephole_opt(), LSTMParams< T >::has_projection(), LSTMParams< T >::hidden_state_scale(), LSTMParams< T >::hidden_state_zero(), LSTMParams< T >::input_gate_bias(), arm_compute::test::validation::input_info, LSTMParams< T >::input_intermediate_scale(), LSTMParams< T >::input_layer_norm_weights(), LSTMParams< T >::input_to_input_weights(), arm_compute::test::validation::output_info, LSTMParams< T >::output_intermediate_scale(), LSTMParams< T >::output_layer_norm_weights(), LSTMParams< T >::projection_bias(), LSTMParams< T >::projection_weights(), LSTMParams< T >::recurrent_to_input_weights(), LSTMParams< T >::set_cifg_params(), LSTMParams< T >::set_hidden_state_params(), LSTMParams< T >::set_layer_normalization_params(), LSTMParams< T >::set_matmul_scale_params(), LSTMParams< T >::set_peephole_params(), LSTMParams< T >::set_projection_params(), and LSTMParams< T >::use_layer_norm().

Referenced by NELSTMLayer::configure(), NEQLSTMLayer::configure(), CLLSTMLayer::configure(), and CLQLSTMLayer::configure().

◆ is_relu()

bool arm_compute::utils::info_helpers::is_relu ( ActivationLayerInfo  activation_info)
inline

Checks if activation information correspond to a relu activation function.

Parameters
[in]activation_infoActivation metadata
Returns
True if activation metadata correspond to a relu activation else false

Definition at line 43 of file InfoHelpers.h.

44 {
45  return activation_info.enabled() && activation_info.activation() == ActivationLayerInfo::ActivationFunction::RELU;
46 }

References ActivationLayerInfo::activation(), and ActivationLayerInfo::enabled().

◆ is_relu6()

bool arm_compute::utils::info_helpers::is_relu6 ( ActivationLayerInfo  activation_info)
inline

Checks if activation information correspond to a relu6 activation function.

Parameters
[in]activation_infoActivation metadata
Returns
True if activation metadata correspond to a relu6 activation else false

Definition at line 54 of file InfoHelpers.h.

55 {
56  const bool is_lu_bounded_relu =
57  activation_info.activation() == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU &&
58  activation_info.a() == 6.f && activation_info.b() == 0.f;
59  const bool is_bounded_relu =
60  activation_info.activation() == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU &&
61  activation_info.a() == 6.f;
62  return activation_info.enabled() && (is_lu_bounded_relu || is_bounded_relu);
63 }

References ActivationLayerInfo::a(), ActivationLayerInfo::activation(), ActivationLayerInfo::b(), and ActivationLayerInfo::enabled().

arm_compute::test::validation::input_info
input_info
Definition: DirectConvolutionLayer.cpp:547
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
arm_compute::test::validation::output_info
output_info
Definition: DirectConvolutionLayer.cpp:547