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_CONTEXT_H_ 16 #define TENSORFLOW_C_EXPERIMENTAL_GRADIENTS_TAPE_TAPE_CONTEXT_H_ 17 18 #include "tensorflow/c/eager/abstract_context.h" 19 #include "tensorflow/c/experimental/gradients/tape/tape_operation.h" 20 21 namespace tensorflow { 22 namespace gradients { 23 class TapeContext : public AbstractContext { 24 public: 25 explicit TapeContext(AbstractContext*, Tape*, const GradientRegistry&); 26 void Release() override; 27 TapeOperation* CreateOperation() override; 28 Status RegisterFunction(AbstractFunction*) override; 29 Status RemoveFunction(const string& func) override; 30 // For LLVM style RTTI. classof(const AbstractContext * ptr)31 static bool classof(const AbstractContext* ptr) { 32 return ptr->getKind() == kTape; 33 } 34 ~TapeContext() override; 35 36 private: 37 AbstractContext* parent_ctx_; // Not owned. 38 Tape* tape_; 39 const GradientRegistry& registry_; 40 }; 41 } // namespace gradients 42 } // namespace tensorflow 43 44 #endif // TENSORFLOW_C_EXPERIMENTAL_GRADIENTS_TAPE_TAPE_CONTEXT_H_ 45