| 161 | } |
| 162 | |
| 163 | TfLiteStatus EvalHybrid(const TfLiteTensor* input, |
| 164 | const TfLiteTensor* input_weights, |
| 165 | const TfLiteTensor* recurrent_weights, |
| 166 | const TfLiteTensor* bias, const TfLiteRNNParams* params, |
| 167 | TfLiteTensor* input_scratch, |
| 168 | TfLiteTensor* hidden_state_scratch, |
| 169 | TfLiteTensor* scaling_factors, |
| 170 | TfLiteTensor* hidden_state, TfLiteTensor* output) { |
| 171 | const int batch_size = input->dims->data[0]; |
| 172 | const int num_units = input_weights->dims->data[0]; |
| 173 | const int input_size = input->dims->data[1]; |
| 174 | const int output_batch_leading_dim = |
| 175 | output->dims->data[output->dims->size - 1]; |
| 176 | |
| 177 | // Initialize the pointer to hidden state. |
| 178 | float* hidden_state_ptr_batch = hidden_state->data.f; |
| 179 | // Initialize the pointer to input and output. |
| 180 | const float* input_ptr_batch = input->data.f; |
| 181 | float* output_ptr_batch = output->data.f; |
| 182 | // Initialize input_weights, recurrent_weights and bias. |
| 183 | const int8_t* input_weights_ptr = GetTensorData<int8_t>(input_weights); |
| 184 | const int8_t* recurrent_weights_ptr = |
| 185 | GetTensorData<int8_t>(recurrent_weights); |
| 186 | const float* bias_ptr = bias->data.f; |
| 187 | // Get the scale of the quantized weights. |
| 188 | float input_weights_scale = input_weights->params.scale; |
| 189 | float recurrent_weights_scale = recurrent_weights->params.scale; |
| 190 | // Initialize temporary storage for quantized values. |
| 191 | int8_t* quantized_input_ptr = GetTensorData<int8_t>(input_scratch); |
| 192 | int8_t* quantized_hidden_state_ptr = |
| 193 | GetTensorData<int8_t>(hidden_state_scratch); |
| 194 | float* scaling_factors_ptr = scaling_factors->data.f; |
| 195 | |
| 196 | kernel_utils::RnnBatchStep( |
| 197 | input_ptr_batch, input_weights_ptr, input_weights_scale, |
| 198 | recurrent_weights_ptr, recurrent_weights_scale, bias_ptr, input_size, |
| 199 | num_units, batch_size, output_batch_leading_dim, params->activation, |
| 200 | quantized_input_ptr, quantized_hidden_state_ptr, scaling_factors_ptr, |
| 201 | hidden_state_ptr_batch, output_ptr_batch); |
| 202 | return kTfLiteOk; |
| 203 | } |
| 204 | |
| 205 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
| 206 | auto* params = reinterpret_cast<TfLiteRNNParams*>(node->builtin_data); |