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

numpy-svn@scip... numpy-svn@scip...
Wed Oct 31 05:47:26 CDT 2007


Author: cdavid
Date: 2007-10-31 05:47:18 -0500 (Wed, 31 Oct 2007)
New Revision: 4364

Modified:
   branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
   branches/numpy.scons/numpy/distutils/scons/checkers/support.py
   branches/numpy.scons/numpy/scons_fake/checkers/SConstruct
Log:
Refactor libperf checkers: mostly done

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-10-31 09:48:00 UTC (rev 4363)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-10-31 10:47:18 UTC (rev 4364)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Tue Oct 30 07:00 PM 2007 J
+# Last Change: Wed Oct 31 07:00 PM 2007 J
 
 # Module for custom, common checkers for numpy (and scipy)
 import sys
@@ -49,7 +49,7 @@
             
         else:
             # Check MKL, then ATLAS, then Sunperf
-            st = CheckMKL(context, autoadd)
+            st, opts = CheckMKL(context, autoadd)
             if st:
                 add_info(env, 'cblas', opt_info('mkl'))
                 return st

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-10-31 09:48:00 UTC (rev 4363)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-10-31 10:47:18 UTC (rev 4364)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Wed Oct 31 06:00 PM 2007 J
+# Last Change: Wed Oct 31 07: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
@@ -14,10 +14,17 @@
         c_sgemm as sunperf_src, lapack_sgesv
 
 from support import check_include_and_run, check_symbol
-from support import save_and_set, restore, ConfigOpts
+from support import save_and_set, restore, ConfigOpts, ConfigRes
 
 def _check(context, name, section, defopts, headers_to_check, funcs_to_check, 
            check_version, version_checker, autoadd):
+    """Generic implementation for perflib check.
+
+    This checks for header (by compiling code including them) and symbols in
+    libraries (by linking code calling for given symbols). Optionnaly, it can
+    get the version using some specific function.
+    
+    See CheckATLAS or CheckMKL for examples."""
     context.Message("Checking %s ... " % name)
 
     # Get site.cfg customization if any
@@ -42,7 +49,7 @@
     if not st:
         context.Result('Failed (could not check header(s) : check config.log '\
                        'in %s for more details)' % env['build_dir'])
-        return st, {}
+        return st, ConfigRes(opts, found)
 
     # Check whether the library is available (CheckLib-like checker)
     saved = save_and_set(env, opts)
@@ -59,7 +66,7 @@
     if not st:
         context.Result('Failed (could not check symbol %s : check config.log '\
                        'in %s for more details))' % (sym, env['build_dir']))
-        return st, {}
+        return st, ConfigRes(opts, found)
         
     context.Result(st)
 
@@ -73,233 +80,93 @@
                 version = 'Unknown (checking version failed)'
         else:
             version = 'Unkown (not implemented)'
+        cfgres = ConfigRes(opts, found, version)
+    else:
+        cfgres = ConfigRes(opts, found, version = 'Not checked')
 
-    return st, opts
+    return st, cfgres
 
-def CheckMKL(context, check_version = 0, autoadd = 1):
-    name = 'MKL'
-    section = 'mkl'
-    defopts = ConfigOpts(libs = ['mkl', 'guide', 'm'])
-    headers = ['mkl.h']
-    funcs = ['MKLGetVersion']
-
-    def mkl_version_checker(env, opts):
-        version_code = r"""
+def _check_mkl_version(env, opts):
+    version_code = r"""
 #include <stdio.h>
 #include <mkl.h>
 
 int main(void)
 {
-    MKLVersion ver;
-    MKLGetVersion(&ver);
+MKLVersion ver;
+MKLGetVersion(&ver);
 
-    printf("Full version: %d.%d.%d\n", ver.MajorVersion,
-           ver.MinorVersion,
-           ver.BuildNumber);
+printf("Full version: %d.%d.%d\n", ver.MajorVersion,
+       ver.MinorVersion,
+       ver.BuildNumber);
 
-    return 0;
+return 0;
 }
 """
 
-        opts['rpath'] = libpath
-        saved = save_and_set(env, opts)
-        try:
-            vst, out = context.TryRun(version_code, '.c')
-        finally:
-            restore(env, saved)
+    opts['rpath'] = opts['libpath']
+    saved = save_and_set(env, opts)
+    try:
+        vst, out = context.TryRun(version_code, '.c')
+    finally:
+        restore(env, saved)
 
-        if vst and re.search(r'Full version: (\d+[.]\d+[.]\d+)', out):
+    if vst and re.search(r'Full version: (\d+[.]\d+[.]\d+)', out):
+        version = m.group(1)
+    else:
+        version = ''
+
+    return vst, version
+
+def _atlas_version_checker(env, opts):
+    version_code = """
+void ATL_buildinfo(void);
+int main(void) {
+ATL_buildinfo();
+return 0;
+}
+"""
+    opts['rpath'] = opts['libpath']
+    saved = save_and_set(env, opts)
+    try:
+        vst, out = context.TryRun(version_code, '.c')
+    finally:
+        restore(env, saved)
+
+    if vst:
+        m = re.search('ATLAS version (?P<version>\d+[.]\d+[.]\d+)', out)
+        if m:
             version = m.group(1)
         else:
             version = ''
+    else:
+        version = ''
 
-        return vst, version
+    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)
+                  check_version, _mkl_version_checker, autoadd)
 
-#def CheckMKL(context, check_version = 0, autoadd = 1):
-#    """Check whether mkl is usable in C."""
-#    context.Message("Checking MKL ... ")
-#
-#    # XXX: take into account siteconfig
-#    section = "mkl"
-#    siteconfig, cfgfiles = get_config()
-#    (cpppath, libs, libpath), found = get_config_from_section(siteconfig, section)
-#    if not found:
-#        # XXX: find exact options to use for the MKL
-#        libs.extend(['mkl', 'guide', 'm'])
-#    opts = {'cpppath' : cpppath, 'libpath' : libpath, 'libs' : libs} 
-#
-#    env = context.env
-#    test_funcs = ['MKLGetVersion']
-#    headers = ['mkl.h']
-#
-#    # Check whether the header is available (CheckHeader-like checker)
-#    saved = save_and_set(env, opts)
-#    try:
-#        # XXX: add dep vars in code
-#        src = '\n'.join([r'#include <%s>\n' % h for h in headers])
-#        st = context.TryCompile(src, '.c')
-#    finally:
-#        restore(env, saved)
-#
-#    if not st:
-#        context.Result('Failed (could not check header(s) : check config.log '\
-#                       'in %s for more details)' % env['build_dir'])
-#        return st, opts
-#
-#    # Check whether the library is available (CheckLib-like checker)
-#    saved = save_and_set(env, opts)
-#    try:
-#        for sym in test_funcs:
-#            # XXX: add dep vars in code
-#            st = check_symbol(context, headers, sym)
-#            if not st:
-#                break
-#    finally:
-#        if st == 0 or autoadd == 0:
-#            restore(env, saved)
-#        
-#    if not st:
-#        context.Result('Failed (could not check symbol %s : check config.log in %s for more details))' % (sym, env['build_dir']))
-#        return st, opts
-#        
-#    context.Result(st)
-#
-#    # Check version if requested
-#    if check_version:
-#        version_code = r"""
-##include <stdio.h>
-##include <mkl.h>
-#
-#int main(void)
-#{
-#    MKLVersion ver;
-#    MKLGetVersion(&ver);
-#
-#    printf("Full version: %d.%d.%d\n", ver.MajorVersion,
-#           ver.MinorVersion,
-#           ver.BuildNumber);
-#
-#    return 0;
-#}
-#"""
-#
-#        opts['rpath'] = libpath
-#        saved = save_and_set(env, opts)
-#        try:
-#            vst, out = context.TryRun(version_code, '.c')
-#        finally:
-#            restore(env, saved)
-#
-#        if not vst:
-#            version = r'?.?.? (could not get version)'
-#        else:
-#            m = re.search(r'Full version: (\d+[.]\d+[.]\d+)', out)
-#            if m:
-#                version = m.group(1)
-#            else:
-#                version = r'?.?.? (could not get version)'
-#        opts['version'] = version
-#
-#    return st, opts
-
-def CheckATLAS2(context, check_version = 1, autoadd = 1):
+def CheckATLAS(context, autoadd = 1, check_version = 0):
     """Check whether ATLAS is usable in C."""
     name    = 'ATLAS'
     section = 'atlas'
     defopts = ConfigOpts(libs = ['atlas'])
     headers = ['atlas_enum.h']
     funcs   = ['ATL_sgemm']
+    
     return _check(context, name, section, defopts, headers, funcs,
-                  check_version, None, autoadd)
+                  check_version, _atlas_version_checker, autoadd)
 
