• 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 
16 #ifndef TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_
17 #define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_
18 
19 #include "tensorflow/lite/micro/compatibility.h"
20 #include "tensorflow/lite/micro/memory_planner/memory_planner.h"
21 
22 namespace tflite {
23 
24 // The simplest possible memory planner that just lays out all buffers at
25 // increasing offsets without trying to reuse memory.
26 class LinearMemoryPlanner : public MemoryPlanner {
27  public:
28   LinearMemoryPlanner();
29   ~LinearMemoryPlanner() override;
30 
31   TfLiteStatus AddBuffer(tflite::ErrorReporter* error_reporter, int size,
32                          int first_time_used, int last_time_used) override;
33 
34   size_t GetMaximumMemorySize() override;
35   int GetBufferCount() override;
36   TfLiteStatus GetOffsetForBuffer(tflite::ErrorReporter* error_reporter,
37                                   int buffer_index, int* offset) override;
38 
39  private:
40   static constexpr int kMaxBufferCount = 1024;
41   size_t buffer_offsets_[kMaxBufferCount];
42   int current_buffer_count_;
43   size_t next_free_offset_;
44 
45   TF_LITE_REMOVE_VIRTUAL_DELETE
46 };
47 
48 }  // namespace tflite
49 
50 #endif  // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_
51