1 /* Copyright 2022 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 /// \file 16 /// Functions for serializiation/deserialization of control dependency 17 /// information to/from model metadata. 18 /// 19 20 #ifndef TENSORFLOW_LITE_EXPERIMENTAL_REMAT_METADATA_UTIL_H_ 21 #define TENSORFLOW_LITE_EXPERIMENTAL_REMAT_METADATA_UTIL_H_ 22 23 #include <string> 24 #include <vector> 25 26 #include "tensorflow/lite/graph_info.h" 27 28 namespace tflite { 29 30 /// Control dependencies for the model is the collection of control dependencies 31 /// for its subgraphs. 32 using ModelControlDependencies = std::vector<ControlEdges>; 33 34 /// Serializes `in` into the returned string. The result is parseable with 35 /// ParseModelControlDependencies. 36 std::string SerializeModelControlDependencies( 37 const ModelControlDependencies& in); 38 39 /// Deserializes `*out` from a character buffer of size `size` at `data`. 40 /// Returns true iff successful. `*out` needn't be empty before invocation. 41 /// When returning false, `*out`'s state is undefined. 42 bool ParseModelControlDependencies(const char* data, size_t size, 43 ModelControlDependencies* out); 44 45 /// The key under which to store the serialized control dependencies in the 46 /// model's metadata. 47 constexpr char kModelControlDependenciesMetadataKey[] = 48 "model_control_dependencies"; 49 50 /// To allow future changes to the format, serialized control dependency data 51 /// will contain a version; this constant is the version that will be used for 52 /// serialization. For deserialization, past versions should remain parseable. 53 constexpr uint32_t kModelControlDependenciesMetadataVersion = 1; 54 55 } // namespace tflite 56 57 #endif // TENSORFLOW_LITE_EXPERIMENTAL_REMAT_METADATA_UTIL_H_ 58