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 #include "tensorflow/c/experimental/gradients/tape/tape_context.h"
16
17 #include "tensorflow/c/eager/abstract_context.h"
18 #include "tensorflow/c/experimental/gradients/tape/tape_operation.h"
19
20 namespace tensorflow {
21 namespace gradients {
TapeContext(AbstractContext * c,Tape * tape,const GradientRegistry & registry)22 TapeContext::TapeContext(AbstractContext* c, Tape* tape,
23 const GradientRegistry& registry)
24 : AbstractContext(kTape), parent_ctx_(c), tape_(tape), registry_(registry) {
25 // TODO(srbs): Make AbstractContext ref counted.
26 // parent_ctx_->Ref();
27 }
Release()28 void TapeContext::Release() {
29 // TODO(srbs): Change to Unref()
30 delete this;
31 }
~TapeContext()32 TapeContext::~TapeContext() {
33 // TODO(srbs): Make AbstractContext ref counted.
34 // parent_ctx_->Unref();
35 }
CreateOperation()36 TapeOperation* TapeContext::CreateOperation() {
37 return new TapeOperation(parent_ctx_->CreateOperation(), tape_, registry_);
38 }
RegisterFunction(AbstractFunction * f)39 Status TapeContext::RegisterFunction(AbstractFunction* f) {
40 return parent_ctx_->RegisterFunction(f);
41 }
RemoveFunction(const string & func)42 Status TapeContext::RemoveFunction(const string& func) {
43 return parent_ctx_->RemoveFunction(func);
44 }
45
46 } // namespace gradients
47 } // namespace tensorflow
48