1 /* Copyright 2021 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 #ifndef TENSORFLOW_CC_EXPERIMENTAL_CORE_FUNCTION_H_ 16 #define TENSORFLOW_CC_EXPERIMENTAL_CORE_FUNCTION_H_ 17 18 #include <vector> 19 20 #include "tensorflow/c/eager/abstract_context.h" 21 #include "tensorflow/c/eager/abstract_function.h" 22 #include "tensorflow/c/eager/abstract_tensor_handle.h" 23 #include "tensorflow/cc/experimental/libtf/object.h" 24 #include "tensorflow/core/platform/statusor.h" 25 26 namespace tf { 27 namespace libtf { 28 29 class Function { 30 public: 31 tensorflow::Status RegisterTrace(tensorflow::AbstractFunctionPtr, 32 TaggedValue input_signature, 33 TaggedValue output_signature); 34 35 // Executes this function under the execution context. 36 // 37 // Raises an error is no matching signature is found for TaggedValue. 38 tensorflow::StatusOr<TaggedValue> Execute(tensorflow::AbstractContext*, 39 TaggedValue) const; 40 41 private: 42 struct ConcreteFunction { 43 tensorflow::AbstractFunctionPtr trace; 44 TaggedValue input_signature; 45 TaggedValue output_signature; 46 }; 47 tensorflow::StatusOr<ConcreteFunction> GetConcreteFunction(TaggedValue) const; 48 std::vector<ConcreteFunction> concrete_fns_; 49 }; 50 51 } // namespace libtf 52 } // namespace tf 53 54 #endif // TENSORFLOW_CC_EXPERIMENTAL_CORE_FUNCTION_H_ 55