starpu_send_recv_data_use.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # StarPU --- Runtime system for heterogeneous multicore architectures.
  4. #
  5. # Copyright (C) 2019 Inria
  6. #
  7. # StarPU is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # StarPU is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. #
  16. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. #
  18. import sys
  19. PROGNAME = sys.argv[0]
  20. def usage():
  21. print("Offline tool to draw graph showing elapsed time between sent or received data and their use by tasks")
  22. print("")
  23. print("Usage: %s <folder containing comms.rec and tasks.rec files>" % PROGNAME)
  24. if len(sys.argv) != 2:
  25. usage()
  26. sys.exit(1)
  27. import re
  28. import numpy as np
  29. import matplotlib.pyplot as plt
  30. from matplotlib.gridspec import GridSpec
  31. import os
  32. def convert_rec_file(filename):
  33. lines = []
  34. item = dict()
  35. with open(filename, "r") as f:
  36. for l in f.readlines():
  37. if l == "\n":
  38. lines.append(item)
  39. item = dict()
  40. else:
  41. ls = l.split(":")
  42. key = ls[0].lower()
  43. value = ls[1].strip()
  44. if key in item:
  45. print("Warning: duplicated key '" + key + "'")
  46. else:
  47. if re.match('^\d+$', value) != None:
  48. item[key] = int(value)
  49. elif re.match("^\d+\.\d+$", value) != None:
  50. item[key] = float(value)
  51. else:
  52. item[key] = value
  53. return lines
  54. working_directory = sys.argv[1]
  55. comms = convert_rec_file(os.path.join(working_directory, "comms.rec"))
  56. tasks = [t for t in convert_rec_file(os.path.join(working_directory, "tasks.rec")) if "control" not in t and "starttime" in t]
  57. if len(tasks) == 0:
  58. print("There is no task using data after communication.")
  59. sys.exit(0)
  60. def plot_graph(comm_time_key, match, filename, title, xlabel):
  61. delays = []
  62. workers = dict()
  63. nb = 0
  64. durations = []
  65. min_time = 0.
  66. max_time = 0.
  67. for c in comms:
  68. t_matched = None
  69. for t in tasks:
  70. if match(t, c):
  71. t_matched = t
  72. break
  73. if t_matched is not None:
  74. worker = str(t_matched['mpirank']) + "-" + str(t_matched['workerid'])
  75. if worker not in workers:
  76. workers[worker] = []
  77. eps = t["starttime"] - c[comm_time_key]
  78. assert(eps > 0)
  79. durations.append(eps)
  80. workers[worker].append((c[comm_time_key], eps))
  81. if min_time == 0 or c[comm_time_key] < min_time:
  82. min_time = c[comm_time_key]
  83. if max_time == 0 or c[comm_time_key] > max_time:
  84. max_time = c[comm_time_key]
  85. nb += 1
  86. fig = plt.figure(constrained_layout=True)
  87. gs = GridSpec(2, 2, figure=fig)
  88. axs = [fig.add_subplot(gs[0, :-1]), fig.add_subplot(gs[1, :-1]), fig.add_subplot(gs[0:, -1])]
  89. i = 0
  90. for y, x in workers.items():
  91. # print(y, x)
  92. axs[0].broken_barh(x, [i*10, 8], facecolors=(0.1, 0.2, 0.5, 0.2))
  93. i += 1
  94. i = 0
  95. for y, x in workers.items():
  96. for xx in x:
  97. axs[1].broken_barh([xx], [i, 1])
  98. i += 1
  99. axs[0].set_yticks([i*10+4 for i in range(len(workers))])
  100. axs[0].set_yticklabels(list(workers))
  101. axs[0].set(xlabel="Time (ms) - Duration: " + str(max_time - min_time) + "ms", ylabel="Worker [mpi]-[*pu]", title=title)
  102. if len(durations) != 0:
  103. axs[2].hist(durations, bins=np.logspace(np.log10(1), np.log10(max(durations)), 50), rwidth=0.8)
  104. axs[2].set_xscale("log")
  105. axs[2].set(xlabel=xlabel, ylabel="Number of occurences", title="Histogramm")
  106. fig.set_size_inches(15, 9)
  107. plt.savefig(os.path.join(working_directory, filename), dpi=100)
  108. plt.show()
  109. plot_graph("recvtime", lambda t, c: (t["mpirank"] == c["dst"] and t["starttime"] >= c["recvtime"] and str(c["recvhandle"]) in t["handles"]), "recv_use.png", "Elapsed time between recv and use (ms)", "Time between data reception and its use by a task")
  110. plot_graph("sendtime", lambda t, c: (t["mpirank"] == c["src"] and t["starttime"] >= c["sendtime"] and str(c["sendhandle"]) in t["handles"]), "send_use.png", "Elapsed time between send and use (ms)", "Time between data sending and its use by a task")