1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import numpy as np
5+ import matplotlib as mpl
6+ import scipy .ndimage as image
7+ import h5py as h5
8+ #mpl.use('Agg')
9+ import matplotlib .pyplot as plt
10+ mpl .rcParams .update ({'font.size' : 7 })
11+
12+
13+ dims = ['2D' ,'3D' ]
14+ models = ['k40' ,'m40' ,'p100' ,'v100' ]
15+ cases = ['FP16 IO' , 'FP16 COMP' ]
16+ modelcases = {'k40' : [1 ,2 ],'m40' : [1 ,2 ],'p100' : [1 ,2 ,3 ],'v100' : [1 ,2 ,3 ]}
17+ casecodes = {'FP16 IO' : 2 , 'FP16 COMP' : 3 }
18+
19+
20+ # These are the "Tableau 20" colors as RGB.
21+ colors = [(31 , 119 , 180 ), (174 , 199 , 232 ), (255 , 127 , 14 ), (255 , 187 , 120 ),
22+ (44 , 160 , 44 ), (152 , 223 , 138 ), (214 , 39 , 40 ), (255 , 152 , 150 ),
23+ (148 , 103 , 189 ), (197 , 176 , 213 ), (140 , 86 , 75 ), (196 , 156 , 148 ),
24+ (227 , 119 , 194 ), (247 , 182 , 210 ), (127 , 127 , 127 ), (199 , 199 , 199 ),
25+ (188 , 189 , 34 ), (219 , 219 , 141 ), (23 , 190 , 207 ), (158 , 218 , 229 )]
26+ # Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts.
27+ for i in range (len (colors )):
28+ r , g , b = colors [i ]
29+ colors [i ] = (r / 255. , g / 255. , b / 255. )
30+
31+
32+ """
33+ ___________________________Acceleration figure__________________________________
34+ """
35+ fig , ax = plt .subplots (1 ,1 , figsize = (9 / 2.54 , 10 / 2.54 ))
36+ bars = [None ]* len (dims )* len (cases )
37+ labels = [None ]* len (dims )* len (cases )
38+ width = 0.75 / (len (dims ))
39+ ind = np .arange (0 ,len (models ))
40+ for (ii ,dim ) in enumerate (dims ):
41+ for (jj ,case ) in enumerate (cases [::- 1 ]):
42+ thisa = [float ('Nan' )]* len (models )
43+ thise = [float ('Nan' )]* len (models )
44+ for (kk ,model ) in enumerate (models ):
45+ data = h5 .File ('times_' + dim + '_' + model + '.mat' ,'r' )
46+ if casecodes [case ] in modelcases [model ]:
47+ nstr = str (casecodes [case ])
48+ d0 = data ['timesFP1' ][24 :- 6 ]
49+ dc = data ['timesFP' + nstr ][24 :- 6 ]
50+ thisa [kk ] = np .mean (d0 / dc )
51+ thise [kk ] = np .std (d0 / dc )
52+ data .close ()
53+ bars [ii * len (dims )+ jj ] = ax .bar (ind + (ii )* width , thisa ,
54+ width , yerr = thise ,
55+ color = colors [ii * len (dims )+ jj ],
56+ edgecolor = "none" , zorder = 1 ,
57+ error_kw = dict (ecolor = 'gray' , lw = 1 ,
58+ capsize = 4 , capthick = 1 ))
59+ labels [ii * len (dims )+ jj ]= dim + ': ' + case
60+
61+ # add some text for labels, title and axes ticks
62+ ax .set_ylabel ('Acceleration' , labelpad = 5 )
63+ ax .set_xlabel ('Model' , labelpad = 5 )
64+ #ax.legend(bars, labels, frameon=False, bbox_to_anchor=(1, 1.13))
65+ ax .legend (bars , labels , loc = 'upper left' , bbox_to_anchor = (0.55 , 1.12 ))
66+
67+
68+ # Beautify the figure
69+ ax .set_xticks (ind + width * len (cases )/ 2 )
70+ ax .set_xticklabels (models )
71+ ax .spines ["top" ].set_visible (False )
72+ ax .spines ["bottom" ].set_visible (False )
73+ ax .spines ["right" ].set_visible (False )
74+ ax .spines ["left" ].set_visible (False )
75+ plt .tick_params (axis = "both" , which = "both" , bottom = "off" , top = "off" ,
76+ labelbottom = "on" , left = "off" , right = "off" , labelleft = "on" )
77+ ax .set_xlim ([- 0.5 * width ,len (models )])
78+ ax .set_yticks (np .arange (0 ,2.5 ,0.5 ))
79+ ax .set_ylim ([0 ,2.3 ])
80+ for y in np .arange (0.5 , 2.5 , 0.5 ):
81+ plt .plot ([- 0.5 * width ,len (models )],
82+ [y ] * 2 ,
83+ "--" ,
84+ lw = 0.5 , color = "lightgray" , zorder = 0 )
85+ plt .plot ([- 0.49 * width ,- 0.49 * width ], [0 ,2.3 ], lw = 1 , color = "lightgray" , zorder = 0 )
86+ plt .plot ([- 0.49 * width ,len (models )], [0 ,0 ], lw = 1 , color = "lightgray" , zorder = 0 )
87+ #plt.tight_layout()
88+ plt .savefig ('accelaration.eps' ,dpi = 300 )
89+
90+
91+ """
92+ ___________________________Time for update figure_______________________________
93+ """
94+ sizes = {'2D' :np .arange (512 ,8192 , 64 ), '3D' :np .arange (64 ,600 , 8 )}
95+ cases = ['FP32' , 'FP16 IO' , 'FP16 COMP' ]
96+ casecodes = {'FP32' : 0 ,'FP16 IO' : 2 , 'FP16 COMP' : 4 }
97+
98+ # These are the "Tableau 20" colors as RGB.
99+ colors = [(81 ,86 ,143 ), (71 ,113 ,165 ), (150 ,177 ,210 ),
100+ (229 , 83 , 0 ), (255 , 127 , 14 ), (255 , 187 , 120 ) ]
101+ # Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts.
102+ for i in range (len (colors )):
103+ r , g , b = colors [i ]
104+ colors [i ] = (r / 255. , g / 255. , b / 255. )
105+
106+
107+ fig , ax = plt .subplots (1 , 1 , figsize = (9 / 2.54 ,10 / 2.54 ))
108+ bars = [None ]* len (dims )* len (cases )
109+ labels = [None ]* len (dims )* len (cases )
110+ width = 0.75 / (len (dims ))
111+ ind = np .arange (0 ,len (models ))
112+
113+ data = h5 .File ('times_' + dim + '_' + model + '.mat' ,'r' )
114+
115+
116+ for (ii ,dim ) in enumerate (dims ):
117+ for (jj ,case ) in enumerate (cases [::- 1 ]):
118+ thisa = [float ('Nan' )]* len (models )
119+ thise = [float ('Nan' )]* len (models )
120+ for (kk ,model ) in enumerate (models ):
121+ data = h5 .File ('times_' + dim + '_' + model + '.mat' ,'r' )
122+ if casecodes [case ] in modelcases [model ]:
123+ nstr = str (casecodes [case ])
124+ d = data ['timesFP' + nstr ][24 :- 6 ]
125+ size = sizes [dim ][24 :- 6 ]
126+ if dim == '2D' :
127+ d = [d [el ] / size [el ] ** 2 for el in range (0 , len (size ))]
128+ else :
129+ d = [d [el ] / size [el ] ** 3 for el in range (0 , len (size ))]
130+ d = 1.0 / np .array (d )* 10 ** - 6
131+ thisa [kk ] = np .mean (d )
132+ thise [kk ] = np .std (d )
133+
134+ data .close ()
135+ bars [ii * len (cases )+ jj ] = ax .bar (ind + (ii )* width , thisa ,
136+ width , yerr = thise ,
137+ color = colors [ii * len (cases )+ jj ],
138+ edgecolor = "none" , zorder = 1 ,
139+ error_kw = dict (ecolor = 'gray' , lw = 1 ,
140+ capsize = 4 , capthick = 1 ))
141+ labels [ii * len (cases )+ jj ]= dim + ': ' + case
142+
143+ # add some text for labels, title and axes ticks
144+ ax .set_ylabel ('Gridpoint per second x 10$^9$' , labelpad = 10 )
145+ ax .set_xlabel ('Model' , labelpad = 5 )
146+ legend = ax .legend (bars , labels , frameon = False , loc = 'upper left' , shadow = True )
147+ legend .get_frame ().set_facecolor ('w' )
148+
149+ # Beautify the figure
150+ ax .set_xticks (ind + width * len (dims )/ 2 )
151+ ax .set_xticklabels (models )
152+ ax .spines ["top" ].set_visible (False )
153+ ax .spines ["bottom" ].set_visible (False )
154+ ax .spines ["right" ].set_visible (False )
155+ ax .spines ["left" ].set_visible (False )
156+ plt .tick_params (axis = "both" , which = "both" , bottom = "off" , top = "off" ,
157+ labelbottom = "on" , left = "off" , right = "off" , labelleft = "on" )
158+ ax .set_xlim ([- 0.5 * width ,len (models )])
159+ ax .set_yticks (np .arange (0 ,6 ,1 ))
160+ #ax.set_ylim([0,2.3])
161+ for y in np .arange (0 , 6 , 1 ):
162+ plt .plot ([- 0.5 * width ,len (models )],
163+ [y ] * 2 ,
164+ "--" ,
165+ lw = 0.5 , color = "lightgray" , zorder = 0 )
166+ plt .plot ([- 0.49 * width ,- 0.49 * width ], [0 ,6 ], lw = 1 , color = "lightgray" , zorder = 0 )
167+ plt .plot ([- 0.49 * width ,len (models )], [0 ,0 ], lw = 1 , color = "lightgray" , zorder = 0 )
168+
169+
170+ plt .savefig ('GPS.eps' ,dpi = 300 )
0 commit comments