1 /* Copyright 2017 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_MEMORY_PLANNER_H_
16 #define TENSORFLOW_LITE_MEMORY_PLANNER_H_
17 
18 #include "tensorflow/lite/c/c_api_internal.h"
19 
20 namespace tflite {
21 
22 // A MemoryPlanner is responsible for planning and executing a number of
23 // memory-related operations that are necessary in TF Lite.
24 class MemoryPlanner {
25  public:
~MemoryPlanner()26   virtual ~MemoryPlanner() {}
27 
28   // Plans the necessary memory allocations. This is the MemoryPlanner's
29   // pre-processing step and is called when the graph structure is known but
30   // actual size of the tensors is not.
31   virtual TfLiteStatus PlanAllocations() = 0;
32 
33   // Allocates the necessary memory to execute all nodes in the interval
34   // [first_node, last_node].
35   virtual TfLiteStatus ExecuteAllocations(int first_node, int last_node) = 0;
36 
37   // Invalidates allocations made earlier. This is called when tensors sizes
38   // have changed. All planned allocations remain, but can't be used until
39   // ExecuteAllocations() is called.
40   virtual TfLiteStatus ResetAllocations() = 0;
41 };
42 
43 }  // namespace tflite
44 
45 #endif  // TENSORFLOW_LITE_MEMORY_PLANNER_H_
46