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_GATHER_THUNK_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_NCCL_ALL_GATHER_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 NcclAllGatherConfig { 31 NcclCollectiveConfig config; 32 }; 33 34 // Thunk that performs a NCCL-based All-Gather among CUDA GPU-based replicas. 35 class NcclAllGatherThunk : public NcclCollectiveThunk { 36 public: 37 NcclAllGatherThunk(ThunkInfo thunk_info, mlir::lmhlo::AllGatherOp op, 38 int64 replica_count, std::vector<Buffer> buffers); 39 40 // Returns whether the given instruction can be lowered to a nccl all-gather 41 // call. 42 43 // HLO version is still needed for AllGatherDecomposer pass. 44 static bool CanImplement(const HloInstruction* hlo); 45 static bool CanImplement(mlir::lmhlo::AllGatherOp op); 46 GetName()47 static const char* GetName() { return "AllGather"; } 48 49 protected: 50 Status RunNcclCollective(const ExecuteParams& params, 51 ncclComm_t comm) override; 52 config()53 const NcclCollectiveConfig& config() const override { return config_.config; } 54 55 private: 56 const NcclAllGatherConfig config_; 57 const std::vector<Buffer> buffers_; 58 }; 59 60 } // namespace gpu 61 } // namespace xla 62 63 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_NCCL_ALL_GATHER_THUNK_H_ 64