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

Function InitTemporaryTensors

tensorflow/lite/kernels/rfft2d.cc:47–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45bool IsPowerOfTwo(uint32_t v) { return v && !(v & (v - 1)); }
46
47static TfLiteStatus InitTemporaryTensors(TfLiteContext* context,
48 TfLiteNode* node) {
49 OpData* data = reinterpret_cast<OpData*>(node->user_data);
50 // The prepare function may be executed multiple times. But temporary tensors
51 // only need to be initiated once.
52 if (data->fft_integer_working_area_id != kTensorNotAllocated &&
53 data->fft_double_working_area_id != kTensorNotAllocated) {
54 return kTfLiteOk;
55 }
56
57 TfLiteIntArrayFree(node->temporaries);
58 // Create two temporary tensors.
59 node->temporaries = TfLiteIntArrayCreate(2);
60 int first_new_index;
61 TF_LITE_ENSURE_STATUS(context->AddTensors(context, 2, &first_new_index));
62 node->temporaries->data[kFftIntegerWorkingAreaTensor] = first_new_index;
63 data->fft_integer_working_area_id = first_new_index;
64 node->temporaries->data[kFftDoubleWorkingAreaTensor] = first_new_index + 1;
65 data->fft_double_working_area_id = first_new_index + 1;
66
67 // Set up FFT integer working area buffer.
68 TfLiteTensor* fft_integer_working_area =
69 GetTemporary(context, node, kFftIntegerWorkingAreaTensor);
70 fft_integer_working_area->type = kTfLiteInt32;
71 // If fft_length is not a constant tensor, fft_integer_working_area will be
72 // set to dynamic later in Prepare.
73 fft_integer_working_area->allocation_type = kTfLiteArenaRw;
74
75 // Set up FFT double working area buffer.
76 TfLiteTensor* fft_double_working_area =
77 GetTemporary(context, node, kFftDoubleWorkingAreaTensor);
78 // fft_double_working_area is a double tensor. Ideally, double should be
79 // added into tflite data types. However, since fft_double_working_area is a
80 // temporary tensor, and there are no ops having double input/output tensors
81 // in tflite at this point, adding double as a tflite data type may confuse
82 // users that double is supported. As a results, kTfLiteInt64 is used here
83 // for memory allocation. And it will be cast into double in Eval when being
84 // used.
85 fft_double_working_area->type = kTfLiteInt64;
86 // If fft_length is not a constant tensor, fft_double_working_area will be
87 // set to dynamic later in Prepare.
88 fft_double_working_area->allocation_type = kTfLiteArenaRw;
89
90 return kTfLiteOk;
91}
92
93TfLiteStatus ResizeOutputandTemporaryTensors(TfLiteContext* context,
94 TfLiteNode* node) {

Callers 1

PrepareFunction · 0.85

Calls 4

TfLiteIntArrayFreeFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
GetTemporaryFunction · 0.85
AddTensorsMethod · 0.45

Tested by

no test coverage detected