message: Extend tile mapping json
  Summary:
  1. Only log when VLOG lvl is 2
  2. JSON is now a single line - easier for grepping
  3. Add more info about memory usage
  Test Plan: Python still parses it
  Reviewers: davidn
diff: @@ -122,6 +122,7 @@ Status SetVertexField(poplar::Graph& graph, const poplar::FieldRef& field,
  void PrintTensorMapping(const poplar::Graph& graph,
  const TensorMap& tensor_map) {
  + if (VLOG_IS_ON(2)) {
  std::stringstream ss;
  VLOG(2) << "[Poplar] Dumping tensor mapping";
  // Printed in JSON format where
  @@ -129,39 +130,54 @@ void PrintTensorMapping(const poplar::Graph& graph,
  // {
  // "inst_name": "name",
  // "output_index": output_index,
  - // "tiles": [ {"tile_id": tile_id, "num_intervals": num_intervals}, ...]
  + // "tiles_used": tiles_used,
  + // "total_memory_size": total_memory_size,
  + // "tiles": [ {"tile_id": tile_id, "num_intervals": num_intervals,
  + // "memory_size": memory_size}, ...]
  // } ...
  //
  // ]
  // }
  - ss << "\n{\"mapping\": [\n";
  + ss << " {\"mapping\": [";
  bool first_tensor = true;
  for (auto pair : tensor_map) {
  - if (!first_tensor) ss << "\n,";
  + if (!first_tensor) ss << ",";
  const auto inst_name = pair.first.first;
  const auto output_index = pair.first.second;
  const auto tensor = pair.second;
  - ss << " {\n"
  - << " \"inst_name\": \"" << inst_name << "\",\n"
  - << " \"output_index\": " << output_index << ",\n"
  - << " \"tiles\": [\n ";
  + ss << " { "
  + << "\"inst_name\": \"" << inst_name << "\", "
  + << "\"output_index\": " << output_index << ", "
  + << "\"tiles\": [";
  const auto mapping = graph.getTileMapping(tensor);
  bool first_tile = true;
  + unsigned tilesUsed = 0;
  + size_t totalMemory = 0;
  for (size_t tileIdx = 0; tileIdx < mapping.size(); tileIdx++) {
  const auto& tile = mapping[tileIdx];
  if (tile.size() != 0) {
  if (!first_tile) ss << ", ";
  + tilesUsed++;
  + size_t tileMemSize = 0;
  + for (const auto& interval : tile) {
  + tileMemSize += interval.size();
  + }
  ss << "{\"tile_id\": " << tileIdx << ", "
  - << "\"num_intervals\": " << tile.size() << "}";
  + << "\"num_intervals\": " << tile.size() << ", "
  + << "\"memory_size\": " << tileMemSize << "}";
  first_tile = false;
  + totalMemory += tileMemSize;
  }
  }
  - ss << "]\n }";
  + ss << "], "
  + << "\"total_memory_size\": " << totalMemory << ", "
  + << "\"tiles_used\": " << tilesUsed << " }";
  first_tensor = false;
  }
  - ss << " ]\n}\n";
  + ss << "]}";
  VLOG(2) << ss.str();
  }
  +}
  } // namespace poplarplugin
  } // namespace xla
  