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_CONVOLUTION_THUNK_H_
     17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CONVOLUTION_THUNK_H_
     18 
     19 #include "absl/types/optional.h"
     20 #include "tensorflow/compiler/xla/service/buffer_assignment.h"
     21 #include "tensorflow/compiler/xla/service/gpu/buffer_allocations.h"
     22 #include "tensorflow/compiler/xla/service/gpu/cudnn_conv_runner.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/compiler/xla/service/hlo_instruction.h"
     27 #include "tensorflow/compiler/xla/service/hlo_instructions.h"
     28 #include "tensorflow/compiler/xla/types.h"
     29 #include "tensorflow/compiler/xla/xla_data.pb.h"
     30 #include "tensorflow/core/lib/core/status.h"
     31 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
     32 
     33 namespace xla {
     34 namespace gpu {
     35 
     36 // This class stores everything that StreamExecutor needs to launch a DNN
     37 // convolution. It is generated by IrEmitter.
     38 //
     39 // This is thread-compatible.
     40 class ConvolutionThunk : public Thunk {
     41  public:
     42   // Constructs a thunk for launching a DNN convolution.  When run, it will
     43   // write a tuple (result, scratch_memory) into `tuple_result_buffer`.
     44   //
     45   // operand_slices should be in the same order as cudnn_call->operands().
     46   ConvolutionThunk(const HloCustomCallInstruction* cudnn_call,
     47                    std::vector<BufferAllocation::Slice> operand_slices,
     48                    BufferAllocation::Slice result_slice,
     49                    BufferAllocation::Slice scratch_slice,
     50                    BufferAllocation::Slice tuple_result_slice);
     51 
     52   ConvolutionThunk(const ConvolutionThunk&) = delete;
     53   ConvolutionThunk& operator=(const ConvolutionThunk&) = delete;
     54 
     55   // Does the convolution for the thunk on "stream".
     56   Status ExecuteOnStream(const BufferAllocations& buffer_allocations,
     57                          se::Stream* stream,
     58                          HloExecutionProfiler* profiler) override;
     59 
     60  private:
     61   const HloCustomCallInstruction* cudnn_call_;
     62   std::vector<BufferAllocation::Slice> operand_buffers_;
     63   BufferAllocation::Slice result_buffer_;
     64   BufferAllocation::Slice scratch_buffer_;
     65   BufferAllocation::Slice tuple_result_buffer_;
     66 };
     67 
     68 }  // namespace gpu
     69 }  // namespace xla
     70 
     71 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CONVOLUTION_THUNK_H_
     72