plot.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from mpl_toolkits.axes_grid.axislines import Subplot
  5. c = np.loadtxt('ipedirectgma.cpu.txt')
  6. g = np.loadtxt('ipedirectgma.gpu.txt')
  7. xs = np.arange(128, 4096 + 128, 128)
  8. yscm, yscs = [], []
  9. ysgm, ysgs = [], []
  10. def get_mean_std(data, size):
  11. s = data[np.where(data[:,0] == size)][:,1]
  12. # remove 2x std outliers
  13. std = np.std(s)
  14. outliers = s[np.abs(s - np.mean(s)) > 4 * np.std(s)]
  15. s = s[np.abs(s - np.mean(s)) < 4 * np.std(s)]
  16. return np.mean(s), np.std(s)
  17. for i in range(128, 4096 + 128, 128):
  18. cm, cs = get_mean_std(c, i)
  19. yscm.append(cm)
  20. yscs.append(cs)
  21. gm, gs = get_mean_std(g, i)
  22. ysgm.append(gm)
  23. ysgs.append(gs)
  24. #plt.rc('font', **dict(family='serif'))
  25. fig = plt.figure(1, (4,3))
  26. ax = Subplot(fig, 111)
  27. fig.add_subplot(ax)
  28. # plt.figure(figsize=(4, 4))
  29. plt.xlabel('Packet size in (B)')
  30. plt.ylabel('Latency (us)')
  31. # plt.errorbar(xs, yscm, yerr=yscs, label='CPU')
  32. # plt.errorbar(xs, ysgm, ls='dotted', yerr=ysgs, label='GPU')
  33. ax.plot(xs, ysgm, 'x-', label='GPU memory', color='#3b5b92')
  34. ax.plot(xs, yscm, 'o-', markersize=4, label='Main memory', color='#77DD77')
  35. plt.xticks([128, 1024, 2048, 2048+1024, 4096])
  36. plt.yticks([2,4,6,8])
  37. plt.xlim(0, 4200)
  38. ax.axis["right"].set_visible(False)
  39. ax.axis["top"].set_visible(False)
  40. plt.legend(loc='upper left', frameon=False)
  41. plt.savefig('latency.pdf', dpi=300, bbox_inches='tight')
  42. A = np.vstack([xs, np.ones(len(xs))]).T
  43. mc, cc = np.linalg.lstsq(A, yscm)[0]
  44. mg, cg = np.linalg.lstsq(A, ysgm)[0]
  45. print 100000000/ (100000000 * mc + cc)
  46. print 100000000/ (100000000 * mg + cg)