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

Function ManyManyVariablesHelper

tensorflow/core/kernels/variable_ops_test.cc:31–59  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

29// many threads grabbing the ResourceMgr lock at the same time because of the
30// variable and queue ops.
31void 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
61void BM_ManyManyVariablesManyThreads(int iters, int threads) {
62 ManyManyVariablesHelper(threads, 1000, iters);

Callers 1

Calls 13

StopTimingFunction · 0.85
StartTimingFunction · 0.85
nameMethod · 0.65
NodeBuilderClass · 0.50
TensorShapeClass · 0.50
NewSessionFunction · 0.50
FinalizeMethod · 0.45
AttrMethod · 0.45
NewNameMethod · 0.45
push_backMethod · 0.45
ToGraphDefMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected