/[escript]/trunk/cusplibrary/performance/spmv/scripts/benchmark.py
ViewVC logotype

Contents of /trunk/cusplibrary/performance/spmv/scripts/benchmark.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 6 months ago) by sshaw
File MIME type: text/x-python
File size: 4462 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 #!/usr/bin/env python
2
3 ##############################################################################
4 #
5 # Copyright (c) 2003-2015 by The University of Queensland
6 # http://www.uq.edu.au
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development 2012-2013 by School of Earth Sciences
14 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
15 #
16 ##############################################################################
17
18 from __future__ import print_function, division
19
20 import os,csv
21
22 device_id = '0' # index of the device to use
23
24 binary_filename = '../spmv' # command used to run the tests
25 output_file = 'benchmark_output.log' # file where results are stored
26
27
28 # The unstructured matrices are available online:
29 # http://www.nvidia.com/content/NV_Research/matrices.zip
30
31 mats = []
32 unstructured_path = '~/scratch/Matrices/williams/mm/'
33 unstructured_mats = [('Dense','dense2.mtx'),
34 ('Protein','pdb1HYS.mtx'),
35 ('FEM/Spheres','consph.mtx'),
36 ('FEM/Cantilever','cant.mtx'),
37 ('Wind Tunnel','pwtk.mtx'),
38 ('FEM/Harbor','rma10.mtx'),
39 ('QCD','qcd5_4.mtx'),
40 ('FEM/Ship','shipsec1.mtx'),
41 ('Economics','mac_econ_fwd500.mtx'),
42 ('Epidemiology','mc2depi.mtx'),
43 ('FEM/Accelerator','cop20k_A.mtx'),
44 ('Circuit','scircuit.mtx'),
45 ('Webbase','webbase-1M.mtx'),
46 ('LP','rail4284.mtx') ]
47 unstructured_mats = [ mat + (unstructured_path,) for mat in unstructured_mats]
48
49 structured_path = '~/scratch/Matrices/stencil/'
50 structured_mats = [('Laplacian_3pt_stencil', '3pt_1000000.mtx'),
51 ('Laplacian_5pt_stencil', '5pt_1000x1000.mtx'),
52 ('Laplacian_7pt_stencil', '7pt_100x100x100.mtx'),
53 ('Laplacian_9pt_stencil', '9pt_1000x1000.mtx'),
54 ('Laplacian_27pt_stencil', '27pt_100x100x100.mtx')]
55 structured_mats = [ mat + (structured_path,) for mat in structured_mats]
56
57 # assemble suite of matrices
58 trials = unstructured_mats + structured_mats
59
60
61 def run_tests(value_type):
62 # remove previous result (if present)
63 open(output_file,'w').close()
64
65 # run benchmark for each file
66 for matrix,filename,path in trials:
67 matrix_filename = path + filename
68
69 # setup the command to execute
70 cmd = binary_filename
71 cmd += ' ' + matrix_filename # e.g. pwtk.mtx
72 cmd += ' --device=' + device_id # e.g. 0 or 1
73 cmd += ' --value_type=' + value_type # e.g. float or double
74
75 # execute the benchmark on this file
76 os.system(cmd)
77
78 # process output_file
79 matrices = {}
80 results = {}
81 kernels = set()
82 #
83 fid = open(output_file)
84 for line in fid.readlines():
85 tokens = dict( [tuple(part.split('=')) for part in line.split()] )
86
87 if 'file' in tokens:
88 file = os.path.split(tokens['file'])[1]
89 matrices[file] = tokens
90 results[file] = {}
91 else:
92 kernel = tokens['kernel']
93 results[file][kernel] = tokens
94 kernels.add(tokens['kernel'])
95
96 ## put CPU results before GPU results
97 #kernels = ['csr_serial'] + sorted(kernels - set(['csr_serial']))
98 kernels = sorted(kernels)
99
100 # write out CSV formatted results
101 def write_csv(field):
102 fid = open('bench_' + value_type + '_' + field + '.csv','w')
103 writer = csv.writer(fid)
104 writer.writerow(['matrix','file','rows','cols','nonzeros'] + kernels)
105
106 for (matrix,file,path) in trials:
107 line = [matrix, file, matrices[file]['rows'], matrices[file]['cols'], matrices[file]['nonzeros']]
108
109 matrix_results = results[file]
110 for kernel in kernels:
111 if kernel in matrix_results:
112 line.append( matrix_results[kernel][field] )
113 else:
114 line.append(' ')
115 writer.writerow( line )
116 fid.close()
117
118 write_csv('gflops') #GFLOP/s
119 write_csv('gbytes') #GBytes/s
120
121
122 run_tests('float')
123 run_tests('double')
124

  ViewVC Help
Powered by ViewVC 1.1.26