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

Function BM_PingPong

tensorflow/core/framework/rendezvous_test.cc:454–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452BENCHMARK(BM_SendRecv);
453
454void BM_PingPong(int iters) {
455 CHECK_GT(iters, 0);
456 auto* cm = new CancellationManager();
457 thread::ThreadPool* pool = new thread::ThreadPool(Env::Default(), "test", 1);
458
459 // The main thread sends "foo" for iters times and receives "bar"
460 // for iters times. The other thread sends "bar" for iters times
461 // and receives "foo" for iters times.
462 Rendezvous* rendez = NewLocalRendezvous();
463 pool->Schedule([rendez, iters]() {
464 Tensor bar = V("bar");
465 Tensor foo(DT_STRING, TensorShape({}));
466 bool is_dead = false;
467 Rendezvous::Args args;
468 for (int i = 0; i < iters; ++i) {
469 TF_CHECK_OK(rendez->Recv(KeyFoo(), args, &foo, &is_dead));
470 TF_CHECK_OK(rendez->Send(KeyBar(), args, bar, is_dead));
471 }
472 CHECK_EQ("foo", V(foo));
473 });
474 Tensor foo = V("foo");
475 Tensor bar(DT_STRING, TensorShape({}));
476 bool is_dead = false;
477 Rendezvous::Args args;
478 args.cancellation_manager = cm;
479 for (int i = 0; i < iters; ++i) {
480 TF_CHECK_OK(rendez->Send(KeyFoo(), args, foo, is_dead));
481 TF_CHECK_OK(rendez->Recv(KeyBar(), args, &bar, &is_dead));
482 }
483 CHECK_EQ("bar", V(bar));
484 delete pool;
485 delete cm;
486}
487BENCHMARK(BM_PingPong);
488
489} // namespace

Callers

nothing calls this directly

Calls 7

DefaultFunction · 0.85
NewLocalRendezvousFunction · 0.85
VFunction · 0.70
TensorShapeClass · 0.70
ScheduleMethod · 0.45
RecvMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected