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_PUBLIC_CONCRETE_FUNCTION_H_ 17 #define TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_PUBLIC_CONCRETE_FUNCTION_H_ 18 19 #include "tensorflow/c/c_api_macros.h" 20 #include "tensorflow/c/eager/c_api.h" 21 #include "tensorflow/c/experimental/saved_model/public/function_metadata.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif // __cplusplus 26 27 // An opaque type that corresponds to a Function loaded from a SavedModel. 28 // TODO(bmzhao): Work together w/srbs@ to make sure this composes w/the 29 // C++ Unified Eager/Graph API's AbstractFunction 30 typedef struct TF_ConcreteFunction TF_ConcreteFunction; 31 32 // Returns FunctionMetadata associated with `func`. Metadata's lifetime is 33 // bound to `func`, which is bound to the TF_SavedModel it was loaded from. 34 TF_CAPI_EXPORT extern TF_FunctionMetadata* TF_ConcreteFunctionGetMetadata( 35 TF_ConcreteFunction* func); 36 37 // Returns a TFE_Op suitable for executing this function. Caller must provide 38 // all function inputs in `inputs`, and must not add any additional inputs on 39 // the returned op. (i.e. don't call TFE_OpAddInput or TFE_OpAddInputList). 40 // The caller is responsible for deleting the returned TFE_Op. If op 41 // construction fails, `status` will be non-OK and the returned pointer will be 42 // null. 43 // TODO(bmzhao): Remove this function in a subsequent change; Design + implement 44 // a Function Execution interface for ConcreteFunction that accepts a tagged 45 // union of types (tensorflow::Value). This effectively requires moving much of 46 // the implementation of function.py/def_function.py to C++, and exposing a 47 // high-level API here. A strawman for what this interface could look like: 48 // TF_Value* TF_ExecuteFunction(TFE_Context*, TF_ConcreteFunction*, TF_Value* 49 // inputs, int num_inputs, TF_Status* status); 50 TF_CAPI_EXPORT extern TFE_Op* TF_ConcreteFunctionMakeCallOp( 51 TF_ConcreteFunction* func, TFE_TensorHandle** inputs, int num_inputs, 52 TF_Status* status); 53 54 #ifdef __cplusplus 55 } // end extern "C" 56 #endif // __cplusplus 57 58 #endif // TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_PUBLIC_CONCRETE_FUNCTION_H_ 59