| 179 | } |
| 180 | |
| 181 | void RunTest(int num_ranks, int input_length, int instance_key) { |
| 182 | Init(num_ranks, instance_key); |
| 183 | std::vector<float> expected; |
| 184 | InitExpected(&expected, input_length, num_ranks); |
| 185 | if (VLOG_IS_ON(3)) { |
| 186 | string str_buf; |
| 187 | for (const auto& x : expected) { |
| 188 | strings::StrAppend(&str_buf, " ", x); |
| 189 | } |
| 190 | VLOG(3) << "Expected output " << str_buf; |
| 191 | } |
| 192 | for (int rank = 0; rank < num_ranks; ++rank) { |
| 193 | DeviceInstance* instance = instances_[rank].get(); |
| 194 | instance->InitTensor(DT_FLOAT, TensorShape({input_length}), |
| 195 | [this, rank](Tensor* t) { InitInput(t, rank); }); |
| 196 | } |
| 197 | RunCollective(); |
| 198 | // Confirm that every rank computed the same correct value. |
| 199 | for (int rank = 0; rank < instances_.size(); ++rank) { |
| 200 | TF_ASSERT_OK(instances_[rank]->status_); |
| 201 | Tensor* output = &instances_[rank]->output_; |
| 202 | const int output_length = output->NumElements(); |
| 203 | VLOG(2) << "rank " << rank << " output " << output << " buf " |
| 204 | << DMAHelper::base(output); |
| 205 | Tensor actual(DT_FLOAT, TensorShape({output_length})); |
| 206 | Notification note; |
| 207 | Device* dev = instances_[rank]->device_; |
| 208 | auto* dev_info = dev->tensorflow_gpu_device_info(); |
| 209 | dev_info->default_context->CopyDeviceTensorToCPU( |
| 210 | output, /*tensor_name=*/"", dev, &actual, [¬e](const Status& s) { |
| 211 | TF_CHECK_OK(s); |
| 212 | note.Notify(); |
| 213 | }); |
| 214 | note.WaitForNotification(); |
| 215 | VLOG(3) << "rank " << rank << " got output tensor " |
| 216 | << actual.DebugString(output_length); |
| 217 | for (int i = 0; i < output_length; ++i) { |
| 218 | EXPECT_FLOAT_EQ(expected[i], actual.template flat<float>()(i)) |
| 219 | << "Mismatch at rank " << rank << " index " << i; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | std::unique_ptr<OpKernel> GetCollectiveReduceOpKernel( |
| 225 | const CollectiveParams& params, Tensor* input, DeviceBase* device) { |
nothing calls this directly
no test coverage detected