SConstruct 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8; mode: Python -*-
  2. # SConstruct for ra/bench
  3. # (c) Daniel Llorens - 2015-2016, 2018-2019
  4. # This library is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU Lesser General Public License as published by the Free
  6. # Software Foundation; either version 3 of the License, or (at your option) any
  7. # later version.
  8. # FIXME Shared pieces with {examples,test,docs}/SConstruct
  9. import os, string, atexit
  10. from os.path import join, abspath
  11. import imp
  12. ra = imp.load_source('ra', '../config/ra.py')
  13. # FIXME pick BLAS flags from here.
  14. try:
  15. Import('top')
  16. except:
  17. top = { 'skip_summary': False, 'sanitize': False, 'use_blas': False }
  18. raflags = ra.flags(top['sanitize'])
  19. vars = Variables()
  20. vars.AddVariables(PathVariable('variant_dir', 'build directory', '.', PathVariable.PathIsDirCreate))
  21. env = Environment(options=vars,
  22. ENV=dict([(k, os.environ[k] if k in os.environ else '')
  23. for k in ['PATH', 'HOME', 'TERM', 'LD_RUN_PATH', 'DYLD_LIBRARY_PATH',
  24. 'RPATH', 'LIBRARY_PATH', 'TEXINPUTS', 'GCC_COLORS', 'BOOST_ROOT']]))
  25. variant_dir = env['variant_dir']
  26. for var, default in [('CC', 'gcc'), ('CXX', 'g++'), ('FORTRAN', 'gfortran')]:
  27. ra.take_from_environ(env, var, default=default)
  28. for var in ['FORTRANFLAGS', 'LINKFLAGS', 'CCFLAGS', 'CXXFLAGS']:
  29. ra.take_from_environ(env, var, wrapper=lambda x: x.split())
  30. for var in ['RPATH', 'LIBPATH']:
  31. ra.take_from_environ(env, var, wrapper=lambda x: [x])
  32. arch = os.popen('../config/config.guess').read()
  33. cppcomp = os.popen('%s --version' % env['CXX']).read()
  34. if (arch.find('apple-darwin') >= 0) and (cppcomp.find('g++') >= 0):
  35. archflags=['-march=native', '-Wa,-q']
  36. else:
  37. archflags=['-march=native']
  38. env.Prepend(CPPPATH=['..', '.'],
  39. CCFLAGS=archflags if str(env['CCFLAGS']).strip()=='' else '',
  40. CXXFLAGS=raflags['CXXFLAGS'],
  41. LINKFLAGS=raflags['LINKFLAGS'])
  42. if top['use_blas']:
  43. print("[%s] BLAS will be used." % Dir('.').path)
  44. env_blas = ra.blas_flags(Configure, env, arch)
  45. env_blas.Append(CPPDEFINES={'RA_USE_BLAS': 1})
  46. else:
  47. env_blas = env
  48. print("[%s] BLAS won't be used." % Dir('.').path)
  49. [ra.to_test_ra(env_blas, variant_dir)(bench)
  50. for bench in ['bench-gemm']]
  51. tester = ra.to_test_ra(env, variant_dir)
  52. [tester(bench)
  53. for bench in ['bench-reduce-sqrm',
  54. 'bench-gemv', 'bench-sum-rows', 'bench-sum-cols',
  55. 'bench-pack', 'bench-from',
  56. 'bench-stencil1', 'bench-stencil2', 'bench-stencil3',
  57. 'bench-optimize', 'bench-tensorindex',
  58. 'bench-iterator', 'bench-at',
  59. 'bench-dot'
  60. ]]
  61. if not top['skip_summary']:
  62. atexit.register(lambda: ra.print_summary(GetBuildFailures, 'ra/bench'))