• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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_EXPERIMENTAL_RESOURCE_INITIALIZATION_STATUS_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_RESOURCE_INITIALIZATION_STATUS_H_
17 
18 #include <memory>
19 #include <unordered_map>
20 
21 #include "tensorflow/lite/c/common.h"
22 #include "tensorflow/lite/experimental/resource/resource_base.h"
23 
24 namespace tflite {
25 namespace resource {
26 
27 /// WARNING: Experimental interface, subject to change.
28 // An initialization status class. This class will record the completion status
29 // of the initialization procedure. For example, when the initialization
30 // subgraph should be invoked  once in a life cycle, this class instance will
31 // have the initialization status in order to make sure the followup invocations
32 // to invoke the initalization subgraph can be ignored safely.
33 class InitializationStatus : public ResourceBase {
34  public:
InitializationStatus()35   InitializationStatus() {}
InitializationStatus(InitializationStatus && other)36   InitializationStatus(InitializationStatus&& other) {
37     is_initialized_ = other.is_initialized_;
38   }
39 
40   InitializationStatus(const InitializationStatus&) = delete;
41   InitializationStatus& operator=(const InitializationStatus&) = delete;
42 
~InitializationStatus()43   ~InitializationStatus() override {}
44 
45   // Mark initialization is done.
46   void MarkInitializationIsDone();
47 
48   // Returns true if this initialization is done.
49   bool IsInitialized() override;
50 
GetMemoryUsage()51   size_t GetMemoryUsage() override { return 0; };
52 
53  private:
54   // True if the initialization process is done.
55   bool is_initialized_ = false;
56 };
57 
58 /// WARNING: Experimental interface, subject to change.
59 using InitializationStatusMap =
60     std::unordered_map<std::int32_t, std::unique_ptr<InitializationStatus>>;
61 
62 InitializationStatus* GetInitializationStatus(InitializationStatusMap* map,
63                                               int subgraph_id);
64 
65 }  // namespace resource
66 }  // namespace tflite
67 
68 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_RESOURCE_INITIALIZATION_STATUS_H_
69