• 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_CORE_DATA_ROOT_DATASET_H_
16 #define TENSORFLOW_CORE_DATA_ROOT_DATASET_H_
17 
18 #include "tensorflow/core/framework/dataset.h"
19 #include "tensorflow/core/framework/model.h"
20 #include "tensorflow/core/framework/model.pb.h"
21 
22 namespace tensorflow {
23 namespace data {
24 
25 // Dataset transformation responsible for internal tf.data logic such as
26 // autotuning, applying threading configuration.
27 class RootDataset : public DatasetBase {
28  public:
29   struct Params {
30     bool autotune = true;
31     model::AutotuneAlgorithm autotune_algorithm;
32     int64 autotune_cpu_budget = 0;
33     int64 autotune_ram_budget = 0;
34     int64 max_intra_op_parallelism = 1;
35     int64 private_threadpool_size = 0;
36   };
37 
38   static Status FromOptions(DatasetBase* input, DatasetBase** output);
39 
40   ~RootDataset() override;
41 
42   const DataTypeVector& output_dtypes() const override;
43   const std::vector<PartialTensorShape>& output_shapes() const override;
44 
45   int64 Cardinality() const override;
46   Status CheckExternalState() const override;
47   string DebugString() const override;
48   Status InputDatasets(std::vector<const DatasetBase*>* inputs) const override;
49   std::unique_ptr<IteratorBase> MakeIteratorInternal(
50       const string& prefix) const override;
51 
52  protected:
53   Status AsGraphDefInternal(SerializationContext* ctx,
54                             DatasetGraphDefBuilder* b,
55                             Node** output) const override;
56 
57  private:
58   class Iterator;
59 
60   RootDataset(const DatasetBase* input, Params params);
61 
62   const DatasetBase* input_;
63   const Params params_;
64   TraceMeMetadata traceme_metadata_;
65 };
66 
67 // Finalizes the `input` dataset, which is expected to be called before the
68 // dataset is about to be iterated. This can for instance apply static graph
69 // optimizations or inject internal tf.data transformations responsible for
70 // autotuning or threading configuration.
71 Status FinalizeDataset(OpKernelContext* ctx, DatasetBase* input,
72                        DatasetBase** output);
73 
74 }  // namespace data
75 }  // namespace tensorflow
76 
77 #endif  // TENSORFLOW_CORE_DATA_ROOT_DATASET_H_
78