[Numpy-svn] r4489 - in branches/numpy.scons/numpy/distutils/scons: . checkers

numpy-svn@scip... numpy-svn@scip...
Thu Nov 22 02:34:13 CST 2007


Author: cdavid
Date: 2007-11-22 02:34:00 -0600 (Thu, 22 Nov 2007)
New Revision: 4489

Modified:
   branches/numpy.scons/numpy/distutils/scons/__init__.py
   branches/numpy.scons/numpy/distutils/scons/checkers/__init__.py
   branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
Log:
Some perflib cleaning

Modified: branches/numpy.scons/numpy/distutils/scons/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-11-22 04:59:19 UTC (rev 4488)
+++ branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-11-22 08:34:00 UTC (rev 4489)
@@ -4,7 +4,9 @@
 from core.extension import get_python_inc, get_pythonlib_dir
 from core.utils import isstring, rsplit
 
-from checkers import CheckCBLAS, CheckCLAPACK, CheckF77BLAS, CheckF77LAPACK
+from checkers import CheckCBLAS, CheckCLAPACK, CheckF77BLAS, CheckF77LAPACK, \
+                     IsMKL, IsATLAS, IsVeclib, IsAccelerate, IsSunperf
+
 from fortran_scons import CheckF77Verbose, CheckF77Clib, CheckF77Mangling
 
 # XXX: this is ugly, better find the mathlibs with a checker 

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/__init__.py	2007-11-22 04:59:19 UTC (rev 4488)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/__init__.py	2007-11-22 08:34:00 UTC (rev 4489)
@@ -1 +1,2 @@
 from custom_checkers import CheckCLAPACK, CheckCBLAS, CheckF77BLAS, CheckF77LAPACK
+from perflib import IsMKL, IsATLAS, IsVeclib, IsAccelerate, IsSunperf

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-11-22 04:59:19 UTC (rev 4488)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-11-22 08:34:00 UTC (rev 4489)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Fri Nov 16 06:00 PM 2007 J
+# Last Change: Thu Nov 22 04:00 PM 2007 J
 
 # Module for custom, common checkers for numpy (and scipy)
 import sys
@@ -23,15 +23,8 @@
 # LAPACK and CLAPACK ? How to test for fortran ?
 
 def CheckCBLAS(context, autoadd = 1):
-    """This checker tries to find optimized library for cblas.
-
-    This test is pretty strong: it first detects an optimized library, and then
-    tests that a simple cblas program can be run using this lib.
-    
-    It looks for the following libs:
-        - Mac OS X: Accelerate, and then vecLib.
-        - Others: MKL, then ATLAS, then Sunperf."""
-    # XXX: rpath vs LD_LIBRARY_PATH ?
+    """This checker tries to find optimized library for cblas."""
+    libname = 'cblas'
     env = context.env
 
     def check(func, name, suplibs):
@@ -42,7 +35,7 @@
             st = check_include_and_run(context, 'CBLAS (%s)' % name, 
                                        res.cfgopts, [], cblas_src, autoadd)
             if st:
-                add_info(env, 'cblas', res)
+                add_info(env, libname, res)
             return st
 
     # If section cblas is in site.cfg, use those options. Otherwise, use default
@@ -55,25 +48,17 @@
         st = check_include_and_run(context, 'CBLAS (from site.cfg) ', cfg,
                                   [], cblas_src, autoadd)
         if st:
-            add_info(env, 'cblas', ConfigRes('cblas', cfg, found))
-        return st
+            add_info(env, libname, ConfigRes('Generic CBLAS', cfg, found))
+            return st
     else:
         if sys.platform == 'darwin':
-            # Check Accelerate
             st = check(CheckAccelerate, 'Accelerate Framework', [])
             if st:
                 return st
-
             st = check(CheckVeclib, 'vecLib Framework', [])
             if st:
                 return st
-
-            add_info(env, 'cblas', 'Def numpy implementation used')
-            return 0
-            
         else:
