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/tuple_thunk.h" 17 18 #include "tensorflow/compiler/xla/util.h" 19 20 namespace se = ::perftools::gputools; 21 22 namespace xla { 23 namespace gpu { 24 25 tensorflow::Status TupleThunk::ExecuteOnStream( 26 const BufferAllocations& buffer_allocations, se::Stream* stream) { 27 std::vector<void*> tuple_element_buffer_addresses; 28 for (BufferAllocation::Slice tuple_element_buffer : tuple_element_buffers_) { 29 tuple_element_buffer_addresses.push_back( 30 buffer_allocations.GetDeviceAddress(tuple_element_buffer).opaque()); 31 } 32 se::DeviceMemory<void*> dest_buffer_address( 33 buffer_allocations.GetDeviceAddress(dest_buffer_)); 34 35 auto host_size = tuple_element_buffer_addresses.size() * sizeof(void*); 36 if (!stream 37 ->ThenMemcpy(&dest_buffer_address, 38 tuple_element_buffer_addresses.data(), host_size) 39 .ok()) { 40 return InternalError( 41 "Unable to launch MemcpyH2D from %p to %p with size %lu", 42 tuple_element_buffer_addresses.data(), dest_buffer_address.opaque(), 43 sizeof(void*) * tuple_element_buffer_addresses.size()); 44 } 45 return tensorflow::Status::OK(); 46 } 47 48 } // namespace gpu 49 } // namespace xla 50