message: Change benchmark graph creation util to use proto's (GraphDef, NodeDef, AttrValue) explicitly instead of generating string and then converting to proto.
diff: @@ -18,6 +18,7 @@ limitations under the License.
  #include "absl/strings/str_cat.h"
  #include "absl/strings/str_format.h"
  +#include "tensorflow/core/framework/attr_value.pb.h"
  #include "tensorflow/core/framework/graph.pb.h"
  #include "tensorflow/core/framework/node_def.pb.h"
  #include "tensorflow/core/framework/op.h"
  @@ -70,30 +71,43 @@ REGISTER_OP("In16Out1")
  GraphDef CreateGraphDef(int num_nodes, int num_edges_per_node) {
  const int kNumInNodes = 10 * num_edges_per_node;
  - string s;
  - for (int in = 0; in < kNumInNodes; in++) {
  - absl::StrAppendFormat(&s, "node { name: 'in%04d' op: 'Input' }", in);
  + GraphDef graph_def;
  +
  + auto create_node = [](const string& name, const string& op) {
  + NodeDef node;
  + node.set_name(name);
  + node.set_op(op);
  + return node;
  + };
  +
  + NodeDef node;
  + for (int in = 0; in < kNumInNodes; ++in) {
  + node = create_node(/*name=*/absl::StrFormat("in%04d", in), /*op=*/"Input");
  + *graph_def.add_node() = std::move(node);
  }
  +
  random::PhiloxRandom philox(301, 17);
  random::SimplePhilox rnd(&philox);
  - for (int op = 0; op < num_nodes; op++) {
  - absl::StrAppendFormat(&s, "node { name: 'op%05d' op: 'In%dOut1' input: [ ",
  - op, num_edges_per_node);
  - for (int edge = 0; edge < num_edges_per_node - 1; ++edge) {
  - absl::StrAppendFormat(&s, "'in%04d', ", rnd.Uniform(kNumInNodes));
  + for (int op = 0; op < num_nodes; ++op) {
  + node = create_node(/*name=*/absl::StrFormat("op%05d", op),
  + /*op=*/absl::StrFormat("In%dOut1", num_edges_per_node));
  + for (int edge = 0; edge < num_edges_per_node; ++edge) {
  + node.add_input(absl::StrFormat("in%04d", rnd.Uniform(kNumInNodes)));
  }
  - absl::StrAppendFormat(&s, "'in%04d' ] } ", rnd.Uniform(kNumInNodes));
  + *graph_def.add_node() = std::move(node);
  }
  +
  // Add a single sink node. Otherwise a lot of time is spent in
  // FixupSourceAndSinkEdges().
  - absl::StrAppendFormat(&s, "node { name: 'out' op: 'Output' input: [ ");
  - for (int op = 0; op < num_nodes - 1; op++) {
  - absl::StrAppendFormat(&s, "'op%05d', ", op);
  + node = create_node(/*name=*/"out", /*op=*/"Output");
  + for (int op = 0; op < num_nodes; ++op) {
  + node.add_input(absl::StrFormat("op%05d", op));
  }
  - absl::StrAppendFormat(&s, "'op%05d' ], attr: { key: 'N' value { i: %d } } } ",
  - num_nodes - 1, num_nodes);
  - GraphDef graph_def;
  - CHECK(protobuf::TextFormat::ParseFromString(s, &graph_def));
  + AttrValue attr;
  + attr.set_i(num_nodes);
  + node.mutable_attr()->insert({"N", std::move(attr)});
  + *graph_def.add_node() = std::move(node);
  +
  return graph_def;
  }
  