| 166 | |
| 167 | private: |
| 168 | void Compute(user_op::KernelComputeContext* ctx, user_op::OpKernelState*, |
| 169 | const user_op::OpKernelCache* cache) const override { |
| 170 | auto* kernel_cache = dynamic_cast<const EagerBToSOpKernelCache*>(cache); |
| 171 | CHECK(kernel_cache != nullptr); |
| 172 | const user_op::Tensor* in = ctx->Tensor4ArgNameAndIndex("in", 0); |
| 173 | user_op::Tensor* out = ctx->Tensor4ArgNameAndIndex("out", 0); |
| 174 | user_op::Tensor* tmp_buffer = ctx->Tensor4ArgNameAndIndex("tmp_buffer", 0); |
| 175 | const void* in_ptr = in->dptr(); |
| 176 | void* out_ptr = out->mut_dptr(); |
| 177 | void* tmp_buffer_ptr = tmp_buffer->mut_dptr(); |
| 178 | |
| 179 | const auto& sorted_elem_cnt2in_tensor_slice_copier_pair = |
| 180 | kernel_cache->sorted_elem_cnt2in_tensor_slice_copier_pair(); |
| 181 | const auto& sorted_elem_cnt2out_tensor_slice_copier_pair = |
| 182 | kernel_cache->sorted_elem_cnt2out_tensor_slice_copier_pair(); |
| 183 | const auto& sorted_p2p_pair = kernel_cache->sorted_p2p_pair(); |
| 184 | CHECK_EQ(sorted_elem_cnt2in_tensor_slice_copier_pair.size(), sorted_p2p_pair.size()); |
| 185 | CHECK_EQ(sorted_elem_cnt2out_tensor_slice_copier_pair.size(), sorted_p2p_pair.size()); |
| 186 | |
| 187 | DeviceType device_type = ctx->device_type(); |
| 188 | |
| 189 | for (int64_t i = 0; i < sorted_p2p_pair.size(); ++i) { |
| 190 | const auto& p2p_pair = sorted_p2p_pair.at(i); |
| 191 | int64_t src = p2p_pair.first; |
| 192 | int64_t dst = p2p_pair.second; |
| 193 | if (src == dst && src == GlobalProcessCtx::Rank()) { |
| 194 | const auto& elem_cnt2tensor_slice_copier_pair = |
| 195 | sorted_elem_cnt2in_tensor_slice_copier_pair.at(i); |
| 196 | const auto& tensor_slice_copier = elem_cnt2tensor_slice_copier_pair.second; |
| 197 | tensor_slice_copier->Copy(ctx->stream(), out_ptr, in_ptr); |
| 198 | continue; |
| 199 | } |
| 200 | if (GlobalProcessCtx::Rank() == src) { |
| 201 | const auto& elem_cnt2tensor_slice_copier_pair = |
| 202 | sorted_elem_cnt2in_tensor_slice_copier_pair.at(i); |
| 203 | const auto& elem_cnt = elem_cnt2tensor_slice_copier_pair.first; |
| 204 | const auto& tensor_slice_copier = elem_cnt2tensor_slice_copier_pair.second; |
| 205 | tensor_slice_copier->Copy(ctx->stream(), tmp_buffer_ptr, in_ptr); |
| 206 | CHECK_JUST(Send(reinterpret_cast<const void*>(tmp_buffer_ptr), elem_cnt, in->data_type(), |
| 207 | dst, device_type, ctx->stream())); |
| 208 | } |
| 209 | if (GlobalProcessCtx::Rank() == dst) { |
| 210 | const auto& elem_cnt2tensor_slice_copier_pair = |
| 211 | sorted_elem_cnt2out_tensor_slice_copier_pair.at(i); |
| 212 | const auto& elem_cnt = elem_cnt2tensor_slice_copier_pair.first; |
| 213 | const auto& tensor_slice_copier = elem_cnt2tensor_slice_copier_pair.second; |
| 214 | CHECK_JUST( |
| 215 | Recv(tmp_buffer_ptr, elem_cnt, out->data_type(), src, device_type, ctx->stream())); |
| 216 | tensor_slice_copier->Copy(ctx->stream(), out_ptr, |
| 217 | reinterpret_cast<const void*>(tmp_buffer_ptr)); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; } |
| 222 | }; |
| 223 |
nothing calls this directly
no test coverage detected