• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "tensorflow/compiler/xla/service/gpu/copy_thunk.h"
17 
18 #include "tensorflow/compiler/xla/service/gpu/hlo_execution_profiler.h"
19 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
20 
21 namespace xla {
22 namespace gpu {
23 
HostToDeviceCopyThunk(ThunkInfo thunk_info,const void * source_address,const BufferAllocation::Slice & destination_buffer,uint64 mem_size)24 HostToDeviceCopyThunk::HostToDeviceCopyThunk(
25     ThunkInfo thunk_info, const void* source_address,
26     const BufferAllocation::Slice& destination_buffer, uint64 mem_size)
27     : Thunk(Kind::kCopy, thunk_info),
28       source_address_(source_address),
29       destination_buffer_(destination_buffer),
30       mem_size_(mem_size) {}
31 
ExecuteOnStream(const ExecuteParams & params)32 Status HostToDeviceCopyThunk::ExecuteOnStream(const ExecuteParams& params) {
33   se::DeviceMemoryBase destination_data =
34       params.buffer_allocations->GetDeviceAddress(destination_buffer_);
35   auto op_profiler =
36       params.profiler->MakeScopedInstructionProfiler(profile_index());
37   params.stream->ThenMemcpy(&destination_data, source_address_, mem_size_);
38   return Status::OK();
39 }
40 
DeviceToDeviceCopyThunk(ThunkInfo thunk_info,const BufferAllocation::Slice & source_buffer,const BufferAllocation::Slice & destination_buffer,uint64 mem_size)41 DeviceToDeviceCopyThunk::DeviceToDeviceCopyThunk(
42     ThunkInfo thunk_info, const BufferAllocation::Slice& source_buffer,
43     const BufferAllocation::Slice& destination_buffer, uint64 mem_size)
44     : Thunk(Kind::kCopy, thunk_info),
45       source_buffer_(source_buffer),
46       destination_buffer_(destination_buffer),
47       mem_size_(mem_size) {}
48 
ExecuteOnStream(const ExecuteParams & params)49 Status DeviceToDeviceCopyThunk::ExecuteOnStream(const ExecuteParams& params) {
50   se::DeviceMemoryBase destination_data =
51       params.buffer_allocations->GetDeviceAddress(destination_buffer_);
52   se::DeviceMemoryBase source_data =
53       params.buffer_allocations->GetDeviceAddress(source_buffer_);
54   auto op_profiler =
55       params.profiler->MakeScopedInstructionProfiler(profile_index());
56   params.stream->ThenMemcpy(&destination_data, source_data, mem_size_);
57   return Status::OK();
58 }
59 }  // namespace gpu
60 }  // namespace xla
61