| 34 | namespace { |
| 35 | |
| 36 | TEST(RunHandlerUtilTest, TestBasicScheduling) { |
| 37 | int num_threads = 2; |
| 38 | int num_handlers = 10; |
| 39 | |
| 40 | std::unique_ptr<RunHandlerPool> pool( |
| 41 | new RunHandlerPool(num_threads, num_threads)); |
| 42 | |
| 43 | // RunHandler should always be able to run num_threads inter closures |
| 44 | absl::Barrier barrier(num_threads); |
| 45 | |
| 46 | BlockingCounter counter(2 * num_handlers * num_threads); |
| 47 | |
| 48 | thread::ThreadPool test_pool(Env::Default(), "test", num_handlers); |
| 49 | for (int i = 0; i < num_handlers; ++i) { |
| 50 | test_pool.Schedule([&counter, &barrier, &pool, i, num_threads]() { |
| 51 | auto handler = pool->Get(i); |
| 52 | BlockingCounter local_counter(2 * num_threads); |
| 53 | auto intra_thread_pool = handler->AsIntraThreadPoolInterface(); |
| 54 | |
| 55 | for (int j = 0; j < num_threads; ++j) { |
| 56 | handler->ScheduleInterOpClosure( |
| 57 | [&local_counter, &counter, &barrier, i]() { |
| 58 | if (i == 2) { |
| 59 | barrier.Block(); |
| 60 | } |
| 61 | counter.DecrementCount(); |
| 62 | local_counter.DecrementCount(); |
| 63 | }); |
| 64 | intra_thread_pool->Schedule([&local_counter, &counter]() { |
| 65 | counter.DecrementCount(); |
| 66 | local_counter.DecrementCount(); |
| 67 | }); |
| 68 | } |
| 69 | local_counter.Wait(); |
| 70 | }); |
| 71 | } |
| 72 | counter.Wait(); |
| 73 | } |
| 74 | |
| 75 | } // namespace |
| 76 | } // namespace tensorflow |
nothing calls this directly
no test coverage detected