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_CONDITIONAL_THUNK_H_
     17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CONDITIONAL_THUNK_H_
     18 
     19 #include "tensorflow/compiler/xla/service/gpu/buffer_allocations.h"
     20 #include "tensorflow/compiler/xla/service/gpu/sequential_thunk.h"
     21 #include "tensorflow/compiler/xla/service/gpu/thunk.h"
     22 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
     23 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
     24 
     25 namespace xla {
     26 namespace gpu {
     27 
     28 // ConditionalThunk implements the conditional instruction on GPU by reading the
     29 // predicate of the conditional and executing the true or the false computation
     30 // depending on the value of the predicate.
     31 //
     32 // ConditionalThunk assumes that the buffers of the conditional result and the
     33 // result of the true and false computations share the same allocation. Also,
     34 // the buffers of the true operand of the conditional and that of the parameter
     35 // instruction of the true computation share the same allocation. Similarly, the
     36 // buffers of the false operand and that of the parameter instruction of the
     37 // false computation share the same allocation.
     38 class ConditionalThunk : public Thunk {
     39  public:
     40   ConditionalThunk(const BufferAllocation::Slice& predicate_buffer_index,
     41                    const BufferAllocation::Slice& true_operand_buffer_index,
     42                    const BufferAllocation::Slice& false_operand_buffer_index,
     43                    ThunkSequence true_thunk_sequence,
     44                    ThunkSequence false_thunk_sequence,
     45                    const HloInstruction* hlo);
     46 
     47   ConditionalThunk(const ConditionalThunk&) = delete;
     48   ConditionalThunk& operator=(const ConditionalThunk&) = delete;
     49 
     50   Status Initialize(const GpuExecutable& executable) override;
     51   Status ExecuteOnStream(const BufferAllocations& buffer_allocations,
     52                          perftools::gputools::Stream* stream) override;
     53 
     54  private:
     55   BufferAllocation::Slice predicate_buffer_index_;
     56   BufferAllocation::Slice true_operand_buffer_index_;
     57   BufferAllocation::Slice false_operand_buffer_index_;
     58   SequentialThunk true_thunk_;
     59   SequentialThunk false_thunk_;
     60 };
     61 
     62 }  // namespace gpu
     63 }  // namespace xla
     64 
     65 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CONDITIONAL_THUNK_H_
     66