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 #include "tensorflow/c/experimental/saved_model/core/revived_types/tf_concrete_function.h"
17 
18 #include <memory>
19 #include <string>
20 
21 #include "absl/types/span.h"
22 #include "tensorflow/c/eager/abstract_tensor_handle.h"
23 #include "tensorflow/c/eager/immediate_execution_operation.h"
24 #include "tensorflow/c/eager/immediate_execution_tensor_handle.h"
25 #include "tensorflow/c/experimental/saved_model/core/revived_types/flat_tensor_function.h"
26 #include "tensorflow/core/common_runtime/eager/context.h"
27 #include "tensorflow/core/framework/function.pb.h"
28 #include "tensorflow/core/platform/errors.h"
29 #include "tensorflow/core/platform/logging.h"
30 #include "tensorflow/core/platform/status.h"
31 #include "tensorflow/core/protobuf/saved_object_graph.pb.h"
32 #include "tensorflow/core/protobuf/struct.pb.h"
33 
34 namespace tensorflow {
35 
TFConcreteFunction(std::unique_ptr<FlatTensorFunction> func,FunctionMetadata metadata)36 TFConcreteFunction::TFConcreteFunction(std::unique_ptr<FlatTensorFunction> func,
37                                        FunctionMetadata metadata)
38     : func_(std::move(func)), metadata_(std::move(metadata)) {}
39 
Create(const FunctionDef * function_def,std::vector<ImmediateExecutionTensorHandle * > captures,FunctionMetadata metadata,ImmediateExecutionContext * ctx,std::unique_ptr<TFConcreteFunction> * out)40 Status TFConcreteFunction::Create(
41     const FunctionDef* function_def,
42     std::vector<ImmediateExecutionTensorHandle*> captures,
43     FunctionMetadata metadata, ImmediateExecutionContext* ctx,
44     std::unique_ptr<TFConcreteFunction>* out) {
45   std::unique_ptr<FlatTensorFunction> func;
46   TF_RETURN_IF_ERROR(FlatTensorFunction::Create(
47       function_def, std::move(captures), ctx, &func));
48 
49   out->reset(new TFConcreteFunction(std::move(func), std::move(metadata)));
50   return Status();
51 }
52 
GetFunctionMetadata() const53 const FunctionMetadata& TFConcreteFunction::GetFunctionMetadata() const {
54   return metadata_;
55 }
56 
MakeCallOp(absl::Span<AbstractTensorHandle * const> inputs,ImmediateOpPtr * out) const57 Status TFConcreteFunction::MakeCallOp(
58     absl::Span<AbstractTensorHandle* const> inputs, ImmediateOpPtr* out) const {
59   return func_->MakeCallOp(inputs, out);
60 }
61 
62 }  // namespace tensorflow
63