-            # XXX: think about how to share headers info between checkers ?
-
             # Check MKL
             st = check(CheckMKL, 'MKL', [])
             if st:
@@ -89,25 +74,20 @@
             if st:
                 return st
 
-            add_info(env, 'cblas', 'Def numpy implementation used')
-            return 0
+    add_info(env, libname, None)
+    return 0
 
 def CheckF77BLAS(context, autoadd = 1):
-    """This checker tries to find optimized library for blas (fortran F77).
-
-    This test is pretty strong: it first detects an optimized library, and then
-    tests that a simple blas program (in C) can be run using this (F77) lib.
-    
-    It looks for the following libs:
-        - Mac OS X: Accelerate, and then vecLib.
-        - Others: MKL, then ATLAS, then Sunperf."""
-    # XXX: rpath vs LD_LIBRARY_PATH ?
+    """This checker tries to find optimized library for blas (fortran F77)."""
+    libname = 'blas'
     env = context.env
 
     # Get Fortran things we need
     if not env.has_key('F77_NAME_MANGLER'):
         if not CheckF77Mangling(context):
+            add_info(env, libname, None)
             return 0
+
     func_name = env['F77_NAME_MANGLER']('sgemm')
     test_src = c_sgemm2 % {'func' : func_name}
 
@@ -119,7 +99,7 @@
             st = check_include_and_run(context, 'BLAS (%s)' % name, res.cfgopts,
                     [], test_src, autoadd)
             if st:
-                add_info(env, 'blas', res)
+                add_info(env, libname, res)
             return st
 
     # If section blas is in site.cfg, use those options. Otherwise, use default
@@ -132,8 +112,8 @@
         st = check_include_and_run(context, 'BLAS (from site.cfg) ', cfg,
                                   [], test_src, autoadd)
         if st:
-            add_info(env, 'blas', ConfigRes('blas', cfg, found))
-        return st
+            add_info(env, libname, ConfigRes('Generic BLAS', cfg, found))
+            return st
     else:
         if sys.platform == 'darwin':
             # Check Accelerate
@@ -160,8 +140,7 @@
             if st:
                 return st
 
-    # XXX: Use default values for blas
-
+    add_info(env, libname, None)
     return 0
 
 def CheckF77LAPACK(context, autoadd = 1):
