xref: /aosp_15_r20/external/tensorflow/tensorflow/core/runtime_fallback/runtime/runtime_fallback_kernels.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 // This file declares kernels for running TFRT ops/kernels via TF runtime
17 // fallback.
18 
19 #ifndef TENSORFLOW_CORE_RUNTIME_FALLBACK_RUNTIME_RUNTIME_FALLBACK_KERNELS_H_
20 #define TENSORFLOW_CORE_RUNTIME_FALLBACK_RUNTIME_RUNTIME_FALLBACK_KERNELS_H_
21 
22 #include <memory>
23 
24 #include "llvm/Support/Error.h"
25 #include "tensorflow/core/platform/status.h"
26 #include "tensorflow/core/runtime_fallback/runtime/kernel_utils.h"
27 #include "tfrt/core_runtime/op_attrs.h"  // from @tf_runtime
28 #include "tfrt/host_context/async_value.h"  // from @tf_runtime
29 #include "tfrt/host_context/chain.h"  // from @tf_runtime
30 #include "tfrt/host_context/execution_context.h"  // from @tf_runtime
31 #include "tfrt/host_context/shared_context.h"  // from @tf_runtime
32 #include "tfrt/tensor/tensor.h"  // from @tf_runtime
33 
34 namespace tensorflow {
35 namespace tfd {
36 
37 // Injecting TF resources to TFRT GPU resource maps for tfrt::GpuOpHandler to
38 // use.s
39 Status InjectTfGpuResources();
40 
41 // Create an EagerOperation to run the op, taking tensorflow::TensorHandle and
42 // returning tensorflow::AbstractTensorHandle*.
43 Status CallEagerExecute(const tfrt::ExecutionContext& exec_ctx,
44                         EagerContext* eager_ctx, const char* op_name,
45                         const char* device_name,
46                         llvm::ArrayRef<TensorHandle*> input_tensor_handles,
47                         const tfrt::OpAttrsRef& attrs,
48                         llvm::MutableArrayRef<tensorflow::AbstractTensorHandle*>
49                             result_tensor_handles);
50 
51 // Take and return RuntimeFallbackTensors.
52 tfrt::AsyncValueRef<tfrt::Chain> RuntimeFallbackExecute(
53     const tfrt::ExecutionContext& exec_ctx, const char* op_name,
54     const char* device_name, tfrt::ArrayRef<tfrt::Tensor*> arguments,
55     const tfrt::OpAttrsRef& attrs,
56     tfrt::MutableArrayRef<tfrt::RCReference<tfrt::AsyncValue>> results);
57 
58 }  // namespace tfd
59 }  // namespace tensorflow
60 
61 #endif  // TENSORFLOW_CORE_RUNTIME_FALLBACK_RUNTIME_RUNTIME_FALLBACK_KERNELS_H_
62