MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / RunTest

Method RunTest

tensorflow/core/kernels/collective_nccl_test.cc:181–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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, [&note](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) {

Callers

nothing calls this directly

Calls 13

baseClass · 0.85
InitFunction · 0.50
StrAppendFunction · 0.50
TensorShapeClass · 0.50
getMethod · 0.45
InitTensorMethod · 0.45
sizeMethod · 0.45
NumElementsMethod · 0.45
CopyDeviceTensorToCPUMethod · 0.45
NotifyMethod · 0.45
WaitForNotificationMethod · 0.45

Tested by

no test coverage detected