1 |
commit: c2093208c4f1e989a4f0041e33ee3bafd72a2ae6 |
2 |
Author: spiros <andyspiros <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Jul 4 09:35:40 2011 +0000 |
4 |
Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com> |
5 |
CommitDate: Mon Jul 4 09:35:40 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=c2093208 |
7 |
|
8 |
BaseModule introduced. Work on accuracy module. |
9 |
|
10 |
--- |
11 |
.../python/{blas_accuracy.py => basemodule.py} | 153 ++++++++--------- |
12 |
.../autobench/files/python/blas_accuracy.py | 179 +++---------------- |
13 |
app-benchmarks/autobench/files/python/blasbase.py | 23 +--- |
14 |
app-benchmarks/autobench/files/python/btlbase.py | 188 +++----------------- |
15 |
app-benchmarks/autobench/files/python/lapack.py | 26 +--- |
16 |
5 files changed, 128 insertions(+), 441 deletions(-) |
17 |
|
18 |
diff --git a/app-benchmarks/autobench/files/python/blas_accuracy.py b/app-benchmarks/autobench/files/python/basemodule.py |
19 |
similarity index 60% |
20 |
copy from app-benchmarks/autobench/files/python/blas_accuracy.py |
21 |
copy to app-benchmarks/autobench/files/python/basemodule.py |
22 |
index 9e13ed2..5a35cc7 100644 |
23 |
--- a/app-benchmarks/autobench/files/python/blas_accuracy.py |
24 |
+++ b/app-benchmarks/autobench/files/python/basemodule.py |
25 |
@@ -1,8 +1,8 @@ |
26 |
-from pprint import pprint |
27 |
from os.path import join as pjoin |
28 |
import subprocess as sp |
29 |
import shlex, os |
30 |
from htmlreport import HTMLreport |
31 |
+import basemodule |
32 |
|
33 |
try: |
34 |
import matplotlib.pyplot as plt |
35 |
@@ -16,7 +16,7 @@ except ImportError: |
36 |
|
37 |
run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0] |
38 |
|
39 |
-class Module: |
40 |
+class BaseModule: |
41 |
def __init__(self, Print, libdir, args): |
42 |
self.Print = Print |
43 |
self.libdir = libdir |
44 |
@@ -37,31 +37,14 @@ class Module: |
45 |
passargs += [i] |
46 |
|
47 |
self._parse_args(passargs) |
48 |
- |
49 |
- def _initialize(self): |
50 |
- self.libname = 'blas' |
51 |
- self.avail=['axpy', 'matrix_vector', 'trisolve_vector', 'matrix_matrix'] |
52 |
- |
53 |
- def _parse_args(self, args): |
54 |
- # Parse arguments |
55 |
- tests = [] |
56 |
- for i in args: |
57 |
- if i in self.avail: |
58 |
- tests.append(i) |
59 |
- continue |
60 |
- raise Exception("Argument not recognized: " + i) |
61 |
- |
62 |
- # Sort tests |
63 |
- self.tests = [i for i in self.avail if i in tests] |
64 |
- |
65 |
- # If no test is specified, then do everything |
66 |
- if len(self.tests) == 0: |
67 |
- self.tests = self.avail |
68 |
|
69 |
+ # Alternatives-2 version with pkg-config |
70 |
def _get_flags(self, root, impl, libdir): |
71 |
+ while libdir[0] == '/': |
72 |
+ libdir = libdir[1:] |
73 |
# Retrieve pkgconfig settings and map the directories to the new root |
74 |
path = pjoin(root, "etc/env.d/alternatives", \ |
75 |
- self.libname, impl, libdir, "pkgconfig") |
76 |
+ self.libname,impl,libdir, "pkgconfig") |
77 |
cmd = ['pkg-config', '--libs', '--cflags', self.libname] |
78 |
env = {'PKG_CONFIG_PATH':path} |
79 |
pkgconf = sp.Popen(cmd, stdout=sp.PIPE, env=env).communicate()[0] |
80 |
@@ -69,41 +52,60 @@ class Module: |
81 |
pkgconf = pkgconf.replace('-I/', '-I'+root+'/') |
82 |
return shlex.split(pkgconf) |
83 |
|
84 |
+ # Alternatives-2 version |
85 |
def get_impls(self, root): |
86 |
output = sp.Popen( |
87 |
- ['eselect', '--no-color', '--brief', 'blas', 'list'], |
88 |
- env={'ROOT' : root}, stdout=sp.PIPE |
89 |
- ).communicate()[0] |
90 |
+ ['eselect', '--no-color', '--brief', self.libname, 'list'], |
91 |
+ env={'ROOT' : root}, stdout=sp.PIPE).communicate()[0] |
92 |
return output.strip().split('\n') |
93 |
+ |
94 |
+ # Base version |
95 |
+ def _generateResults(self, files): |
96 |
+ return dict(zip(self.tests, files)) |
97 |
|
98 |
def run_test(self, root, impl, testdir, env, logdir): |
99 |
+ # Convenient renames and definition of report files |
100 |
Print = self.Print |
101 |
- libdir = self.libdir |
102 |
name = self.libname |
103 |
- files = [pjoin(testdir, 'accuracy_%s_%s.dat' % (op, name)) \ |
104 |
- for op in self.tests] |
105 |
+ files = [pjoin(testdir,f) for f in self.files] |
106 |
+ if self.libdir[0] == '/': |
107 |
+ libdir = root+self.libdir |
108 |
+ else: |
109 |
+ libdir = pjoin(root, self.libdir) |
110 |
+ |
111 |
+ # Create dir. If all results already exist use them and do not perform |
112 |
+ # the tests, otherwise remove every old results. |
113 |
+ runtests = False |
114 |
+ if os.path.exists(testdir): |
115 |
+ runtests = not all([os.path.exists(i) for i in files]) |
116 |
+ else: |
117 |
+ os.makedirs(testdir) |
118 |
+ runtests = True |
119 |
+ |
120 |
+ if not runtests: |
121 |
+ Print("Not testing: results exist") |
122 |
+ return self._generateResults(files) |
123 |
|
124 |
- results = {} |
125 |
- for op in self.tests: |
126 |
- results[op] = pjoin(testdir, 'accuracy_%s_%s.dat' % (op, name)) |
127 |
+ for i in files: |
128 |
+ if os.path.exists(i): os.remove(i) |
129 |
|
130 |
# Prepare the environment |
131 |
if env.has_key('LIBRARY_PATH'): |
132 |
- env['LIBRARY_PATH'] = pjoin(root,libdir) + ":" + env['LIBRARY_PATH'] |
133 |
+ env['LIBRARY_PATH'] = libdir + ":" + env['LIBRARY_PATH'] |
134 |
else: |
135 |
- env['LIBRARY_PATH'] = pjoin(root, libdir) |
136 |
+ env['LIBRARY_PATH'] = libdir |
137 |
|
138 |
if env.has_key('INCLUDE_PATH'): |
139 |
env['INCLUDE_PATH'] = \ |
140 |
- pjoin(root, "/usr/include") + ":" + env['INCLUDE_PATH'] |
141 |
+ pjoin(root, "usr/include") + ":" + env['INCLUDE_PATH'] |
142 |
else: |
143 |
- env['INCLUDE_PATH'] = pjoin(root, "/usr/include") |
144 |
+ env['INCLUDE_PATH'] = pjoin(root, "usr/include") |
145 |
|
146 |
if env.has_key('LD_LIBRARY_PATH'): |
147 |
env['LD_LIBRARY_PATH'] = \ |
148 |
- pjoin(root, libdir) + ":" + env['LD_LIBRARY_PATH'] |
149 |
+ libdir + ":" + env['LD_LIBRARY_PATH'] |
150 |
else: |
151 |
- env['LD_LIBRARY_PATH'] = pjoin(root, libdir) |
152 |
+ env['LD_LIBRARY_PATH'] = libdir |
153 |
|
154 |
# Backup the environment |
155 |
oldenv = {} |
156 |
@@ -111,60 +113,51 @@ class Module: |
157 |
oldenv[k] = \ |
158 |
(os.environ.has_key(k) and (os.environ[k],) or (None,))[0] |
159 |
|
160 |
- # Set the environment |
161 |
+ # Set the new environment |
162 |
for k,v in env.items(): |
163 |
os.environ[k] = v |
164 |
|
165 |
# Compile test suite |
166 |
- exe = pjoin(testdir, 'test') |
167 |
- source = "accuracy/main_blas.cpp" |
168 |
- flags = self._get_flags(root, impl, libdir) |
169 |
- cxxflags = run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip() |
170 |
- cxx = 'g++' |
171 |
- cmd = [cxx, '-o', exe, source] + flags + shlex.split(cxxflags) |
172 |
- logfile = pjoin(logdir, 'compile.log') |
173 |
- p = sp.Popen(cmd, stdout=file(logfile, 'w'), stderr=sp.STDOUT) |
174 |
- p.wait() |
175 |
- if p.returncode != 0: |
176 |
+ logfile = os.path.join(logdir, name+"_comp.log") |
177 |
+ returncode, exe = self._compileTest(logfile=logfile, testdir=testdir, \ |
178 |
+ root=root, impl=impl, libdir=libdir) |
179 |
+ if returncode != 0: |
180 |
Print("Compilation failed") |
181 |
Print("See log: " + logfile) |
182 |
return |
183 |
Print("Compilation successful") |
184 |
|
185 |
# Run test |
186 |
- logfile = file(pjoin(logdir, name+"_run.log"), 'w') |
187 |
- cmd = [pjoin(testdir,"test")] + self.tests |
188 |
- proc = sp.Popen(cmd, bufsize=1, stdout=sp.PIPE, stderr=sp.PIPE, |
189 |
- cwd=testdir) |
190 |
- Print.down() |
191 |
- while True: |
192 |
- line = proc.stdout.readline() |
193 |
- if not line: |
194 |
- break |
195 |
- logfile.write(line) |
196 |
- if len(line.strip()) == 0: |
197 |
- continue |
198 |
- if line[0] != ' ': |
199 |
- Print.up() |
200 |
- Print(line.strip().split()[-1]) |
201 |
- Print.down() |
202 |
- else: |
203 |
- Print(line.strip()) |
204 |
- Print.up() |
205 |
- logfile.close() |
206 |
- proc.wait() |
207 |
- if proc.returncode != 0: |
208 |
- Print('Test failed') |
209 |
- else: |
210 |
- Print('Test successful') |
211 |
- |
212 |
- return results |
213 |
+ logfile = pjoin(logdir, name+"_run.log") |
214 |
+ retcode = self._executeTest(logfile=logfile, exe=exe, testdir=testdir) |
215 |
+ if returncode != 0: |
216 |
+ Print("Test failed") |
217 |
+ Print("See log: " + logfile) |
218 |
+ return |
219 |
+ Print("Test successful") |
220 |
|
221 |
+ # Restore the old environment |
222 |
+ for k in env.keys(): |
223 |
+ if oldenv[k] != None: |
224 |
+ os.environ[k] = oldenv[k] |
225 |
+ elif os.environ.has_key(k): |
226 |
+ del os.environ[k] |
227 |
+ |
228 |
+ # Return |
229 |
+ return self._generateResults(files) |
230 |
+ |
231 |
|
232 |
- def save_results(self, results, figdir): |
233 |
+ def save_results(self, results, figdir, plottype='plot'): |
234 |
if not with_images: |
235 |
self.Print("Report generation skipped - missing libraries") |
236 |
return |
237 |
+ |
238 |
+ if plottype == 'plot': plotf = plt.plot |
239 |
+ elif plottype == 'semilogx': plotf = plt.semilogx |
240 |
+ elif plottype == 'semilogy': plotf = plt.semilogy |
241 |
+ elif plottype == 'loglog': plotf = plt.loglog |
242 |
+ else: |
243 |
+ raise Exception('Unrecognized plot type: "' + plottype + '"') |
244 |
|
245 |
# Re-order the result dictionary |
246 |
newresults = {} |
247 |
@@ -189,7 +182,7 @@ class Module: |
248 |
plt.title(test) |
249 |
for impl in newresults[test]: |
250 |
x,y = np.loadtxt(newresults[test][impl], unpack=True) |
251 |
- plt.loglog(x,y, label=impl, hold=True) |
252 |
+ plotf(x,y, label=impl, hold=True) |
253 |
plt.legend(loc='best') |
254 |
plt.grid(True) |
255 |
fname = pjoin(figdir, 'summary.png') |
256 |
@@ -203,7 +196,7 @@ class Module: |
257 |
plt.figure(figsize=(12,9), dpi=300) |
258 |
for impl in newresults[test]: |
259 |
x,y = np.loadtxt(newresults[test][impl], unpack=True) |
260 |
- plt.loglog(x,y, label=impl, hold=True) |
261 |
+ plotf(x,y, label=impl, hold=True) |
262 |
plt.legend(loc='best') |
263 |
plt.grid(True) |
264 |
fname = pjoin(figdir, test+".png") |
265 |
@@ -212,5 +205,3 @@ class Module: |
266 |
self.Print('Figure ' + fname + ' saved') |
267 |
|
268 |
html.close() |
269 |
- |
270 |
- |
271 |
|
272 |
diff --git a/app-benchmarks/autobench/files/python/blas_accuracy.py b/app-benchmarks/autobench/files/python/blas_accuracy.py |
273 |
index 9e13ed2..edbf343 100644 |
274 |
--- a/app-benchmarks/autobench/files/python/blas_accuracy.py |
275 |
+++ b/app-benchmarks/autobench/files/python/blas_accuracy.py |
276 |
@@ -1,8 +1,8 @@ |
277 |
-from pprint import pprint |
278 |
from os.path import join as pjoin |
279 |
import subprocess as sp |
280 |
import shlex, os |
281 |
from htmlreport import HTMLreport |
282 |
+import basemodule |
283 |
|
284 |
try: |
285 |
import matplotlib.pyplot as plt |
286 |
@@ -16,27 +16,7 @@ except ImportError: |
287 |
|
288 |
run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0] |
289 |
|
290 |
-class Module: |
291 |
- def __init__(self, Print, libdir, args): |
292 |
- self.Print = Print |
293 |
- self.libdir = libdir |
294 |
- self.summary = False |
295 |
- self.summary_only = False |
296 |
- |
297 |
- self._initialize() |
298 |
- |
299 |
- passargs = [] |
300 |
- for i in args: |
301 |
- if i == '-S': |
302 |
- self.summary_only = True |
303 |
- continue |
304 |
- elif i == '-s': |
305 |
- self.summary = True |
306 |
- continue |
307 |
- else: |
308 |
- passargs += [i] |
309 |
- |
310 |
- self._parse_args(passargs) |
311 |
+class Module(basemodule.BaseModule): |
312 |
|
313 |
def _initialize(self): |
314 |
self.libname = 'blas' |
315 |
@@ -57,86 +37,29 @@ class Module: |
316 |
# If no test is specified, then do everything |
317 |
if len(self.tests) == 0: |
318 |
self.tests = self.avail |
319 |
- |
320 |
- def _get_flags(self, root, impl, libdir): |
321 |
- # Retrieve pkgconfig settings and map the directories to the new root |
322 |
- path = pjoin(root, "etc/env.d/alternatives", \ |
323 |
- self.libname, impl, libdir, "pkgconfig") |
324 |
- cmd = ['pkg-config', '--libs', '--cflags', self.libname] |
325 |
- env = {'PKG_CONFIG_PATH':path} |
326 |
- pkgconf = sp.Popen(cmd, stdout=sp.PIPE, env=env).communicate()[0] |
327 |
- pkgconf = pkgconf.replace('-L/', '-L'+root+'/') |
328 |
- pkgconf = pkgconf.replace('-I/', '-I'+root+'/') |
329 |
- return shlex.split(pkgconf) |
330 |
- |
331 |
- def get_impls(self, root): |
332 |
- output = sp.Popen( |
333 |
- ['eselect', '--no-color', '--brief', 'blas', 'list'], |
334 |
- env={'ROOT' : root}, stdout=sp.PIPE |
335 |
- ).communicate()[0] |
336 |
- return output.strip().split('\n') |
337 |
- |
338 |
- def run_test(self, root, impl, testdir, env, logdir): |
339 |
- Print = self.Print |
340 |
- libdir = self.libdir |
341 |
- name = self.libname |
342 |
- files = [pjoin(testdir, 'accuracy_%s_%s.dat' % (op, name)) \ |
343 |
+ |
344 |
+ # Generate list of dat (result) files, relative to the testdir |
345 |
+ self.files = [pjoin('accuracy_%s_%s.dat' % (op, name)) \ |
346 |
for op in self.tests] |
347 |
|
348 |
- results = {} |
349 |
- for op in self.tests: |
350 |
- results[op] = pjoin(testdir, 'accuracy_%s_%s.dat' % (op, name)) |
351 |
- |
352 |
- # Prepare the environment |
353 |
- if env.has_key('LIBRARY_PATH'): |
354 |
- env['LIBRARY_PATH'] = pjoin(root,libdir) + ":" + env['LIBRARY_PATH'] |
355 |
- else: |
356 |
- env['LIBRARY_PATH'] = pjoin(root, libdir) |
357 |
- |
358 |
- if env.has_key('INCLUDE_PATH'): |
359 |
- env['INCLUDE_PATH'] = \ |
360 |
- pjoin(root, "/usr/include") + ":" + env['INCLUDE_PATH'] |
361 |
- else: |
362 |
- env['INCLUDE_PATH'] = pjoin(root, "/usr/include") |
363 |
- |
364 |
- if env.has_key('LD_LIBRARY_PATH'): |
365 |
- env['LD_LIBRARY_PATH'] = \ |
366 |
- pjoin(root, libdir) + ":" + env['LD_LIBRARY_PATH'] |
367 |
- else: |
368 |
- env['LD_LIBRARY_PATH'] = pjoin(root, libdir) |
369 |
- |
370 |
- # Backup the environment |
371 |
- oldenv = {} |
372 |
- for k in env.keys(): |
373 |
- oldenv[k] = \ |
374 |
- (os.environ.has_key(k) and (os.environ[k],) or (None,))[0] |
375 |
- |
376 |
- # Set the environment |
377 |
- for k,v in env.items(): |
378 |
- os.environ[k] = v |
379 |
- |
380 |
- # Compile test suite |
381 |
+ def _compileTest(self, logfile, testdir, root, impl, *args, **kwargs): |
382 |
exe = pjoin(testdir, 'test') |
383 |
source = "accuracy/main_blas.cpp" |
384 |
- flags = self._get_flags(root, impl, libdir) |
385 |
+ flags = self._get_flags(root, impl, self.libdir) |
386 |
cxxflags = run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip() |
387 |
cxx = 'g++' |
388 |
cmd = [cxx, '-o', exe, source] + flags + shlex.split(cxxflags) |
389 |
- logfile = pjoin(logdir, 'compile.log') |
390 |
- p = sp.Popen(cmd, stdout=file(logfile, 'w'), stderr=sp.STDOUT) |
391 |
- p.wait() |
392 |
- if p.returncode != 0: |
393 |
- Print("Compilation failed") |
394 |
- Print("See log: " + logfile) |
395 |
- return |
396 |
- Print("Compilation successful") |
397 |
- |
398 |
- # Run test |
399 |
- logfile = file(pjoin(logdir, name+"_run.log"), 'w') |
400 |
- cmd = [pjoin(testdir,"test")] + self.tests |
401 |
+ proc = sp.Popen(cmd, stdout=file(logfile, 'w'), stderr=sp.STDOUT) |
402 |
+ proc.wait() |
403 |
+ return proc.returncode, exe |
404 |
+ |
405 |
+ def _executeTest(self, logfile, exe, testdir): |
406 |
+ # TODO: control objdump and nm |
407 |
+ logfile = file(logfile, 'w') |
408 |
+ cmd = [exe] + self.tests |
409 |
proc = sp.Popen(cmd, bufsize=1, stdout=sp.PIPE, stderr=sp.PIPE, |
410 |
cwd=testdir) |
411 |
- Print.down() |
412 |
+ self.Print.down() |
413 |
while True: |
414 |
line = proc.stdout.readline() |
415 |
if not line: |
416 |
@@ -145,72 +68,18 @@ class Module: |
417 |
if len(line.strip()) == 0: |
418 |
continue |
419 |
if line[0] != ' ': |
420 |
- Print.up() |
421 |
- Print(line.strip().split()[-1]) |
422 |
- Print.down() |
423 |
+ self.Print.up() |
424 |
+ self.Print(line.strip().split()[-1]) |
425 |
+ self.Print.down() |
426 |
else: |
427 |
- Print(line.strip()) |
428 |
- Print.up() |
429 |
+ self.Print(line.strip()) |
430 |
+ self.Print.up() |
431 |
logfile.close() |
432 |
proc.wait() |
433 |
- if proc.returncode != 0: |
434 |
- Print('Test failed') |
435 |
- else: |
436 |
- Print('Test successful') |
437 |
- |
438 |
- return results |
439 |
- |
440 |
+ return proc.returncode |
441 |
+ |
442 |
|
443 |
def save_results(self, results, figdir): |
444 |
- if not with_images: |
445 |
- self.Print("Report generation skipped - missing libraries") |
446 |
- return |
447 |
- |
448 |
- # Re-order the result dictionary |
449 |
- newresults = {} |
450 |
- for test in self.tests: |
451 |
- newresults[test] = {} |
452 |
- for nameimpl in results: |
453 |
- nameimplstr = pjoin(*nameimpl) |
454 |
- resdat = results[nameimpl][test] |
455 |
- newresults[test][nameimplstr] = resdat |
456 |
- |
457 |
- # Begin the HTML report |
458 |
- htmlfname = pjoin(figdir, 'index.html') |
459 |
- html = HTMLreport(htmlfname) |
460 |
- |
461 |
- # Generate summary - a single image with all plots |
462 |
- if self.summary or self.summary_only: |
463 |
- # Save summary figure |
464 |
- sprows = (len(self.tests)+1)/2 |
465 |
- plt.figure(figsize=(16,6*sprows), dpi=300) |
466 |
- for i, test in enumerate(self.tests, 1): |
467 |
- plt.subplot(sprows, 2, i) |
468 |
- plt.title(test) |
469 |
- for impl in newresults[test]: |
470 |
- x,y = np.loadtxt(newresults[test][impl], unpack=True) |
471 |
- plt.loglog(x,y, label=impl, hold=True) |
472 |
- plt.legend(loc='best') |
473 |
- plt.grid(True) |
474 |
- fname = pjoin(figdir, 'summary.png') |
475 |
- plt.savefig(fname, format='png') |
476 |
- html.addFig("Summary", image=os.path.basename(fname), width='95%') |
477 |
- self.Print('Summary figure saved: ' + fname) |
478 |
- |
479 |
- # Generate plots |
480 |
- if not self.summary_only: |
481 |
- for test in self.tests: |
482 |
- plt.figure(figsize=(12,9), dpi=300) |
483 |
- for impl in newresults[test]: |
484 |
- x,y = np.loadtxt(newresults[test][impl], unpack=True) |
485 |
- plt.loglog(x,y, label=impl, hold=True) |
486 |
- plt.legend(loc='best') |
487 |
- plt.grid(True) |
488 |
- fname = pjoin(figdir, test+".png") |
489 |
- plt.savefig(fname, format='png') |
490 |
- html.addFig(test, image=os.path.basename(fname)) |
491 |
- self.Print('Figure ' + fname + ' saved') |
492 |
- |
493 |
- html.close() |
494 |
+ basemodule.BaseModule.save_results(self, results,figdir, 'loglog') |
495 |
|
496 |
|
497 |
|
498 |
diff --git a/app-benchmarks/autobench/files/python/blasbase.py b/app-benchmarks/autobench/files/python/blasbase.py |
499 |
index 2ca9070..d2e4edd 100644 |
500 |
--- a/app-benchmarks/autobench/files/python/blasbase.py |
501 |
+++ b/app-benchmarks/autobench/files/python/blasbase.py |
502 |
@@ -36,6 +36,8 @@ class BLASBase(btlbase.BTLBase): |
503 |
if len(self.tests) == 0: |
504 |
self.tests = ['axpy', 'matrix_vector', \ |
505 |
'trisolve_vector', 'matrix_matrix'] |
506 |
+ |
507 |
+ btlbase.BTLBase._parse_args(self, args) |
508 |
|
509 |
@staticmethod |
510 |
def _btl_source(): |
511 |
@@ -47,24 +49,3 @@ class BLASBase(btlbase.BTLBase): |
512 |
|
513 |
def _btl_defines(self): |
514 |
return ["CBLASNAME=" + self.libname, "BLAS_INTERFACE"] |
515 |
- |
516 |
- def _get_flags(self, root, impl, libdir): |
517 |
- # Retrieve pkgconfig settings and map the directories to the new root |
518 |
- path = pjoin(root, "etc/env.d/alternatives", \ |
519 |
- self.libname,impl,libdir, "pkgconfig") |
520 |
- cmd = ['pkg-config', '--libs', '--cflags', self.libname] |
521 |
- env = {'PKG_CONFIG_PATH':path} |
522 |
- pkgconf = sp.Popen(cmd, stdout=sp.PIPE, env=env).communicate()[0] |
523 |
- pkgconf = pkgconf.replace('-L/', '-L'+root+'/') |
524 |
- pkgconf = pkgconf.replace('-I/', '-I'+root+'/') |
525 |
- return shlex.split(pkgconf) |
526 |
- |
527 |
- |
528 |
- def get_impls(self, root): |
529 |
- output = sp.Popen( |
530 |
- ['eselect', '--no-color', '--brief', self.libname, 'list'], |
531 |
- env={'ROOT' : root}, stdout=sp.PIPE |
532 |
- ).communicate()[0] |
533 |
- return output.strip().split('\n') |
534 |
- |
535 |
-del btlbase |
536 |
|
537 |
diff --git a/app-benchmarks/autobench/files/python/btlbase.py b/app-benchmarks/autobench/files/python/btlbase.py |
538 |
index 1c6f8aa..5e07178 100644 |
539 |
--- a/app-benchmarks/autobench/files/python/btlbase.py |
540 |
+++ b/app-benchmarks/autobench/files/python/btlbase.py |
541 |
@@ -3,6 +3,7 @@ import commands as cmd |
542 |
import subprocess as sp |
543 |
from os.path import join as pjoin |
544 |
from htmlreport import HTMLreport |
545 |
+import basemodule |
546 |
|
547 |
try: |
548 |
import matplotlib.pyplot as plt |
549 |
@@ -95,110 +96,36 @@ def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other, \ |
550 |
return cp.returncode |
551 |
|
552 |
|
553 |
-class BTLBase: |
554 |
- def __init__(self, Print, libdir, args): |
555 |
- self.Print = Print |
556 |
- self.libdir = libdir |
557 |
- self.summary = False |
558 |
- self.summary_only = False |
559 |
- |
560 |
- self._initialize() |
561 |
- |
562 |
- passargs = [] |
563 |
- for i in args: |
564 |
- if i == '-S': |
565 |
- self.summary_only = True |
566 |
- continue |
567 |
- elif i == '-s': |
568 |
- self.summary = True |
569 |
- continue |
570 |
- else: |
571 |
- passargs += [i] |
572 |
- |
573 |
- self._parse_args(passargs) |
574 |
- |
575 |
- |
576 |
- def run_test(self, root, impl, testdir, env, logdir): |
577 |
- # Convenient renames and definition of report files |
578 |
- Print = self.Print |
579 |
- libdir = self.libdir |
580 |
- name = self.libname |
581 |
- files = [pjoin(testdir, 'bench_%s_%s.dat' % (op, name)) \ |
582 |
+class BTLBase(basemodule.BaseModule): |
583 |
+ |
584 |
+ def _parse_args(self, args): |
585 |
+ # Generate list of dat (result) files, relative to the testdir |
586 |
+ self.files = [pjoin('bench_%s_%s.dat' % (op, self.libname)) \ |
587 |
for op in self.tests] |
588 |
- |
589 |
- # Create dir. If all results already exist use them and do not perform |
590 |
- # the tests, otherwise remove every old results. |
591 |
- runtests = False |
592 |
- if os.path.exists(testdir): |
593 |
- runtests = not all([os.path.exists(i) for i in files]) |
594 |
- else: |
595 |
- os.makedirs(testdir) |
596 |
- runtests = True |
597 |
- |
598 |
- if not runtests: |
599 |
- Print("Not testing: results exist") |
600 |
- results = {} |
601 |
- for op in self.tests: |
602 |
- results[op] = pjoin(testdir, 'bench_%s_%s.dat'%(op,name)) |
603 |
- return results |
604 |
- |
605 |
- for i in files: |
606 |
- if os.path.exists(i): os.remove(i) |
607 |
- |
608 |
- # Prepare the environment |
609 |
- if env.has_key('LIBRARY_PATH'): |
610 |
- env['LIBRARY_PATH'] = pjoin(root,libdir) + ":" + env['LIBRARY_PATH'] |
611 |
- else: |
612 |
- env['LIBRARY_PATH'] = pjoin(root, libdir) |
613 |
- |
614 |
- if env.has_key('INCLUDE_PATH'): |
615 |
- env['INCLUDE_PATH'] = \ |
616 |
- pjoin(root, "/usr/include") + ":" + env['INCLUDE_PATH'] |
617 |
- else: |
618 |
- env['INCLUDE_PATH'] = pjoin(root, "/usr/include") |
619 |
- |
620 |
- if env.has_key('LD_LIBRARY_PATH'): |
621 |
- env['LD_LIBRARY_PATH'] = \ |
622 |
- pjoin(root, libdir) + ":" + env['LD_LIBRARY_PATH'] |
623 |
- else: |
624 |
- env['LD_LIBRARY_PATH'] = pjoin(root, libdir) |
625 |
- |
626 |
- # Backup the environment |
627 |
- oldenv = {} |
628 |
- for k in env.keys(): |
629 |
- oldenv[k] = \ |
630 |
- (os.environ.has_key(k) and (os.environ[k],) or (None,))[0] |
631 |
- |
632 |
- # Set the environment |
633 |
- for k,v in env.items(): |
634 |
- os.environ[k] = v |
635 |
- |
636 |
- # Compile test suite |
637 |
+ |
638 |
+ def _compileTest(self, logfile, testdir, root, impl, libdir, \ |
639 |
+ *args, **kwargs): |
640 |
btldir = 'btl/' |
641 |
- logfile = os.path.join(logdir, name+"_comp.log") |
642 |
+ exe = pjoin(testdir, "test") |
643 |
returncode = btlcompile( |
644 |
- exe = pjoin(testdir, "test"), |
645 |
+ exe = exe, |
646 |
source = pjoin(btldir, self._btl_source()), |
647 |
btldir = btldir, |
648 |
includes = [pjoin(btldir, d) for d in self._btl_includes()], |
649 |
defines = self._btl_defines(), |
650 |
libs = [], |
651 |
- libdirs = [root+libdir], |
652 |
- other = self._get_flags(root, impl, libdir), |
653 |
+ libdirs = [libdir], |
654 |
+ other = self._get_flags(root, impl, self.libdir), |
655 |
logfile = logfile |
656 |
) |
657 |
- if returncode != 0: |
658 |
- Print("Compilation failed") |
659 |
- Print("See log: " + logfile) |
660 |
- return |
661 |
- Print("Compilation successful") |
662 |
- |
663 |
- # Run test |
664 |
- logfile = file(pjoin(logdir, name+"_run.log"), 'w') |
665 |
- args = [pjoin(testdir,"test")] + self.tests |
666 |
+ return returncode, exe |
667 |
+ |
668 |
+ def _executeTest(self, logfile, exe, testdir): |
669 |
+ # TODO: control objdump and nm |
670 |
+ logfile = file(logfile, 'w') |
671 |
+ args = [exe] + self.tests |
672 |
proc = sp.Popen(args, bufsize=1, stdout=sp.PIPE, stderr=sp.PIPE, |
673 |
cwd = testdir) |
674 |
- results = {} |
675 |
while True: |
676 |
# Each operation test begins with a line on stderr |
677 |
errline = proc.stderr.readline() |
678 |
@@ -206,82 +133,19 @@ class BTLBase: |
679 |
break |
680 |
logfile.write(errline) |
681 |
resfile = errline.split()[-1] |
682 |
- testname = resfile[6:-5-len(name)] |
683 |
- results[testname] = pjoin(testdir, resfile) |
684 |
- Print(resfile) |
685 |
+ testname = resfile[6:-5-len(self.libname)] |
686 |
+ self.Print(resfile) |
687 |
|
688 |
# 100 different sizes for each operation test |
689 |
- Print.down() |
690 |
+ self.Print.down() |
691 |
for i in xrange(100): |
692 |
outline = proc.stdout.readline() |
693 |
logfile.write(outline) |
694 |
- Print(outline.rstrip()) |
695 |
- Print.up() |
696 |
+ self.Print(outline.strip()) |
697 |
+ self.Print.up() |
698 |
logfile.close() |
699 |
proc.wait() |
700 |
- if proc.returncode != 0: |
701 |
- Print('Test failed') |
702 |
- else: |
703 |
- Print('Test successful') |
704 |
- |
705 |
- # Restore the old environment |
706 |
- for k in env.keys(): |
707 |
- if oldenv[k] != None: |
708 |
- os.environ[k] = oldenv[k] |
709 |
- elif os.environ.has_key(k): |
710 |
- del os.environ[k] |
711 |
- return results |
712 |
+ return proc.returncode |
713 |
|
714 |
def save_results(self, results, figdir): |
715 |
- if not with_images: |
716 |
- self.Print("Report generation skipped - missing libraries") |
717 |
- return |
718 |
- |
719 |
- # Re-order the result dictionary |
720 |
- newresults = {} |
721 |
- for test in self.tests: |
722 |
- newresults[test] = {} |
723 |
- for nameimpl in results: |
724 |
- nameimplstr = pjoin(*nameimpl) |
725 |
- resdat = results[nameimpl][test] |
726 |
- newresults[test][nameimplstr] = resdat |
727 |
- |
728 |
- # Begin the HTML report |
729 |
- htmlfname = pjoin(figdir, 'index.html') |
730 |
- html = HTMLreport(htmlfname) |
731 |
- |
732 |
- # Generate summary - a single image with all plots |
733 |
- if self.summary or self.summary_only: |
734 |
- # Save summary figure |
735 |
- sprows = (len(self.tests)+1)/2 |
736 |
- plt.figure(figsize=(16,6*sprows), dpi=300) |
737 |
- for i, test in enumerate(self.tests, 1): |
738 |
- plt.subplot(sprows, 2, i) |
739 |
- plt.title(test) |
740 |
- for impl in newresults[test]: |
741 |
- x,y = np.loadtxt(newresults[test][impl], unpack=True) |
742 |
- plt.semilogx(x,y, label=impl, hold=True) |
743 |
- plt.legend(loc='best') |
744 |
- plt.grid(True) |
745 |
- fname = pjoin(figdir, 'summary.png') |
746 |
- plt.savefig(fname, format='png') |
747 |
- html.addFig("Summary", image=os.path.basename(fname), width='95%') |
748 |
- self.Print('Summary figure saved: ' + fname) |
749 |
- |
750 |
- # Generate plots |
751 |
- if not self.summary_only: |
752 |
- for test in self.tests: |
753 |
- plt.figure(figsize=(12,9), dpi=300) |
754 |
- for impl in newresults[test]: |
755 |
- x,y = np.loadtxt(newresults[test][impl], unpack=True) |
756 |
- plt.semilogx(x,y, label=impl, hold=True) |
757 |
- plt.legend(loc='best') |
758 |
- plt.grid(True) |
759 |
- fname = pjoin(figdir, test+".png") |
760 |
- plt.savefig(fname, format='png') |
761 |
- html.addFig(test, image=os.path.basename(fname)) |
762 |
- self.Print('Figure ' + fname + ' saved') |
763 |
- |
764 |
- html.close() |
765 |
- |
766 |
- |
767 |
+ basemodule.BaseModule.save_results(self, results,figdir, 'semilogx') |
768 |
|
769 |
diff --git a/app-benchmarks/autobench/files/python/lapack.py b/app-benchmarks/autobench/files/python/lapack.py |
770 |
index ec98cd5..136d837 100644 |
771 |
--- a/app-benchmarks/autobench/files/python/lapack.py |
772 |
+++ b/app-benchmarks/autobench/files/python/lapack.py |
773 |
@@ -23,34 +23,16 @@ class Module(btlbase.BTLBase): |
774 |
# If no test is specified, run everything |
775 |
if len(self.tests) == 0: |
776 |
self.tests = self.avail |
777 |
+ |
778 |
+ btlbase.BTLBase._parse_args(self, args) |
779 |
|
780 |
@staticmethod |
781 |
def _btl_source(): |
782 |
- return "/libs/LAPACK/main.cpp" |
783 |
+ return "libs/LAPACK/main.cpp" |
784 |
|
785 |
@staticmethod |
786 |
def _btl_includes(): |
787 |
- return ["/libs/BLAS", "libs/LAPACK"] |
788 |
+ return ["libs/BLAS", "libs/LAPACK"] |
789 |
|
790 |
def _btl_defines(self): |
791 |
return ["LAPACKNAME=" + self.libname] |
792 |
- |
793 |
- def _get_flags(self, root, impl, libdir): |
794 |
- # Retrieve pkgconfig settings and map the directories to the new root |
795 |
- path = "%s/etc/env.d/alternatives/%s/%s/%s/pkgconfig" % \ |
796 |
- (root, self.libname, impl, libdir) |
797 |
- pkgconf = sp.Popen('pkg-config --libs --cflags lapack', shell=True, \ |
798 |
- stdout=sp.PIPE, env={'PKG_CONFIG_PATH':path}).communicate()[0] |
799 |
- pkgconf = pkgconf.replace('-L/', '-L'+root+'/') |
800 |
- pkgconf = pkgconf.replace('-I/', '-I'+root+'/') |
801 |
- return shlex.split(pkgconf) |
802 |
- |
803 |
- |
804 |
- def get_impls(self, root): |
805 |
- output = sp.Popen( |
806 |
- ['eselect', '--no-color', '--brief', self.libname, 'list'], |
807 |
- env={'ROOT' : root}, stdout=sp.PIPE |
808 |
- ).communicate()[0] |
809 |
- return output.strip().split('\n') |
810 |
- |
811 |
-del btlbase |