xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/service/gpu/copy_thunk.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2017 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_COMPILER_XLA_SERVICE_GPU_COPY_THUNK_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_COPY_THUNK_H_
18 
19 #include "tensorflow/compiler/xla/service/buffer_assignment.h"
20 #include "tensorflow/compiler/xla/service/gpu/buffer_allocations.h"
21 #include "tensorflow/compiler/xla/service/gpu/thunk.h"
22 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
23 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
24 
25 namespace xla {
26 namespace gpu {
27 
28 // A thunk that copies data from a device buffer to another device buffer.
29 class DeviceToDeviceCopyThunk : public Thunk {
30  public:
31   // Constructs a CopyThunk that copies host data from `source_buffer` to the
32   // device buffer `destination_buffer`. `mem_size` is the size of the data in
33   // bytes.
34   DeviceToDeviceCopyThunk(ThunkInfo thunk_info,
35                           const BufferAllocation::Slice& source_buffer,
36                           const BufferAllocation::Slice& destination_buffer,
37                           uint64_t mem_size);
38 
39   DeviceToDeviceCopyThunk(const DeviceToDeviceCopyThunk&) = delete;
40   DeviceToDeviceCopyThunk& operator=(const DeviceToDeviceCopyThunk&) = delete;
41 
42   Status ExecuteOnStream(const ExecuteParams& params) override;
43 
source()44   const BufferAllocation::Slice& source() const { return source_buffer_; }
destination()45   const BufferAllocation::Slice& destination() const {
46     return destination_buffer_;
47   }
size_bytes()48   uint64_t size_bytes() const { return mem_size_; }
49 
50  private:
51   const BufferAllocation::Slice source_buffer_;
52   const BufferAllocation::Slice destination_buffer_;
53   const uint64_t mem_size_;
54 };
55 
56 }  // namespace gpu
57 }  // namespace xla
58 
59 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_COPY_THUNK_H_
60