xref: /aosp_15_r20/external/tensorflow/tensorflow/core/kernels/data/generator_dataset_op.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2018 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_DATA_GENERATOR_DATASET_OP_H_
17 #define TENSORFLOW_CORE_KERNELS_DATA_GENERATOR_DATASET_OP_H_
18 
19 #include "tensorflow/core/data/captured_function.h"
20 #include "tensorflow/core/framework/dataset.h"
21 
22 namespace tensorflow {
23 namespace data {
24 
25 class GeneratorDatasetOp : public DatasetOpKernel {
26  public:
27   static constexpr const char* const kDatasetType = "Generator";
28   static constexpr const char* const kInitFuncOtherArgs =
29       "init_func_other_args";
30   static constexpr const char* const kNextFuncOtherArgs =
31       "next_func_other_args";
32   static constexpr const char* const kFinalizeFuncOtherArgs =
33       "finalize_func_other_args";
34   static constexpr const char* const kInitFunc = "init_func";
35   static constexpr const char* const kNextFunc = "next_func";
36   static constexpr const char* const kFinalizeFunc = "finalize_func";
37   static constexpr const char* const kTinitFuncArgs = "Tinit_func_args";
38   static constexpr const char* const kTnextFuncArgs = "Tnext_func_args";
39   static constexpr const char* const kTfinalizeFuncArgs = "Tfinalize_func_args";
40   static constexpr const char* const kOutputTypes = "output_types";
41   static constexpr const char* const kOutputShapes = "output_shapes";
42 
43   explicit GeneratorDatasetOp(OpKernelConstruction* ctx);
44 
45   void MakeDataset(OpKernelContext* ctx, DatasetBase** output) override;
46 
47  private:
48   class Dataset;
49 
50   DataTypeVector output_types_;
51   std::vector<PartialTensorShape> output_shapes_;
52   std::shared_ptr<FunctionMetadata> init_func_metadata_ = nullptr;
53   std::shared_ptr<FunctionMetadata> next_func_metadata_ = nullptr;
54   std::shared_ptr<FunctionMetadata> finalize_func_metadata_ = nullptr;
55 };
56 
57 }  // namespace data
58 }  // namespace tensorflow
59 #endif  // TENSORFLOW_CORE_KERNELS_DATA_GENERATOR_DATASET_OP_H_
60