| 403 | } |
| 404 | |
| 405 | TfLiteStatus EvalHybrid( |
| 406 | const TfLiteTensor* input, const TfLiteTensor* bw_input, |
| 407 | const TfLiteTensor* fw_input_weights, |
| 408 | const TfLiteTensor* fw_recurrent_weights, const TfLiteTensor* fw_bias, |
| 409 | const TfLiteTensor* bw_input_weights, |
| 410 | const TfLiteTensor* bw_recurrent_weights, const TfLiteTensor* bw_bias, |
| 411 | const TfLiteTensor* aux_input, const TfLiteTensor* aux_fw_input_weights, |
| 412 | const TfLiteTensor* aux_bw_input_weights, |
| 413 | const TfLiteBidirectionalSequenceRNNParams* params, |
| 414 | TfLiteTensor* scaling_factors, TfLiteTensor* input_quantized, |
| 415 | TfLiteTensor* aux_input_quantized, TfLiteTensor* fw_hidden_state_quantized, |
| 416 | TfLiteTensor* fw_hidden_state, TfLiteTensor* fw_output, |
| 417 | TfLiteTensor* bw_hidden_state_quantized, TfLiteTensor* bw_hidden_state, |
| 418 | TfLiteTensor* bw_output) { |
| 419 | const bool time_major = params->time_major; |
| 420 | const int batch_size = |
| 421 | (time_major) ? input->dims->data[1] : input->dims->data[0]; |
| 422 | const int max_time = |
| 423 | (time_major) ? input->dims->data[0] : input->dims->data[1]; |
| 424 | const int input_size = input->dims->data[2]; |
| 425 | const int aux_input_size = (aux_input) ? aux_input->dims->data[2] : 0; |
| 426 | |
| 427 | const int fw_num_units = fw_input_weights->dims->data[0]; |
| 428 | const float* fw_bias_ptr = fw_bias->data.f; |
| 429 | const int8_t* fw_input_weights_ptr = GetTensorData<int8_t>(fw_input_weights); |
| 430 | float fw_input_weights_scale = fw_input_weights->params.scale; |
| 431 | const int8_t* fw_recurrent_weights_ptr = |
| 432 | GetTensorData<int8_t>(fw_recurrent_weights); |
| 433 | float fw_recurrent_weights_scale = fw_recurrent_weights->params.scale; |
| 434 | |
| 435 | const int bw_num_units = bw_input_weights->dims->data[0]; |
| 436 | const float* bw_bias_ptr = bw_bias->data.f; |
| 437 | const int8_t* bw_input_weights_ptr = GetTensorData<int8_t>(bw_input_weights); |
| 438 | float bw_input_weights_scale = bw_input_weights->params.scale; |
| 439 | const int8_t* bw_recurrent_weights_ptr = |
| 440 | GetTensorData<int8_t>(bw_recurrent_weights); |
| 441 | float bw_recurrent_weights_scale = bw_recurrent_weights->params.scale; |
| 442 | |
| 443 | // Set the auxiliary pointers and scales if needed. |
| 444 | const int8_t* aux_fw_input_weights_ptr = nullptr; |
| 445 | float aux_fw_input_weights_scale = 0.0f; |
| 446 | const int8_t* aux_bw_input_weights_ptr = nullptr; |
| 447 | float aux_bw_input_weights_scale = 0.0f; |
| 448 | int8_t* aux_quantized_input_ptr = nullptr; |
| 449 | if (aux_input_size > 0) { |
| 450 | aux_fw_input_weights_ptr = GetTensorData<int8_t>(aux_fw_input_weights); |
| 451 | aux_fw_input_weights_scale = aux_fw_input_weights->params.scale; |
| 452 | aux_bw_input_weights_ptr = GetTensorData<int8_t>(aux_bw_input_weights); |
| 453 | aux_bw_input_weights_scale = aux_bw_input_weights->params.scale; |
| 454 | aux_quantized_input_ptr = GetTensorData<int8_t>(aux_input_quantized); |
| 455 | } |
| 456 | |
| 457 | // Initialize temporary storage for quantized values. |
| 458 | int8_t* quantized_input_ptr = GetTensorData<int8_t>(input_quantized); |
| 459 | int8_t* fw_quantized_hidden_state_ptr = |
| 460 | GetTensorData<int8_t>(fw_hidden_state_quantized); |
| 461 | int8_t* bw_quantized_hidden_state_ptr = |
| 462 | GetTensorData<int8_t>(bw_hidden_state_quantized); |