plot.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. import numpy as np
  3. import matplotlib.mlab as mlab
  4. import matplotlib.pyplot as plt
  5. import matplotlib.patches as mpatches
  6. # Import data from file
  7. data_cpu = np.genfromtxt('results/cpu/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  8. data_gpu_primary = np.genfromtxt('results/gpu-primary/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  9. data_gpu_secondary = np.genfromtxt('results/gpu-secondary/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  10. # We construct a set in which we insert each benchmark name once
  11. nameset = set()
  12. names = data_cpu['name']
  13. for name in names:
  14. nameset.add(name)
  15. # Generate an array as placeholder for the x axis (we need to pass from a list to an array to take advantage of range)
  16. x = range(0, 17)
  17. # Strip away the "opencl/" prefix from all the name
  18. stripped_names = []
  19. for elem in data_cpu['name']:
  20. elem = elem.replace("opencl/", "")
  21. elem = elem.replace("/ocl", "")
  22. elem = elem.replace("/OpenCL", "")
  23. stripped_names.append(elem)
  24. # Create the bar plot for the time values
  25. plt.bar(x, data_cpu['time'], width=0.3, color='b', align='edge')
  26. plt.bar(x, data_gpu_primary['time'], width=-0.3, color='r', align='center')
  27. plt.bar(x, data_gpu_secondary['time'], width=-0.3, color='g', align='edge')
  28. plt.xticks(x, stripped_names)
  29. plt.title('Execution time of the various benchmarks expressed in seconds')
  30. plt.xlabel('Benchmark')
  31. plt.ylabel('seconds')
  32. # Add some patches as legend of the colors used for the various benchmarks
  33. red_patch = mpatches.Patch(color='blue', label='Execution time for cpu')
  34. blue_patch = mpatches.Patch(color='red', label='Execution time for gpu(4 core)')
  35. green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core)')
  36. plt.legend(handles=[red_patch, blue_patch, green_patch])
  37. # Save the obtained plot on file
  38. plt.savefig('times.pdf')
  39. plt.show()
  40. # Create the bar plot for the power values
  41. plt.bar(x, data_cpu['power'], width=0.3, color='b', align='edge')
  42. plt.bar(x, data_gpu_primary['power'], width=-0.3, color='r', align='center')
  43. plt.bar(x, data_gpu_secondary['power'], width=-0.3, color='g', align='edge')
  44. plt.xticks(x, stripped_names)
  45. plt.title('Power consumption of the various benchmarks expressed in Watt/hour')
  46. plt.xlabel('Benchmark')
  47. plt.ylabel('Watt/hour')
  48. # Add some patches as legend of the colors used for the various benchmarks
  49. red_patch = mpatches.Patch(color='blue', label='Power consumption for cpu')
  50. blue_patch = mpatches.Patch(color='red', label='Power consumption for gpu(4 core)')
  51. green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core)')
  52. plt.legend(handles=[red_patch, blue_patch, green_patch])
  53. # Save the obtained plot on file
  54. plt.savefig('power.pdf')
  55. plt.show()