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

Function BuildTree

tensorflow/core/common_runtime/executor_test.cc:214–240  ·  view source on GitHub ↗

Builds a graph which adds N copies of one variable "in". I.e., a + a + a + ... + a The returned graph is parenthesized ramdonly. I.e., a + ((a + a) + a) (a + a) + (a + a) ((a + a) + a) + a are all possibly generated.

Source from the content-addressed store, hash-verified

212// ((a + a) + a) + a
213// are all possibly generated.
214void BuildTree(int N, Graph* g) {
215 CHECK_GT(N, 1);
216 // A single input node "in".
217 auto in = test::graph::Recv(g, "a", "float", ALICE, 1, BOB);
218 std::vector<Node*> nodes;
219 int i = 0;
220 // Duplicate "in" N times. Each copies is named as l0, l1, l2, ....
221 for (; i < N; ++i) {
222 nodes.push_back(test::graph::Identity(g, in, 0));
223 }
224 random::PhiloxRandom philox(testing::RandomSeed(), 17);
225 random::SimplePhilox rnd(&philox);
226 while (nodes.size() > 1) {
227 // Randomly pick two from nodes and add them. The resulting node
228 // is named lik n10, n11, .... and is put back into "nodes".
229 int x = rnd.Uniform(nodes.size());
230 auto in0 = nodes[x];
231 nodes[x] = nodes.back();
232 nodes.resize(nodes.size() - 1);
233 x = rnd.Uniform(nodes.size());
234 auto in1 = nodes[x];
235 // node = in0 + in1.
236 nodes[x] = test::graph::Add(g, in0, in1);
237 }
238 // The final output node "out".
239 test::graph::Send(g, nodes.back(), "b", BOB, 1, ALICE);
240}
241
242TEST_F(ExecutorTest, RandomTree) {
243 auto g = absl::make_unique<Graph>(OpRegistry::Global());

Callers 1

TEST_FFunction · 0.70

Calls 10

RandomSeedFunction · 0.85
UniformMethod · 0.80
RecvFunction · 0.70
SendFunction · 0.70
IdentityFunction · 0.50
AddFunction · 0.50
push_backMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected