| 148 | |
| 149 | private: |
| 150 | void Compute(user_op::KernelComputeContext* ctx, user_op::OpKernelState*, |
| 151 | const user_op::OpKernelCache* cache) const override { |
| 152 | auto* kernel_cache = dynamic_cast<const EagerSToBOpKernelCache*>(cache); |
| 153 | CHECK(kernel_cache != nullptr); |
| 154 | const user_op::Tensor* in = ctx->Tensor4ArgNameAndIndex("in", 0); |
| 155 | user_op::Tensor* out = ctx->Tensor4ArgNameAndIndex("out", 0); |
| 156 | user_op::Tensor* tmp_buffer = ctx->Tensor4ArgNameAndIndex("tmp_buffer", 0); |
| 157 | const void* in_ptr = in->dptr(); |
| 158 | void* out_ptr = out->mut_dptr(); |
| 159 | void* tmp_buffer_ptr = tmp_buffer->mut_dptr(); |
| 160 | |
| 161 | const auto& sorted_elem_cnt2in_tensor_slice_copier_pair = |
| 162 | kernel_cache->sorted_elem_cnt2in_tensor_slice_copier_pair(); |
| 163 | const auto& sorted_elem_cnt2out_tensor_slice_copier_pair = |
| 164 | kernel_cache->sorted_elem_cnt2out_tensor_slice_copier_pair(); |
| 165 | const auto& sorted_p2p_pair = kernel_cache->sorted_p2p_pair(); |
| 166 | CHECK_EQ(sorted_elem_cnt2in_tensor_slice_copier_pair.size(), sorted_p2p_pair.size()); |
| 167 | CHECK_EQ(sorted_elem_cnt2out_tensor_slice_copier_pair.size(), sorted_p2p_pair.size()); |
| 168 | |
| 169 | DeviceType device_type = ctx->device_type(); |
| 170 | |
| 171 | for (int64_t i = 0; i < sorted_p2p_pair.size(); ++i) { |
| 172 | const auto& p2p_pair = sorted_p2p_pair.at(i); |
| 173 | int64_t src = p2p_pair.first; |
| 174 | int64_t dst = p2p_pair.second; |
| 175 | if (GlobalProcessCtx::Rank() == src) { |
| 176 | const auto& elem_cnt2tensor_slice_copier_pair = |
| 177 | sorted_elem_cnt2in_tensor_slice_copier_pair.at(i); |
| 178 | const auto& elem_cnt = elem_cnt2tensor_slice_copier_pair.first; |
| 179 | const auto& tensor_slice_copier = elem_cnt2tensor_slice_copier_pair.second; |
| 180 | tensor_slice_copier->Copy(ctx->stream(), tmp_buffer_ptr, in_ptr); |
| 181 | CHECK_JUST(Send(reinterpret_cast<const void*>(tmp_buffer_ptr), elem_cnt, in->data_type(), |
| 182 | dst, device_type, ctx->stream())); |
| 183 | } |
| 184 | if (GlobalProcessCtx::Rank() == dst) { |
| 185 | const auto& elem_cnt2tensor_slice_copier_pair = |
| 186 | sorted_elem_cnt2out_tensor_slice_copier_pair.at(i); |
| 187 | const auto& elem_cnt = elem_cnt2tensor_slice_copier_pair.first; |
| 188 | const auto& tensor_slice_copier = elem_cnt2tensor_slice_copier_pair.second; |
| 189 | CHECK_JUST( |
| 190 | Recv(tmp_buffer_ptr, elem_cnt, out->data_type(), src, device_type, ctx->stream())); |
| 191 | tensor_slice_copier->Copy(ctx->stream(), out_ptr, |
| 192 | reinterpret_cast<const void*>(tmp_buffer_ptr)); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; } |
| 197 | }; |
| 198 |
nothing calls this directly
no test coverage detected