• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #ifndef TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_
16 #define TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "tensorflow/lite/c/common.h"
22 #include "tensorflow/lite/core/api/error_reporter.h"
23 #include "tensorflow/lite/schema/schema_generated.h"
24 
25 namespace tflite {
26 
27 // Returns the next pointer address aligned to the given alignment.
28 uint8_t* AlignPointerUp(uint8_t* data, size_t alignment);
29 
30 // Returns the previous pointer address aligned to the given alignment.
31 uint8_t* AlignPointerDown(uint8_t* data, size_t alignment);
32 
33 // Returns an increased size that's a multiple of alignment.
34 size_t AlignSizeUp(size_t size, size_t alignment);
35 
36 // Returns size in bytes for a given TfLiteType.
37 TfLiteStatus TfLiteTypeSizeOf(TfLiteType type, size_t* size);
38 
39 // How many bytes are needed to hold a tensor's contents.
40 TfLiteStatus BytesRequiredForTensor(const tflite::Tensor& flatbuffer_tensor,
41                                     size_t* bytes, size_t* type_size,
42                                     ErrorReporter* error_reporter);
43 
44 // How many bytes are used in a TfLiteEvalTensor instance. The byte length is
45 // returned in out_bytes.
46 TfLiteStatus TfLiteEvalTensorByteLength(const TfLiteEvalTensor* eval_tensor,
47                                         size_t* out_bytes);
48 
49 // Deduce output dimensions from input and allocate given size.
50 // Useful for operators with two inputs where the largest input should equal the
51 // output dimension.
52 TfLiteStatus AllocateOutputDimensionsFromInput(TfLiteContext* context,
53                                                const TfLiteTensor* input1,
54                                                const TfLiteTensor* input2,
55                                                TfLiteTensor* output);
56 
57 }  // namespace tflite
58 
59 #endif  // TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_
60