@@ -173,11 +152,12 @@
     It looks for the following libs:
         - Mac OS X: Accelerate, and then vecLib.
         - Others: MKL, then ATLAS."""
+    libname = 'lapack'
     env = context.env
 
     if not env.has_key('F77_NAME_MANGLER'):
         if not CheckF77Mangling(context):
-            add_info(env, 'lapack', 'Def numpy implementation used')
+            add_info(env, 'lapack', None)
             return 0
     
     # Get the mangled name of our test function
@@ -185,6 +165,8 @@
     test_src = lapack_sgesv % sgesv_string
 
     def check(func, name, suplibs):
+        # func is the perflib checker, name the printed name for the check, and
+        # suplibs a list of libraries to link in addition.
         st, res = func(context, autoadd)
         if st:
             for lib in suplibs:
@@ -192,7 +174,7 @@
             st = check_include_and_run(context, 'LAPACK (%s)' % name, res.cfgopts,
                                        [], test_src, autoadd)
             if st:
-                add_info(env, 'lapack', res)
+                add_info(env, libname, res)
             return st
 
     # If section lapack is in site.cfg, use those options. Otherwise, use default
@@ -213,8 +195,8 @@
         st = check_include_and_run(context, 'LAPACK (from site.cfg) ', fortrancfg,
                                   [], test_src, autoadd)
         if st:
-            add_info(env, 'lapack', ConfigRes('lapack', cfg, found))
-        return st
+            add_info(env, libname, ConfigRes('Generic LAPACK', cfg, found))
+            return st
     else:
         if sys.platform == 'darwin':
             st = check(CheckAccelerate, 'Accelerate Framework', [])
@@ -224,9 +206,6 @@
             st = check(CheckVeclib, 'vecLib Framework', [])
             if st:
                 return st
-
-            add_info(env, 'lapack: def numpy implementation', opts)
-            return 0
         else:
             # Check MKL
             # XXX: handle different versions of mkl (with different names)
@@ -244,7 +223,7 @@
             if st:
                 return st
 
-    add_info(env, 'lapack', 'Def numpy implementation used')
+    add_info(env, libname, None)
     return 0
 
 def CheckCLAPACK(context, autoadd = 1):
@@ -259,6 +238,7 @@
     context.Message('Checking CLAPACK ...')
     context.Result('FIXME: not implemented yet')
     return 0
+    libname = 'clapack'
     env = context.env
 
     # If section lapack is in site.cfg, use those options. Otherwise, use default
@@ -292,30 +272,30 @@
         st = check_include_and_run(context, 'LAPACK (from site.cfg) ', fortrancfg,
                                   [], test_src, autoadd)
         if st:
-            add_info(env, 'lapack', ConfigRes('lapack', cfg, found))
+            add_info(env, libname, ConfigRes('Generic CLAPACK', cfg, found))
         return st
     else:
         if sys.platform == 'darwin':
             st, opts = CheckAccelerate(context, autoadd)
             if st:
                 if st:
-                    add_info(env, 'lapack: Accelerate', opts)
+                    add_info(env, libname, opts)
                 return st
             st, opts = CheckAccelerate(context, autoadd)
             if st:
                 if st:
-                    add_info(env, 'lapack: vecLib', opts)
+                    add_info(env, libname, opts)
                 return st
 
         else:
             # Get fortran stuff (See XXX at the top on F77 vs C)
             if not env.has_key('F77_NAME_MANGLER'):
                 if not CheckF77Mangling(context):
-		    add_info(env, 'lapack', 'Def numpy implementation used')
+                    add_info(env, libname, None)
                     return 0
             if not env.has_key('F77_LDFLAGS'):
                 if not CheckF77Clib(context):
-		    add_info(env, 'lapack', 'Def numpy implementation used')
+                    add_info(env, libname, None)
                     return 0
 
             # Get the mangled name of our test function
@@ -330,7 +310,7 @@
                 st = check_include_and_run(context, 'LAPACK (MKL)', res.cfgopts,
                                            [], test_src, autoadd)
                 if st:
-                    add_info(env, 'lapack', res)
+                    add_info(env, libname, res)
                 return st
 
             # Check ATLAS
@@ -340,7 +320,7 @@
                 st = check_include_and_run(context, 'LAPACK (ATLAS)', res.cfgopts,
                                            [], test_src, autoadd)
                 if st:
-                    add_info(env, 'lapack', res)
+                    add_info(env, libname, res)
                 # XXX: Check complete LAPACK or not. (Checking for not
                 # implemented lapack symbols ?)
                 return st
@@ -351,8 +331,8 @@
                 st = check_include_and_run(context, 'LAPACK (Sunperf)', res.cfgopts,
                                            [], test_src, autoadd)
                 if st:
-                    add_info(env, 'lapack', res)
+                    add_info(env, libname, res)
                 return st
 
-    add_info(env, 'lapack', 'Def numpy implementation used')
+    add_info(env, libname, None)
     return 0

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-11-22 04:59:19 UTC (rev 4488)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-11-22 08:34:00 UTC (rev 4489)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Thu Nov 22 01:00 PM 2007 J
+# Last Change: Thu Nov 22 05:00 PM 2007 J
 
 # This module defines checkers for performances libs providing standard API,
 # such as MKL (Intel), ATLAS, Sunperf (solaris and linux), Accelerate (Mac OS
@@ -20,6 +20,82 @@
 from support import check_include_and_run, check_symbol
 from support import save_and_set, restore, ConfigOpts, ConfigRes
 
+#-------------------------------------------
+# Perflib specific configuration and helpers
+#-------------------------------------------
+class PerflibConfig:
+    def __init__(self, name, section, defopts, headers, funcs, version_checker = None):
+        """Initialize the configuration.
+
+        Args:
+            - name : str
+                the name of the perflib
+            - section : str
+                the name of the section used in site.cfg for customization
+            - defopts : ConfigOpts
+                the compilation configuration for the checker
+            - headers : list
+                the list of headers to test in the checker
+            - funcs : list
+                the list of functions to test in the checker.
+            - version_checker : callable
+                optional function to check version of the perflib. Its
+                arguments should be env and opts, where env is a scons
+                environment and opts a ConfigOpts instance. It should return an
+                integer (1 if successfull) and a version string."""
+                
+        self.name = name
+        self.section = section
+        self.defopts = defopts
+        self.headers = headers
+        self.funcs = funcs
+        self.version_checker = version_checker
+
+_CONFIG = {
+        'MKL': PerflibConfig('MKL', 'mkl', ConfigOpts(libs = ['mkl', 'guide', 'm']),
+                             ['mkl.h'], ['MKLGetVersion']),
+        'ATLAS': PerflibConfig('ATLAS', 'atlas', 
+                               ConfigOpts(libs = ['atlas'], 
+                               libpath = [pjoin(i, 'atlas') for i in 
+                                          default_lib_dirs]),
+                               ['atlas_enum.h'],
+                               ['ATL_sgemm']),
+        'Accelerate' : PerflibConfig('Framework: Accelerate', 'accelerate', 
+                                      ConfigOpts(frameworks = ['Accelerate']),
+                                      ['Accelerate/Accelerate.h'],
+                                      ['cblas_sgemm']),
+        'vecLib' : PerflibConfig('Framework: vecLib', 'vecLib', 
+                                 ConfigOpts(frameworks = ['vecLib']),
+                                 ['vecLib/vecLib.h'],
+                                 ['cblas_sgemm']),
+        'Sunperf' : PerflibConfig('Sunperf', 'sunperf', 
+                                  ConfigOpts(cflags = ['-dalign'], 
+                                             linkflags = ['-xlic_lib=sunperf']),
+                                  ['sunperf.h'],
+                                  ['cblas_sgemm'])}
+
+class IsFactory:
+    def __init__(self, name):
+        """Name should be one key of _CONFIG."""
+        try:
+            _CONFIG[name]
+        except KeyError, e:
+            raise RuntimeError("name %s is unknown")
+
+        def f(env, libname):
+            if env['NUMPY_PKG_CONFIG'][libname] is None:
+                return 0 == 1
+            else:
+                return env['NUMPY_PKG_CONFIG'][libname].name == \
+                       _CONFIG[name].name
+        self.func = f
+
+    def get_func(self):
+        return self.func
+
+#------------------------
+# Generic functionalities
+#------------------------
 def _check(context, name, section, defopts, headers_to_check, funcs_to_check, 
            check_version, version_checker, autoadd, rpath_is_libpath = True):
     """Generic implementation for perflib check.
