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

Function CreateGraphDef

tensorflow/core/graph/benchmark_testlib.h:72–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 .Output("y: float");
71
72GraphDef CreateGraphDef(int num_nodes, int num_edges_per_node) {
73 const int kNumInNodes = 10 * num_edges_per_node;
74 GraphDef graph_def;
75
76 auto create_node = [](const string& name, const string& op) {
77 NodeDef node;
78 node.set_name(name);
79 node.set_op(op);
80 return node;
81 };
82
83 NodeDef node;
84 for (int in = 0; in < kNumInNodes; ++in) {
85 node = create_node(/*name=*/absl::StrFormat("in%04d", in), /*op=*/"Input");
86 *graph_def.add_node() = std::move(node);
87 }
88
89 random::PhiloxRandom philox(301, 17);
90 random::SimplePhilox rnd(&philox);
91 for (int op = 0; op < num_nodes; ++op) {
92 node = create_node(/*name=*/absl::StrFormat("op%05d", op),
93 /*op=*/absl::StrFormat("In%dOut1", num_edges_per_node));
94 for (int edge = 0; edge < num_edges_per_node; ++edge) {
95 node.add_input(absl::StrFormat("in%04d", rnd.Uniform(kNumInNodes)));
96 }
97 *graph_def.add_node() = std::move(node);
98 }
99
100 // Add a single sink node. Otherwise a lot of time is spent in
101 // FixupSourceAndSinkEdges().
102 node = create_node(/*name=*/"out", /*op=*/"Output");
103 for (int op = 0; op < num_nodes; ++op) {
104 node.add_input(absl::StrFormat("op%05d", op));
105 }
106 AttrValue attr;
107 attr.set_i(num_nodes);
108 node.mutable_attr()->insert({"N", std::move(attr)});
109 *graph_def.add_node() = std::move(node);
110
111 return graph_def;
112}
113
114GraphDef CreateRandomGraph(int size) {
115 random::PhiloxRandom philox(0x12345);

Callers 5

BM_InEdgeIterationFunction · 0.70
BM_GraphCreationFunction · 0.70
BM_ToGraphDefFunction · 0.70
BM_RemoveNodeFunction · 0.70

Calls 5

set_opMethod · 0.80
UniformMethod · 0.80
set_nameMethod · 0.45
add_inputMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected