Home | History | Annotate | Download | only in gpu
      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 "tensorflow/compiler/xla/service/buffer_assignment.h"
     22 #include "tensorflow/compiler/xla/service/gpu/gpu_executable.h"
     23 #include "tensorflow/compiler/xla/service/gpu/thunk.h"
     24 #include "tensorflow/core/lib/core/status.h"
     25 #include "tensorflow/core/lib/gtl/array_slice.h"
     26 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
     27 
     28 namespace xla {
     29 namespace gpu {
     30 
     31 // A thunk that copies the addresses of tuple elements to the buffer of the
     32 // tuple. This avoids emitting kernels that may suffer from the parameter space
     33 // issue (b/31336476).
     34 class TupleThunk : public Thunk {
     35  public:
     36   TupleThunk(tensorflow::gtl::ArraySlice<BufferAllocation::Slice>
     37                  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   tensorflow::Status ExecuteOnStream(
     49       const BufferAllocations& buffer_allocations,
     50       perftools::gputools::Stream* stream) 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