-#    context.Message("Checking ATLAS ... ")
-# 
-#    section = "atlas"
-#    siteconfig, cfgfiles = get_config()
-#    (cpppath, libs, libpath), found = get_config_from_section(siteconfig, section)
-#    if not found:
-#        libs.extend(['atlas'])
-#    opts = {'cpppath' : cpppath, 'libpath' : libpath, 'libs' : libs}
-#
-#    env = context.env
-#    test_funcs = ['ATL_sgemm']
-#    headers = ['atlas_enum.h']
-#
-#    # Check whether the header is available (CheckHeader-like checker)
-#    saved = save_and_set(env, opts)
-#    try:
-#        # XXX: add dep vars in code
-#        src = '\n'.join([r'#include <%s>\n' % h for h in headers])
-#        st = context.TryCompile(src, '.c')
-#    finally:
-#        restore(env, saved)
-#
-#    if not st:
-#        context.Result('Failed (could not check header(s))')
-#        return st
-#
-#    # Check whether the library is available (CheckLib-like checker)
-#    saved = save_and_set(env, opts)
-#    try:
-#        for sym in test_funcs:
-#            # XXX: add dep vars in code
-#            st = check_symbol(context, headers, sym)
-#            if not st:
-#                break
-#    finally:
-#        if st == 0 or autoadd == 0:
-#            restore(env, saved)
-#        
-#    if not st:
-#        context.Result('Failed (could not check symbol %s)' % sym)
-#        return st
-#        
-#    context.Result(st)
-#
-#    # Check version if requested
-#    if check_version:
-#        saved = save_and_set(env, opts)
-#        version_code = """
-#void ATL_buildinfo(void);
-#int main(void) {
-#  ATL_buildinfo();
-#  return 0;
-#}
-#"""
-#        try:
-#            vst, out = context.TryRun(version_code, '.c')
-#        finally:
-#            restore(env, saved)
-#
-#        if not vst:
-#            version = r'?.?.? (could not get version)'
-#        else:
-#            m = re.search(
-#                    r'ATLAS version (?P<version>\d+[.]\d+[.]\d+)',
-#                    out)
-#            if m:
-#                version = m.group('version')
-#            else:
-#                version = r'?.?.? (could not get version)'
-#        opts['version'] = version
-#
-#    return st, opts
-
-def CheckATLAS(context, autoadd = 1):
-    """Check whether ATLAS is usable in C."""
-
-    libs = ['atlas', 'f77blas', 'cblas']
-    libpath = []
-
-    return check_include_and_run(context, 'ATLAS', None, ['atlas_enum.h', 'cblas.h'],
-                                  cblas_src, libs, libpath, [], [], autoadd)
-
-def CheckAccelerate(context, autoadd = 1):
-    """Checker for Accelerate framework (on Mac OS X >= 10.3). Only test from
-    C."""
+def CheckAccelerate(context, autoadd = 1, check_version = 0):
+    """Checker for Accelerate framework (on Mac OS X >= 10.3). """
     # According to
     # http://developer.apple.com/hardwaredrivers/ve/vector_libraries.html:
     #
@@ -317,30 +184,37 @@
     #    is_intel = 0
     #    cflags.append('-faltivec')
 
-    # XXX: This double append is not good, any other way ?
-    linkflags = ['-framework', 'Accelerate']
+    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)
 
-    return check_include_and_run(context, 'FRAMEWORK: Accelerate', None, 
-                                  ['Accelerate/Accelerate.h'], cblas_src, [], 
-                                  [], linkflags, [], autoadd)
-
 def CheckVeclib(context, autoadd = 1):
     """Checker for Veclib framework (on Mac OS X < 10.3)."""
-    # XXX: This double append is not good, any other way ?
-    linkflags = ['-framework', 'vecLib']
+    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)
 
-    return check_include_and_run(context, 'FRAMEWORK: veclib', None, 
-                                  ['vecLib/vecLib.h'], cblas_src, [], 
-                                  [], linkflags, [], autoadd)
 
-def CheckSunperf(context, autoadd = 1):
-    """Checker for sunperf using a simple sunperf example"""
-
+def CheckSunperf(context, autoadd = 1, check_version = 0):
+    """Checker for sunperf."""
+    name    = 'Sunperf'
+    section = 'sunperf'
     # XXX: Other options needed ?
-    linkflags = ['-xlic_lib=sunperf']
-    cflags = ['-dalign']
-
-    return check_include_and_run(context, 'sunperf', None, 
-                                  ['sunperf.h'], sunperf_src, [], 
-                                  [], linkflags, cflags, autoadd)
-
+    defopts = ConfigOpts(cflags = ['-dalign'], linkflags = ['-xlic_lib=sunperf'])
+    headers = ['sunperf.h']
+    funcs   = ['cblas_sgemm']
+    
+    return _check(context, name, section, defopts, headers, funcs,
+                  check_version, None, autoadd)

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/support.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/support.py	2007-10-31 09:48:00 UTC (rev 4363)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/support.py	2007-10-31 10:47:18 UTC (rev 4364)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Wed Oct 31 06:00 PM 2007 J
+# Last Change: Wed Oct 31 07:00 PM 2007 J
 
 # This module defines some helper functions, to be used by high level checkers
 
