Benchmark to simulate the overhead in training and serving workloads from too many threads grabbing the ResourceMgr lock at the same time because of the variable and queue ops.
| 29 | // many threads grabbing the ResourceMgr lock at the same time because of the |
| 30 | // variable and queue ops. |
| 31 | void ManyManyVariablesHelper(int threads, int variables, int iters) { |
| 32 | testing::StopTiming(); |
| 33 | Graph g(OpRegistry::Global()); |
| 34 | std::vector<string> targets; |
| 35 | for (int i = 0; i < variables; ++i) { |
| 36 | Node* v; |
| 37 | TF_CHECK_OK( |
| 38 | NodeBuilder( |
| 39 | g.NewName("VeryVeryLongRealistSoundingVariableName/weights"), |
| 40 | "VariableV2") |
| 41 | .Attr("shape", TensorShape()) |
| 42 | .Attr("dtype", DT_FLOAT) |
| 43 | .Finalize(&g, &v)); |
| 44 | targets.push_back(v->name()); |
| 45 | } |
| 46 | GraphDef gd; |
| 47 | g.ToGraphDef(&gd); |
| 48 | SessionOptions opts; |
| 49 | opts.config.set_inter_op_parallelism_threads(threads); |
| 50 | Session* sess = NewSession(opts); |
| 51 | TF_CHECK_OK(sess->Create(gd)); |
| 52 | TF_CHECK_OK(sess->Run({}, {}, targets, nullptr)); |
| 53 | testing::StartTiming(); |
| 54 | for (int i = 0; i < iters; ++i) { |
| 55 | TF_CHECK_OK(sess->Run({}, {}, targets, nullptr)); |
| 56 | } |
| 57 | testing::StopTiming(); |
| 58 | delete sess; |
| 59 | } |
| 60 | |
| 61 | void BM_ManyManyVariablesManyThreads(int iters, int threads) { |
| 62 | ManyManyVariablesHelper(threads, 1000, iters); |
no test coverage detected