| 47 | } |
| 48 | |
| 49 | void flushReduceBucket(at::ScalarType scalar_type) override |
| 50 | { |
| 51 | if (!hasKey(reduce_tasks_, scalar_type)) { return; } |
| 52 | |
| 53 | blockCopyEvents(scalar_type); |
| 54 | applyPreDivision(scalar_type); |
| 55 | |
| 56 | // NCCL AllReduce operation |
| 57 | ncclGroupStart(); |
| 58 | for (const ReduceTask& t : reduce_tasks_.at(scalar_type)) { |
| 59 | ncclResult_t result = ncclAllReduce(t.getSendBuf().data_ptr(), |
| 60 | t.getSendBuf().data_ptr(), |
| 61 | t.getSendBuf().numel(), |
| 62 | get_nccl_data_type(scalar_type), |
| 63 | getReductionOp(), |
| 64 | nccl_comm_, |
| 65 | rs_stream_); |
| 66 | if (result != ncclSuccess) { throw std::runtime_error("NCCL AllReduce failed"); } |
| 67 | } |
| 68 | ncclGroupEnd(); |
| 69 | |
| 70 | // Copy results to gradient buffers |
| 71 | { |
| 72 | at::cuda::CUDAStreamGuard guard(rs_stream_); |
| 73 | for (const ReduceTask& t : reduce_tasks_.at(scalar_type)) { |
| 74 | auto param = param_registry_->getParam(t.getDSId()); |
| 75 | auto grad_buf = param.getGradBuffer().flatten(); |
| 76 | |
| 77 | if (grad_buf.numel() == 0) { continue; } |
| 78 | |
| 79 | int64_t offset = param.getOffset(); |
| 80 | auto recv_buf = t.getSendBuf().flatten().index( |
| 81 | {torch::indexing::Slice(offset, offset + grad_buf.numel())}); |
| 82 | grad_buf.copy_(recv_buf); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | performCleanup(scalar_type); |
| 87 | } |
| 88 | |
| 89 | protected: |
| 90 | std::unordered_map<long, at::Tensor> grad_tensors_; |
nothing calls this directly
no test coverage detected