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 
16 #ifndef TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_TENSORHANDLE_CONVERTIBLE_H_
17 #define TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_TENSORHANDLE_CONVERTIBLE_H_
18 
19 #include "tensorflow/c/eager/immediate_execution_tensor_handle.h"
20 
21 namespace tensorflow {
22 
23 // A common interface for objects that can be converted to a TensorHandle.
24 // Examples of objects that implement this include Variables, Constants, Assets,
25 // etc. This is used to convert captured objects into a ConcreteFunction's
26 // captured TensorHandles:
27 // https://github.com/tensorflow/tensorflow/blob/676a68963ea4b64fe479b9cede06aa8f5b290ab8/tensorflow/python/saved_model/load.py#L229-L240
28 class TensorHandleConvertible {
29  public:
TensorHandleConvertible(ImmediateTensorHandlePtr handle)30   explicit TensorHandleConvertible(ImmediateTensorHandlePtr handle)
31       : handle_(std::move(handle)) {}
32 
handle()33   ImmediateExecutionTensorHandle* handle() { return handle_.get(); }
34 
35   // TensorHandleConvertible is movable, but not copyable.
36   TensorHandleConvertible(TensorHandleConvertible&& other) = default;
37   TensorHandleConvertible& operator=(TensorHandleConvertible&& other) = default;
38 
39   virtual ~TensorHandleConvertible() = default;
40 
41  protected:
42   TensorHandleConvertible(const TensorHandleConvertible&) = delete;
43   TensorHandleConvertible& operator=(const TensorHandleConvertible&) = delete;
44   ImmediateTensorHandlePtr handle_;
45 };
46 
47 }  // namespace tensorflow
48 
49 #endif  // TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_TENSORHANDLE_CONVERTIBLE_H_
50