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_TUPLE_THUNK_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_TUPLE_THUNK_H_
18 
19 #include <vector>
20 
21 #include "absl/types/span.h"
22 #include "tensorflow/compiler/xla/service/buffer_assignment.h"
23 #include "tensorflow/compiler/xla/service/gpu/gpu_executable.h"
24 #include "tensorflow/compiler/xla/service/gpu/hlo_execution_profiler.h"
25 #include "tensorflow/compiler/xla/service/gpu/thunk.h"
26 #include "tensorflow/core/lib/core/status.h"
27 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
28 
29 namespace xla {
30 namespace gpu {
31 
32 // A thunk that copies the addresses of tuple elements to the buffer of the
33 // tuple. This avoids emitting kernels that may suffer from the parameter space
34 // issue (b/31336476).
35 class TupleThunk : public Thunk {
36  public:
TupleThunk(absl::Span<const BufferAllocation::Slice> tuple_element_buffers,const BufferAllocation::Slice & dest_buffer,const HloInstruction * hlo_instruction)37   TupleThunk(absl::Span<const BufferAllocation::Slice> tuple_element_buffers,
38              const BufferAllocation::Slice& dest_buffer,
39              const HloInstruction* hlo_instruction)
40       : Thunk(Kind::kTuple, hlo_instruction),
41         tuple_element_buffers_(tuple_element_buffers.begin(),
42                                tuple_element_buffers.end()),
43         dest_buffer_(dest_buffer) {}
44 
45   TupleThunk(const TupleThunk&) = delete;
46   TupleThunk& operator=(const TupleThunk&) = delete;
47 
48   Status ExecuteOnStream(const BufferAllocations& buffer_allocations,
49                          se::Stream* stream,
50                          HloExecutionProfiler* profiler) override;
51 
52  private:
53   const std::vector<BufferAllocation::Slice> tuple_element_buffers_;
54   const BufferAllocation::Slice dest_buffer_;
55 };
56 
57 }  // namespace gpu
58 }  // namespace xla
59 
60 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_TUPLE_THUNK_H_
61