MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Prepare

Function Prepare

tensorflow/lite/kernels/basic_rnn.cc:50–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
51 // Check we have all the inputs and outputs we need.
52 TF_LITE_ENSURE_EQ(context, node->inputs->size, 5);
53 TF_LITE_ENSURE_EQ(context, node->outputs->size, 1);
54
55 const TfLiteTensor* input = GetInput(context, node, kInputTensor);
56 const TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
57 const TfLiteTensor* recurrent_weights =
58 GetInput(context, node, kRecurrentWeightsTensor);
59 const TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
60 const TfLiteTensor* hidden_state =
61 GetInput(context, node, kHiddenStateTensor);
62
63 // Check all the parameters of tensor match within themselves and match the
64 // input configuration.
65 const int batch_size = input->dims->data[0];
66 const int num_units = input_weights->dims->data[0];
67 TF_LITE_ENSURE_EQ(context, input->dims->data[1],
68 input_weights->dims->data[1]);
69 TF_LITE_ENSURE_EQ(context, input_weights->dims->data[0], bias->dims->data[0]);
70 TF_LITE_ENSURE_EQ(context, recurrent_weights->dims->data[0],
71 bias->dims->data[0]);
72 TF_LITE_ENSURE_EQ(context, recurrent_weights->dims->data[1],
73 bias->dims->data[0]);
74 TF_LITE_ENSURE_EQ(context, input->type, kTfLiteFloat32);
75 TF_LITE_ENSURE_EQ(context, input_weights->type, recurrent_weights->type);
76 TF_LITE_ENSURE_EQ(context, NumDimensions(hidden_state), 2);
77 TF_LITE_ENSURE_EQ(context, hidden_state->dims->data[0], batch_size);
78 TF_LITE_ENSURE_EQ(context, hidden_state->dims->data[1], num_units);
79
80 TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
81
82 // Resize output.
83 TfLiteIntArray* output_size_array = TfLiteIntArrayCreate(2);
84 output_size_array->data[0] = batch_size;
85 output_size_array->data[1] = num_units;
86 TF_LITE_ENSURE_OK(context,
87 context->ResizeTensor(context, output, output_size_array));
88
89 const bool is_hybrid = IsHybridOp(input, input_weights);
90
91 // Allocate temporary tensors to store quantized values of input and
92 // hidden_state tensors.
93 if (is_hybrid) {
94 int* scratch_tensor_index = reinterpret_cast<int*>(node->user_data);
95 TfLiteIntArrayFree(node->temporaries);
96 node->temporaries = TfLiteIntArrayCreate(3);
97 node->temporaries->data[0] = *scratch_tensor_index;
98 TfLiteTensor* input_quantized = GetTemporary(context, node, /*index=*/0);
99 input_quantized->type = input_weights->type;
100 input_quantized->allocation_type = kTfLiteArenaRw;
101 if (!TfLiteIntArrayEqual(input_quantized->dims, input->dims)) {
102 TfLiteIntArray* input_quantized_size = TfLiteIntArrayCopy(input->dims);
103 TF_LITE_ENSURE_OK(context, context->ResizeTensor(context, input_quantized,
104 input_quantized_size));
105 }
106 node->temporaries->data[1] = *scratch_tensor_index + 1;
107 TfLiteTensor* hidden_state_quantized =

Callers

nothing calls this directly

Calls 11

GetInputFunction · 0.85
NumDimensionsFunction · 0.85
GetOutputFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
IsHybridOpFunction · 0.85
TfLiteIntArrayFreeFunction · 0.85
GetTemporaryFunction · 0.85
TfLiteIntArrayEqualFunction · 0.85
TfLiteIntArrayCopyFunction · 0.85
ResizeTensorMethod · 0.80

Tested by

no test coverage detected