1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- # -*- coding: utf-8 -*-
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.axes_grid.axislines import Subplot
- c = np.loadtxt('ipedirectgma.cpu.txt')
- g = np.loadtxt('ipedirectgma.gpu.txt')
- xs = np.arange(128, 4096 + 128, 128)
- yscm, yscs = [], []
- ysgm, ysgs = [], []
- def get_mean_std(data, size):
- s = data[np.where(data[:,0] == size)][:,1]
- # remove 2x std outliers
- std = np.std(s)
- outliers = s[np.abs(s - np.mean(s)) > 4 * np.std(s)]
- s = s[np.abs(s - np.mean(s)) < 4 * np.std(s)]
- return np.mean(s), np.std(s)
- for i in range(128, 4096 + 128, 128):
- cm, cs = get_mean_std(c, i)
- yscm.append(cm)
- yscs.append(cs)
- gm, gs = get_mean_std(g, i)
- ysgm.append(gm)
- ysgs.append(gs)
- #plt.rc('font', **dict(family='serif'))
- fig = plt.figure(1, (4,3))
- ax = Subplot(fig, 111)
- fig.add_subplot(ax)
- # plt.figure(figsize=(4, 4))
- plt.xlabel('Packet size in (B)')
- plt.ylabel('Latency (us)')
- # plt.errorbar(xs, yscm, yerr=yscs, label='CPU')
- # plt.errorbar(xs, ysgm, ls='dotted', yerr=ysgs, label='GPU')
- ax.plot(xs, ysgm, 'x-', label='GPU memory', color='#3b5b92')
- ax.plot(xs, yscm, 'o-', markersize=4, label='Main memory', color='#77DD77')
- plt.xticks([128, 1024, 2048, 2048+1024, 4096])
- plt.yticks([2,4,6,8])
- plt.xlim(0, 4200)
- ax.axis["right"].set_visible(False)
- ax.axis["top"].set_visible(False)
- plt.legend(loc='upper left', frameon=False)
- plt.savefig('latency.pdf', dpi=300, bbox_inches='tight')
- A = np.vstack([xs, np.ones(len(xs))]).T
- mc, cc = np.linalg.lstsq(A, yscm)[0]
- mg, cg = np.linalg.lstsq(A, ysgm)[0]
- print 100000000/ (100000000 * mc + cc)
- print 100000000/ (100000000 * mg + cg)
|