xref: /aosp_15_r20/external/tensorflow/tensorflow/core/runtime_fallback/util/gpu/gpu_utils.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 gpu related utility functions.
17 
18 #ifndef TENSORFLOW_CORE_RUNTIME_FALLBACK_RUNTIME_GPU_GPU_UTILS_H_
19 #define TENSORFLOW_CORE_RUNTIME_FALLBACK_RUNTIME_GPU_GPU_UTILS_H_
20 
21 #include "tensorflow/core/common_runtime/eager/tensor_handle.h"
22 #include "tensorflow/core/common_runtime/gpu/gpu_device.h"
23 #include "tfrt/gpu/device/gpu_config.h"  // from @tf_runtime
24 #include "tfrt/gpu/gpu_types.h"  // from @tf_runtime
25 #include "tfrt/tensor/tensor.h"  // from @tf_runtime
26 
27 namespace tensorflow {
28 namespace tfd {
29 
30 // Lookup GPU platform (CUDA vs ROCm) from a given tensorflow::TensorHandle.
31 tfrt::gpu::wrapper::Platform GetTfrtGpuPlatform(tensorflow::TensorHandle* th);
32 
33 tfrt::gpu::wrapper::Platform GetTfrtGpuPlatform(
34     tensorflow::BaseGPUDevice* device);
35 
36 // Moves one ref on GpuBuffer to tensorflow::Tensor.
37 tfrt::Expected<tensorflow::Tensor> MoveGpuBufferToTFTensor(
38     tfrt::AsyncValueRef<tfrt::gpu::GpuBuffer> gpu_buffer, tfrt::DType dtype,
39     tfrt::TensorShape shape);
40 
41 }  // namespace tfd
42 }  // namespace tensorflow
43 
44 #endif  // TENSORFLOW_CORE_RUNTIME_FALLBACK_RUNTIME_GPU_GPU_UTILS_H_
45