This contains my bachelors thesis and associated tex files, code snippets and maybe more. Topic: Data Movement in Heterogeneous Memories with Intel Data Streaming Accelerator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.9 KiB

  1. import os
  2. import csv
  3. import numpy as np
  4. import pandas as pd
  5. import seaborn as sns
  6. import plotly.express as px
  7. import matplotlib.pyplot as plt
  8. output_path = "./plots"
  9. hbm_result = "./evaluation-results/current/qdp-xeonmax-hbm-tca4-tcb0-tcj1-tmul32-wl4294967296-cs2097152.csv"
  10. dram_result = "./evaluation-results/current/qdp-xeonmax-dram-tca2-tcb0-tcj1-tmul32-wl4294967296-cs2097152.csv"
  11. prefetch_result = "./evaluation-results/current/qdp-xeonmax-prefetch-tca1-tcb1-tcj1-tmul32-wl4294967296-cs8388608.csv"
  12. distprefetch_result = "./evaluation-results/current/qdp-xeonmax-distprefetch-tca1-tcb1-tcj1-tmul32-wl4294967296-cs8388608.csv"
  13. tt_name = "rt-ns"
  14. function_names = ["aggrj-run" , "scana-run", "scanb-run" ]
  15. fn_nice_prefetch = [ "Aggregate" ,"Scan A", "Scan A and B (parallel)"]
  16. fn_nice_normal = [ "Aggregate" , "Scan A", "NULL"]
  17. def read_timings_from_csv(fname, fn_nice) -> tuple[list[float], list[str]]:
  18. t = {}
  19. row_count = 0
  20. with open(fname, newline='') as csvfile:
  21. reader = csv.DictReader(csvfile, delimiter=';')
  22. for row in reader:
  23. row_count = row_count + 1
  24. for i in range(len(function_names)):
  25. t[fn_nice[i]] = t.get(fn_nice[i], 0) + int(row[function_names[i]])
  26. t = {key: value / (1000 * 1000 * row_count) for key, value in t.items() if value != 0}
  27. if fn_nice[2] in t.keys():
  28. t[fn_nice[1]] = t[fn_nice[1]] - t[fn_nice[2]]
  29. return list(t.values()), list(t.keys())
  30. def read_total_time_from_csv(fname) -> float:
  31. time = 0
  32. row_count = 0
  33. with open(fname, newline='') as csvfile:
  34. reader = csv.DictReader(csvfile, delimiter=';')
  35. for row in reader:
  36. row_count = row_count + 1
  37. time += int(row["rt-ns"])
  38. return time / (1000 * 1000 * row_count)
  39. def read_cache_hitrate_from_csv(fname) -> float:
  40. hitrate = 0
  41. row_count = 0
  42. with open(fname, newline='') as csvfile:
  43. reader = csv.DictReader(csvfile, delimiter=';')
  44. for row in reader:
  45. row_count = row_count + 1
  46. hitrate += float(row["cache-hr"])
  47. return (hitrate * 100) / row_count
  48. def generate_speedup_table():
  49. baseline = read_total_time_from_csv(dram_result)
  50. columns = [ "Configuration", "Speedup", "Cache Hitrate", "Raw Time" ]
  51. names = [
  52. "DDR-SDRAM (Baseline)",
  53. "HBM (Upper Limit)",
  54. "Prefetching",
  55. "Prefetching, Distributed Columns"
  56. ]
  57. rawtime = [
  58. read_total_time_from_csv(dram_result),
  59. read_total_time_from_csv(hbm_result),
  60. read_total_time_from_csv(prefetch_result),
  61. read_total_time_from_csv(distprefetch_result),
  62. ]
  63. speedup = [
  64. baseline / rawtime[0],
  65. baseline / rawtime[1],
  66. baseline / rawtime[2],
  67. baseline / rawtime[3]
  68. ]
  69. cachehr = [
  70. 0,
  71. 0,
  72. read_cache_hitrate_from_csv(prefetch_result),
  73. read_cache_hitrate_from_csv(distprefetch_result)
  74. ]
  75. data = [
  76. [ names[0], f"x{speedup[0]:1.2f}", r" \textemdash ", f"{rawtime[0]:.2f} ms" ],
  77. [ names[1], f"x{speedup[1]:1.2f}", r" \textemdash ", f"{rawtime[1]:.2f} ms" ],
  78. [ names[2], f"x{speedup[2]:1.2f}", f"{cachehr[2]:2.2f} \%", f"{rawtime[2]:.2f} ms" ],
  79. [ names[3], f"x{speedup[3]:1.2f}", f"{cachehr[3]:2.2f} \%", f"{rawtime[3]:.2f} ms" ]
  80. ]
  81. return pd.DataFrame(data, columns=columns)
  82. def generate_rawtime_base_table():
  83. baseline = read_total_time_from_csv(dram_result)
  84. columns = [ "Configuration", "Raw Time" ]
  85. names = [
  86. "DDR-SDRAM (Baseline)",
  87. "HBM (Upper Limit)"
  88. ]
  89. rawtime = [
  90. read_total_time_from_csv(dram_result),
  91. read_total_time_from_csv(hbm_result)
  92. ]
  93. data = [
  94. [ names[0], f"{rawtime[0]:.2f} ms" ],
  95. [ names[1], f"{rawtime[1]:.2f} ms" ]
  96. ]
  97. return pd.DataFrame(data, columns=columns)
  98. def tex_table(df, fname):
  99. with open(os.path.join(output_path, fname), "w") as of:
  100. of.write(df.to_latex(index=False))
  101. # loops over all possible configuration combinations and calls
  102. # process_file_to_dataset for them in order to build a dataframe
  103. # which is then displayed and saved
  104. def donut_plot(data: tuple[list[float], list[str]], maxtime, fname):
  105. # pad to maxtime
  106. data[0].append(maxtime - sum(data[0]))
  107. data[1].append("NULL")
  108. # pad to only display semi-circle
  109. data[0].append(sum(data[0]))
  110. data[1].append("NULL")
  111. fig, (ax, lax) = plt.subplots(nrows=2, gridspec_kw={"height_ratios":[4, 1]})
  112. palette_color = sns.color_palette('mako_r')
  113. wedges, texts = ax.pie(data[0], wedgeprops=dict(width=0.5), colors=palette_color)
  114. wedges[-1].set_visible(False)
  115. wedges[-2].set_visible(False)
  116. ax.set_ylim(-0.0, 1.0)
  117. legend_labels = [f"{data[0][i]:3.2f} ms - {data[1][i]}" for i in range(len(data[0])) if data[1][i] != "NULL"]
  118. lax.legend(wedges, legend_labels, borderaxespad=0, loc="upper center")
  119. lax.set_ylim(0.0, 0.25)
  120. lax.axis("off")
  121. plt.tight_layout()
  122. plt.rcParams.update({'font.size': 16})
  123. fig.savefig(os.path.join(output_path, fname), bbox_inches='tight')
  124. def main():
  125. timings = [
  126. read_timings_from_csv(prefetch_result, fn_nice_prefetch),
  127. read_timings_from_csv(distprefetch_result, fn_nice_prefetch),
  128. read_timings_from_csv(dram_result, fn_nice_normal),
  129. read_timings_from_csv(hbm_result, fn_nice_normal)
  130. ]
  131. maxtime = max([sum(timings[0][0]), sum(timings[1][0]), sum(timings[2][0]), sum(timings[3][0])])
  132. donut_plot(timings[0], maxtime, "plot-timing-prefetch.pdf")
  133. donut_plot(timings[1], maxtime, "plot-timing-distprefetch.pdf")
  134. donut_plot(timings[2], maxtime, "plot-timing-dram.pdf")
  135. donut_plot(timings[3], maxtime, "plot-timing-hbm.pdf")
  136. donut_plot(read_timings_from_csv(prefetch_result, fn_nice_prefetch), maxtime, "plot-timing-prefetch.pdf")
  137. tex_table(generate_speedup_table(), "table-qdp-speedup.tex")
  138. tex_table(generate_rawtime_base_table(), "table-qdp-baseline.tex")
  139. if __name__ == "__main__":
  140. main()