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_CONCRETE_FUNCTION_H_ 17 #define TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_CONCRETE_FUNCTION_H_ 18 19 #include <memory> 20 #include <vector> 21 22 #include "absl/types/span.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/function_metadata.h" 26 27 namespace tensorflow { 28 29 // ConcreteFunctions correspond to an instance of a tf.function with a known set 30 // of inputs (either through get_concrete_function) or an input_signature. 31 // ConcreteFunction attempts to preserve the user-facing semantics of the 32 // tf.function python API and can take a limited set of types as arguments 33 // (to be modeled in tensorflow::Value), not just Tensors. 34 // SavedModelAPI's ConcreteFunctions' lifetimes are bound to the SavedModel they 35 // are loaded from, since they retain pointers to the TensorHandles owned by the 36 // SavedModel, and the FunctionDef of the SavedModel. 37 // Note(bmzhao): This class is only TEMPORARILY virtual, as a way to unblock 38 // TFRT integration with TF Serving. Do not add more virtual implementations of 39 // this class. Eventually we want to remove this virtual base class indirection 40 // and have only a single implementation. 41 class ConcreteFunction { 42 public: 43 virtual ~ConcreteFunction() = default; 44 45 // This method returns the "Call" Op used to execute the function. 46 virtual Status MakeCallOp(absl::Span<AbstractTensorHandle* const> inputs, 47 ImmediateOpPtr* out) const = 0; 48 49 virtual const FunctionMetadata& GetFunctionMetadata() const = 0; 50 }; 51 52 } // namespace tensorflow 53 54 #endif // TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_CONCRETE_FUNCTION_H_ 55