@@ -10,7 +10,8 @@
             'libpath' : 'LIBPATH',
             'libs' : 'LIBS',
             'linkflags' : 'LINKFLAGS',
-            'rpath' : 'RPATH'}
+            'rpath' : 'RPATH',
+            'frameworks' : 'FRAMEWORKS'}
 
 def save_and_set(env, opts):
     """keys given as config opts args."""
@@ -53,9 +54,11 @@
     return context.TryLink('\n'.join(code), '.c')
 
 class ConfigOpts:
-    _keys = ['cpppath', 'cflags', 'libpath', 'libs', 'linkflags', 'rpath']
+    # Any added key should be added as an argument to __init__ 
+    _keys = ['cpppath', 'cflags', 'libpath', 'libs', 'linkflags', 'rpath',
+             'frameworks']
     def __init__(self, cpppath = None, cflags = None, libpath = None, libs = None, 
-                 linkflags = None, rpath = None):
+                 linkflags = None, rpath = None, frameworks = None):
         data = {}
 
         if not cpppath:
@@ -88,6 +91,11 @@
         else:
             data['rpath'] = rpath
 
+        if not frameworks:
+            data['frameworks'] = []
+        else:
+            data['frameworks'] = frameworks
+
         self.data = data
 
     def __getitem__(self, key):
@@ -101,9 +109,30 @@
         return '\n'.join(msg)
 
 class ConfigRes():
-    def __init__(self, cfgopts, version, origin):
-        pass
+    def __init__(self, cfgopts, origin, version = None):
+        self.data = cfgopts.data
+        self.origin = origin
+        self.version = version
 
+    def __getitem__(self, key):
+        return self.data[key]
+
+    def __setitem__(self, key, item):
+        self.data[key] = item
+
+    def is_customized(self):
+        return bool(self.origin)
+
+    def __repr__(self):
+        if self.is_customized():
+            msg = ['Customized items site.cfg:']
+        else:
+            msg = ['Using default configuration:']
+
+        msg += ['\t%s : %s' % (k, i) for k, i in self.data.items() if len(i) > 0]
+        msg += ['Version is : %s' % self.version]
+        return '\n'.join(msg)
+
 def check_include_and_run(context, name, cpppath, headers, run_src, libs,
                           libpath, linkflags, cflags, autoadd = 1):
     """This is a basic implementation for generic "test include and run"

Modified: branches/numpy.scons/numpy/scons_fake/checkers/SConstruct
===================================================================
--- branches/numpy.scons/numpy/scons_fake/checkers/SConstruct	2007-10-31 09:48:00 UTC (rev 4363)
+++ branches/numpy.scons/numpy/scons_fake/checkers/SConstruct	2007-10-31 10:47:18 UTC (rev 4364)
@@ -1,7 +1,7 @@
 # vim:syntax=python
 from numpy.distutils.scons import GetNumpyEnvironment
 from numpy.distutils.scons.checkers.perflib import \
-        CheckATLAS, CheckAccelerate, CheckMKL, CheckSunperf, CheckATLAS2
+        CheckATLAS, CheckAccelerate, CheckMKL, CheckSunperf
 
 env = GetNumpyEnvironment(ARGUMENTS)
 
@@ -14,21 +14,21 @@
 
 config = env.NumpyConfigure(custom_tests = 
     {'CheckATLAS' : CheckATLAS,
-    'CheckATLAS2' : CheckATLAS2,
     'CheckMKL' : CheckMKL,
     'CheckAccelerate' : CheckAccelerate,
     'CheckSunperf' : CheckSunperf})
 
 if do_check:
-    #config.CheckATLAS(autoadd = 0)
-    st, opts = config.CheckATLAS2(autoadd = 0)
+    st, opts = config.CheckATLAS(autoadd = 0)
     if st:
         print opts
     st, opts = config.CheckMKL(autoadd = 0)
     if st:
         print opts
-   # config.CheckAccelerate(autoadd = 0)
-   # config.CheckSunperf(autoadd = 0)
+    st, opts = config.CheckAccelerate(autoadd = 0)
+    if st:
+        print opts
+    st, opts = config.CheckSunperf(autoadd = 0)
 
     if env.has_key('LIBS'):
         print env.Dump('LIBS')



More information about the Numpy-svn mailing list