@@ -103,6 +179,9 @@
 
     return st, cfgres
 
+#--------------
+# MKL checker
+#--------------
 def _mkl_version_checker(env, opts):
     version_code = r"""
 #include <stdio.h>
@@ -135,6 +214,17 @@
 
     return vst, version
 
+def CheckMKL(context, autoadd = 1, check_version = 0):
+    cfg = _CONFIG['MKL']
+
+    return _check(context, cfg.name, cfg.section, cfg.defopts, cfg.headers,
+                  cfg.funcs, check_version, _mkl_version_checker, autoadd)
+
+IsMKL = IsFactory('MKL').get_func()
+
+#---------------
+# ATLAS Checker
+#---------------
 def _atlas_version_checker(env, opts):
     version_code = """
 void ATL_buildinfo(void);
@@ -161,29 +251,18 @@
 
     return vst, version
 
-def CheckMKL(context, autoadd = 1, check_version = 0):
-    name    = 'MKL'
-    section = 'mkl'
-    defopts = ConfigOpts(libs = ['mkl', 'guide', 'm'])
-    headers = ['mkl.h']
-    funcs   = ['MKLGetVersion']
-
-    return _check(context, name, section, defopts, headers, funcs,
-                  check_version, _mkl_version_checker, autoadd)
-
 def CheckATLAS(context, autoadd = 1, check_version = 0):
     """Check whether ATLAS is usable in C."""
