• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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_C_EXPERIMENTAL_GRADIENTS_TAPE_TAPE_OPERATION_H_
16 #define TENSORFLOW_C_EXPERIMENTAL_GRADIENTS_TAPE_TAPE_OPERATION_H_
17 
18 #include "tensorflow/c/eager/abstract_operation.h"
19 #include "tensorflow/c/eager/gradients.h"
20 
21 namespace tensorflow {
22 namespace gradients {
23 class TapeOperation : public AbstractOperation {
24  public:
25   explicit TapeOperation(AbstractOperation*, Tape*, const GradientRegistry&);
26   void Release() override;
27   Status Reset(const char* op, const char* raw_device_name) override;
28   const string& Name() const override;
29   const string& DeviceName() const override;
30   Status SetDeviceName(const char* name) override;
31   Status AddInput(AbstractTensorHandle* input) override;
32   Status AddInputList(absl::Span<AbstractTensorHandle* const> inputs) override;
33   Status Execute(absl::Span<AbstractTensorHandle*> retvals,
34                  int* num_retvals) override;
35   Status SetAttrString(const char* attr_name, const char* data,
36                        size_t length) override;
37   Status SetAttrInt(const char* attr_name, int64_t value) override;
38   Status SetAttrFloat(const char* attr_name, float value) override;
39   Status SetAttrBool(const char* attr_name, bool value) override;
40   Status SetAttrType(const char* attr_name, DataType value) override;
41   Status SetAttrShape(const char* attr_name, const int64_t* dims,
42                       const int num_dims) override;
43   Status SetAttrFunction(const char* attr_name,
44                          const AbstractOperation* value) override;
45   Status SetAttrFunctionName(const char* attr_name, const char* value,
46                              size_t length) override;
47   Status SetAttrTensor(const char* attr_name,
48                        AbstractTensorInterface* tensor) override;
49   Status SetAttrStringList(const char* attr_name, const void* const* values,
50                            const size_t* lengths, int num_values) override;
51   Status SetAttrFloatList(const char* attr_name, const float* values,
52                           int num_values) override;
53   Status SetAttrIntList(const char* attr_name, const int64_t* values,
54                         int num_values) override;
55   Status SetAttrTypeList(const char* attr_name, const DataType* values,
56                          int num_values) override;
57   Status SetAttrBoolList(const char* attr_name, const unsigned char* values,
58                          int num_values) override;
59   Status SetAttrShapeList(const char* attr_name, const int64_t** dims,
60                           const int* num_dims, int num_values) override;
61   Status SetAttrFunctionList(
62       const char* attr_name,
63       absl::Span<const AbstractOperation*> values) override;
64   AbstractOperation* GetBackingOperation();
65   // For LLVM style RTTI.
classof(const AbstractOperation * ptr)66   static bool classof(const AbstractOperation* ptr) {
67     return ptr->getKind() == kTape;
68   }
69   ~TapeOperation() override;
70 
71  private:
72   AbstractOperation* parent_op_;
73   ForwardOperation forward_op_;
74   Tape* tape_;
75   const GradientRegistry& registry_;
76 };
77 
78 }  // namespace gradients
79 }  // namespace tensorflow
80 #endif  // TENSORFLOW_C_EXPERIMENTAL_GRADIENTS_TAPE_TAPE_OPERATION_H_
81