xref: /aosp_15_r20/external/tensorflow/tensorflow/core/runtime_fallback/kernel/kernel_fallback_execute.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 
16 // Provides a way to execute a TensorFlow kernel using TFRT kernel fallback.
17 
18 #ifndef TENSORFLOW_CORE_RUNTIME_FALLBACK_KERNEL_KERNEL_FALLBACK_EXECUTE_H_
19 #define TENSORFLOW_CORE_RUNTIME_FALLBACK_KERNEL_KERNEL_FALLBACK_EXECUTE_H_
20 
21 #include "llvm/ADT/ArrayRef.h"
22 #include "tfrt/core_runtime/op_attrs.h"  // from @tf_runtime
23 #include "tfrt/host_context/async_value.h"  // from @tf_runtime
24 #include "tfrt/host_context/execution_context.h"  // from @tf_runtime
25 #include "tfrt/support/forward_decls.h"  // from @tf_runtime
26 #include "tfrt/support/ref_count.h"  // from @tf_runtime
27 
28 namespace tfrt {
29 class AsyncKernelFrame;
30 }  // namespace tfrt
31 
32 namespace tensorflow {
33 namespace tfd {
34 
35 enum KernelFallbackOutputType {
36   TENSOR = 0,                 // Output type is tensorflow::Tensor
37   KERNEL_FALLBACK_TENSOR = 1  // Output type is KernelFallbackTensor
38 };
39 
40 // Runs kernel asynchronously.
41 // `frame` must contain tensorflow::Tensor inputs and pre-allocated
42 // tensorflow::Tensor or tfrt::KernelFallbackTensor outputs.
43 bool KernelFallbackExecute(
44     const tfrt::ExecutionContext& exec_ctx, tfrt::string_view op_name,
45     llvm::ArrayRef<tfrt::AsyncValue*> arguments,
46     llvm::MutableArrayRef<tfrt::RCReference<tfrt::AsyncValue>> results,
47     const tfrt::OpAttrsRef& attrs, KernelFallbackOutputType output_type);
48 }  // namespace tfd
49 }  // namespace tensorflow
50 
51 #endif  // TENSORFLOW_CORE_RUNTIME_FALLBACK_KERNEL_KERNEL_FALLBACK_EXECUTE_H_
52