xref: /aosp_15_r20/external/tensorflow/tensorflow/core/kernels/batching_util/input_split_metadata.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 
16 #ifndef TENSORFLOW_CORE_KERNELS_BATCHING_UTIL_INPUT_SPLIT_METADATA_H_
17 #define TENSORFLOW_CORE_KERNELS_BATCHING_UTIL_INPUT_SPLIT_METADATA_H_
18 
19 #include <algorithm>
20 
21 #include "absl/container/fixed_array.h"
22 
23 namespace tensorflow {
24 namespace serving {
25 namespace internal {
26 // InputSplitMetadata represents the task sizes of an batch-task after it's
27 // tailored according to queue status (`open_batch_remaining_slot` and
28 // `batch_size_limit`).
29 //
30 // This is an internal helper class, and the implementation is shared
31 // shared across different instantiations of internal::Queue<TaskType>
32 // in input-split mode (QueueOptions.enable_large_batch_splitting is true).
33 class InputSplitMetadata {
34  public:
35   InputSplitMetadata(int input_task_size, int open_batch_remaining_slot,
36                      int batch_size_limit);
37 
38   // Returns underlying task sizes.
39   const absl::FixedArray<int>& task_sizes() const;
40 
41   // Serializes task split metadata into a string for debugging.
42   std::string DebugString() const;
43 
44  private:
45   absl::FixedArray<int> generate_task_sizes(int input_task_size,
46                                             int open_batch_remaining_slot,
47                                             int batch_size_limit) const;
48 
49   const absl::FixedArray<int> task_sizes_;
50 };
51 }  // namespace internal
52 }  // namespace serving
53 }  // namespace tensorflow
54 
55 #endif  // TENSORFLOW_CORE_KERNELS_BATCHING_UTIL_INPUT_SPLIT_METADATA_H_
56