1 /* Copyright 2019 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_NCCL_ALL_REDUCE_THUNK_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_NCCL_ALL_REDUCE_THUNK_H_ 18 19 #include "tensorflow/compiler/mlir/hlo/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.h" 20 #include "tensorflow/compiler/xla/service/collective_ops_utils.h" 21 #include "tensorflow/compiler/xla/service/gpu/buffer_allocations.h" 22 #include "tensorflow/compiler/xla/service/gpu/nccl_collective_thunk.h" 23 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 24 #include "tensorflow/compiler/xla/xla_data.pb.h" 25 #include "tensorflow/core/platform/types.h" 26 27 namespace xla { 28 namespace gpu { 29 30 struct NcclAllReduceConfig { 31 NcclCollectiveConfig config; 32 ReductionKind reduction_kind; 33 }; 34 35 // Thunk that performs a NCCL-based All-Reduce among CUDA GPU-based replicas. 36 class NcclAllReduceThunk : public NcclCollectiveThunk { 37 public: 38 NcclAllReduceThunk(ThunkInfo thunk_info, mlir::lmhlo::AllReduceOp op, 39 int64 replica_count, std::vector<Buffer> buffers); 40 41 // Returns whether the given instruction can be lowered to a nccl all-reduce 42 // call. 43 static bool CanImplement(mlir::lmhlo::AllReduceOp op); 44 GetName()45 static const char* GetName() { return "AllReduce"; } 46 47 protected: 48 Status RunNcclCollective(const ExecuteParams& params, 49 ncclComm_t comm) override; 50 config()51 const NcclCollectiveConfig& config() const override { return config_.config; } 52 53 private: 54 const NcclAllReduceConfig config_; 55 const std::vector<Buffer> buffers_; 56 }; 57 58 } // namespace gpu 59 } // namespace xla 60 61 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_NCCL_ALL_REDUCE_THUNK_H_ 62