-    name    = 'ATLAS'
-    section = 'atlas'
-    defopts = ConfigOpts(libs = ['atlas'], 
-                         libpath = [pjoin(i, 'atlas') for i in 
-                                    default_lib_dirs])
-    headers = ['atlas_enum.h']
-    funcs   = ['ATL_sgemm']
-    
-    return _check(context, name, section, defopts, headers, funcs,
-                  check_version, _atlas_version_checker, autoadd)
+    cfg = _CONFIG['ATLAS']
 
+    return _check(context, cfg.name, cfg.section, cfg.defopts, cfg.headers,
+                  cfg.funcs, check_version, _atlas_version_checker, autoadd)
+
+IsATLAS = IsFactory('ATLAS').get_func()
+
+#------------------------------
+# Mac OS X Frameworks checkers
+#------------------------------
 def CheckAccelerate(context, autoadd = 1, check_version = 0):
     """Checker for Accelerate framework (on Mac OS X >= 10.3). """
     # According to
@@ -203,29 +282,25 @@
     #    is_intel = 0
     #    cflags.append('-faltivec')
 
-    name    = 'Framework: Accelerate'
-    # XXX: does it make sense to customize mac os X frameworks ?
-    section = 'accelerate'
-    defopts = ConfigOpts(frameworks = ['Accelerate'])
-    headers = ['Accelerate/Accelerate.h']
-    funcs   = ['cblas_sgemm']
-    
-    return _check(context, name, section, defopts, headers, funcs,
-                  check_version, None, autoadd)
+    cfg = _CONFIG['Accelerate']
 
+    return _check(context, cfg.name, cfg.section, cfg.defopts, cfg.headers,
+                  cfg.funcs, check_version, None, autoadd)
+
+IsAccelerate = IsFactory('Accelerate').get_func()
+
 def CheckVeclib(context, autoadd = 1, check_version = 0):
     """Checker for Veclib framework (on Mac OS X < 10.3)."""
-    name    = 'Framework: Accelerate'
-    # XXX: does it make sense to customize mac os X frameworks ?
-    section = 'accelerate'
-    defopts = ConfigOpts(frameworks = ['Accelerate'])
-    headers = ['vecLib/vecLib.h']
-    funcs   = ['cblas_sgemm']
-    
-    return _check(context, name, section, defopts, headers, funcs,
-                  check_version, None, autoadd)
+    cfg = _CONFIG['vecLib']
 
+    return _check(context, cfg.name, cfg.section, cfg.defopts, cfg.headers,
+                  cfg.funcs, check_version, None, autoadd)
 
+IsVeclib = IsFactory('vecLib').get_func()
+
+#-----------------
+# Sunperf checker
+#-----------------
 from os.path import basename, dirname
 from copy import deepcopy
 from numpy.distutils.scons.core.utils import popen_wrapper
@@ -233,16 +308,10 @@
 
 def CheckSunperf(context, autoadd = 1, check_version = 0):
     """Checker for sunperf."""
-    name    = 'Sunperf'
-    section = 'sunperf'
-    # XXX: Other options needed ?
-    defopts = ConfigOpts(cflags = ['-dalign'], linkflags = ['-xlic_lib=sunperf'])
-    headers = ['sunperf.h']
-    funcs   = ['cblas_sgemm']
+    cfg = _CONFIG['vecLib']
     
-    st, res = _check(context, name, section, defopts, headers, funcs,
-                check_version, None, autoadd)
-
+    st, res = _check(context, cfg.name, cfg.section, cfg.defopts, cfg.headers,
+                     cfg.funcs, check_version, None, autoadd)
     if not st:
         return st, res
 
@@ -342,3 +411,5 @@
         t = parse(t)
 
     return keep
+
+IsSunperf = IsFactory('Sunperf').get_func()



More information about the Numpy-svn mailing list