@@ -130,22 +130,32 @@ class Subgraph {
130130  //  This variant assumes an external buffer has been allocated of size
131131  //  bytes. The lifetime of buffer must be ensured to be greater or equal
132132  //  to Interpreter. `quantization` ownership is passed to the subgraph.
133+   //  `buffer_identifier`: An optional value to identify the buffer. If set to
134+   //  a value other than kTfLiteNoBufferIdentifier, this tensor is considered a
135+   //  constant tensor shared across multiple subgraphs / interpreters.
136+   //  `external_buffer_id`: An optional value to identify the external buffer. If
137+   //  set to a value other than kTfLiteNoBufferIdentifier, this tensor is
138+   //  considered a tensor using an external buffer shared across multiple
139+   //  subgraphs / interpreters.
133140  inline  TfLiteStatus SetTensorParametersReadOnly (
134141      int  tensor_index, TfLiteType type, const  char * name,
135142      const  std::vector<int >& dims, TfLiteQuantization quantization,
136143      const  char * buffer, size_t  bytes, const  Allocation* allocation = nullptr ,
137144      TfLiteSparsity* sparsity = nullptr ,
138-       size_t  buffer_identifier = kTfLiteNoBufferIdentifier ) {
145+       size_t  buffer_identifier = kTfLiteNoBufferIdentifier ,
146+       size_t  external_buffer_id = kTfLiteNoBufferIdentifier ) {
139147    return  SetTensorParametersReadOnly (tensor_index, type, name, dims.size (),
140148                                       dims.data (), quantization, buffer, bytes,
141-                                        allocation, sparsity, buffer_identifier);
149+                                        allocation, sparsity, buffer_identifier,
150+                                        external_buffer_id);
142151  }
143152  TfLiteStatus SetTensorParametersReadOnly (
144153      int  tensor_index, TfLiteType type, const  char * name, size_t  ndims,
145154      const  int * dims, TfLiteQuantization quantization, const  char * buffer,
146155      size_t  bytes, const  Allocation* allocation = nullptr ,
147156      TfLiteSparsity* sparsity = nullptr ,
148-       size_t  buffer_identifier = kTfLiteNoBufferIdentifier );
157+       size_t  buffer_identifier = kTfLiteNoBufferIdentifier ,
158+       size_t  external_buffer_id = kTfLiteNoBufferIdentifier );
149159
150160  //  Set description of inputs/outputs/data/fptrs for node `node_index`.
151161  //  This variant assumes an external buffer has been allocated of size
@@ -611,6 +621,11 @@ class Subgraph {
611621    return  tensor_buffer_identifiers_;
612622  }
613623
624+   const  std::unordered_map<size_t , size_t >& GetExternalTensorBufferIdentifiers ()
625+       const  {
626+     return  tensor_external_buffer_ids_;
627+   }
628+ 
614629  //  Replaces the node for the given execution index with the subgraph.
615630  // 
616631  //  - The node and subgraph tensor counts must match.
@@ -1220,6 +1235,10 @@ class Subgraph {
12201235  //  Maps tensor constant buffers used in the subgraph to a model-wide
12211236  //  identifiers.
12221237  std::unordered_map<size_t , size_t > tensor_buffer_identifiers_;
1238+ 
1239+   //  Maps tensor external buffer ids used in the subgraph to a model-wide
1240+   //  identifiers.
1241+   std::unordered_map<size_t , size_t > tensor_external_buffer_ids_;
12231242};
12241243
12251244}  //  namespace tflite
0 commit comments