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

numpy-svn@scip... numpy-svn@scip...
Mon Nov 5 22:39:54 CST 2007


Author: cdavid
Date: 2007-11-05 22:39:41 -0600 (Mon, 05 Nov 2007)
New Revision: 4398

Modified:
   branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/checkers/support.py
   branches/numpy.scons/numpy/scons_fake/checkers/SConstruct
   branches/numpy.scons/test.sh
Log:
Refactor check_include_and_run to use ConfigOpts

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-11-06 04:19:29 UTC (rev 4397)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-11-06 04:39:41 UTC (rev 4398)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Mon Nov 05 07:00 PM 2007 J
+# Last Change: Tue Nov 06 01:00 PM 2007 J
 
 # Module for custom, common checkers for numpy (and scipy)
 import sys
@@ -18,6 +18,15 @@
 from support import check_include_and_run
 
 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 ?
     env = context.env
 
     # If section cblas is in site.cfg, use those options. Otherwise, use default
@@ -37,31 +46,52 @@
             return st
     else:
         if sys.platform == 'darwin':
-            st, opts = CheckAccelerate(context, autoadd)
+            st, res = CheckAccelerate(context, autoadd)
             if st:
-                add_info(env, 'cblas', opts)
+                st = check_include_and_run(context, 'CBLAS (Accelerate Framework)', 
+                                           res.cfgopts, ['cblas.h'], cblas_src, autoadd)
+                if st:
+                    add_info(env, 'cblas', res)
                 return st
-            st, opts = CheckVeclib(context, autoadd)
+
+            st, res = CheckVeclib(context, autoadd)
             if st:
-                add_info(env, 'cblas', opt_info('vecLib'))
+                st = check_include_and_run(context, 'CBLAS (vecLib Framework)', 
+                                           res.cfgopts, ['cblas.h'], cblas_src, autoadd)
+                if st:
+                    add_info(env, 'cblas', res)
                 return st
 
             add_info(env, 'cblas', 'Def numpy implementation used')
             return 0
             
         else:
-            # Check MKL, then ATLAS, then Sunperf
-            st, opts = CheckMKL(context, autoadd)
+            # XXX: think about how to share headers info between checkers ?
+            # Check MKL
+            st, res = CheckMKL(context, autoadd)
             if st:
-                add_info(env, 'cblas', opts)
+                st = check_include_and_run(context, 'CBLAS (MKL)', res.cfgopts,
+                                           [], cblas_src, autoadd)
+                if st:
+                    add_info(env, 'cblas', res)
                 return st
-            st, opts = CheckATLAS(context, autoadd)
+
+            # Check ATLAS
+            st, res = CheckATLAS(context, autoadd)
             if st:
-                add_info(env, 'cblas', opts)
+                st = check_include_and_run(context, 'CBLAS (ATLAS)', res.cfgopts,
+                                           ['cblas.h'], cblas_src, autoadd)
+                if st:
+                    add_info(env, 'cblas', res)
                 return st
-            st, opts = CheckSunperf(context, autoadd)
+
+            # Check Sunperf
+            st, res = CheckSunperf(context, autoadd)
             if st:
-                add_info(env, 'cblas', opts)
+                st = check_include_and_run(context, 'CBLAS (Sunperf)', res.cfgopts,
+                                           ['sunperf.h'], cblas_src, autoadd)
+                if st:
+                    add_info(env, 'cblas', res)
                 return st
 
             add_info(env, 'cblas', 'Def numpy implementation used')

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/support.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/support.py	2007-11-06 04:19:29 UTC (rev 4397)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/support.py	2007-11-06 04:39:41 UTC (rev 4398)
@@ -1,10 +1,12 @@
 #! /usr/bin/env python
-# Last Change: Mon Nov 05 05:00 PM 2007 J
+# Last Change: Tue Nov 06 01:00 PM 2007 J
 
 # This module defines some helper functions, to be used by high level checkers
 
 from copy import deepcopy
 
+# Tools to save and restore environments construction variables (the ones often
+# altered for configuration tests)
 _arg2env = {'cpppath' : 'CPPPATH',
             'cflags' : 'CFLAGS',
             'libpath' : 'LIBPATH',
@@ -33,26 +35,6 @@
     kw = dict(kw)
     env.Replace(**kw)
 
-def check_symbol(context, headers, sym, extra = r''):
-    # XXX: add dep vars in code
-    #code = [r'#include <%s>' %h for h in headers]
-    code = []
-    code.append(r'''
-#undef %(func)s
-#ifdef __cplusplus
-extern "C" 
-#endif
-char %(func)s();
-
-int main()
-{
-return %(func)s();
-return 0;
-}
-''' % {'func' : sym})
-    code.append(extra)
-    return context.TryLink('\n'.join(code), '.c')
-
 class ConfigOpts:
     # Any added key should be added as an argument to __init__ 
     _keys = ['cpppath', 'cflags', 'libpath', 'libs', 'linkflags', 'rpath',
@@ -108,18 +90,39 @@
         msg = [r'%s : %s' % (k, i) for k, i in self.data.items()]
         return '\n'.join(msg)
 
+# Implementation function to check symbol in a library
+def check_symbol(context, headers, sym, extra = r''):
+    # XXX: add dep vars in code
+    #code = [r'#include <%s>' %h for h in headers]
+    code = []
+    code.append(r'''
+#undef %(func)s
+#ifdef __cplusplus
+extern "C" 
+#endif
+char %(func)s();
+
+int main()
+{
+return %(func)s();
+return 0;
+}
+''' % {'func' : sym})
+    code.append(extra)
+    return context.TryLink('\n'.join(code), '.c')
+
 class ConfigRes:
     def __init__(self, name, cfgopts, origin, version = None):
         self.name = name
-        self.data = cfgopts.data
+        self.cfgopts = cfgopts
         self.origin = origin
         self.version = version
 
     def __getitem__(self, key):
-        return self.data[key]
+        return self.cfgopts.data[key]
 
     def __setitem__(self, key, item):
-        self.data[key] = item
+        self.cfgopts.data[key] = item
 
     def is_customized(self):
         return bool(self.origin)
@@ -131,7 +134,7 @@
         else:
             msg += ['  Using default configuration:']
 
-        msg += ['  %s : %s' % (k, i) for k, i in self.data.items() if len(i) > 0]
+        msg += ['  %s : %s' % (k, i) for k, i in self.cfgopts.data.items() if len(i) > 0]
         msg += ['  Version is : %s' % self.version]
         return '\n'.join(msg)
 
@@ -161,12 +164,10 @@
     if ret == 0 or autoadd == 0:         
         env.Replace(CPPPATH = oldCPPPATH)        
         env.Replace(CFLAGS = oldCFLAGS)          
-        return 0         
         
     return ret 
 
-def check_include_and_run(context, name, cpppath, headers, run_src, libs,
-                          libpath, linkflags, cflags, autoadd = 1):
+def check_include_and_run(context, name, opts, headers, run_src, autoadd = 1):
     """This is a basic implementation for generic "test include and run"
     testers.
     
@@ -188,36 +189,29 @@
     context.Message('Checking for %s ... ' % name)
     env = context.env
 
-    ret = _check_headers(context, cpppath, cflags, headers, autoadd)
+    ret = _check_headers(context, opts['cpppath'], opts['cflags'], headers, 
+                         autoadd)
     if not ret:
-         context.Result('Failed: %s include not found' % name)
+        context.Result('Failed: %s include not found' % name)
+        return 0
 
     #------------------------------
     # Check a simple example works
     #------------------------------
-    oldLIBPATH = (env.has_key('LIBPATH') and deepcopy(env['LIBPATH'])) or []
-    oldLIBS = (env.has_key('LIBS') and deepcopy(env['LIBS'])) or []
-    # XXX: RPATH, drawbacks using it ?
-    oldRPATH = (env.has_key('RPATH') and deepcopy(env['RPATH'])) or []
-    oldLINKFLAGS = (env.has_key('LINKFLAGS') and deepcopy(env['LINKFLAGS'])) or []
-    env.AppendUnique(LIBPATH = libpath)
-    env.AppendUnique(LIBS = libs)
-    env.AppendUnique(RPATH = libpath)
-    env.AppendUnique(LINKFLAGS = linkflags)
+    saved = save_and_set(env, opts)
+    try:
+        # XXX: reenable this
+        ## HACK: we add libpath and libs at the end of the source as a comment, to
+        ## add dependency of the check on those.
+        #src = '\n'.join(['#include <%s>' % h for h in headers] +\
+        #                [run_src, '#if 0', '%s' % libpath, 
+        #                 '%s' % headers, '%s' % libs, '#endif'])
+        ret = context.TryRun(src, '.c')
+    except:
+        if (not ret or not autoadd):
+            # If test failed or autoadd is disabled, restore everything
+            restore(env, saved)
 
-    # HACK: we add libpath and libs at the end of the source as a comment, to
-    # add dependency of the check on those.
-    src = '\n'.join(['#include <%s>' % h for h in headers] +\
-                    [run_src, '#if 0', '%s' % libpath, 
-                     '%s' % headers, '%s' % libs, '#endif'])
-    ret = context.TryLink(src, '.c')
-    if (not ret or not autoadd):
-        # If test failed or autoadd = 0, restore everything
-        env.Replace(LIBS = oldLIBS)
-        env.Replace(LIBPATH = oldLIBPATH)
-        env.Replace(RPATH = oldRPATH)
-        env.Replace(LINKFLAGS = oldLINKFLAGS)
-
     if not ret:
         context.Result('Failed: %s test could not be linked and run' % name)
         return 0

Modified: branches/numpy.scons/numpy/scons_fake/checkers/SConstruct
===================================================================
--- branches/numpy.scons/numpy/scons_fake/checkers/SConstruct	2007-11-06 04:19:29 UTC (rev 4397)
+++ branches/numpy.scons/numpy/scons_fake/checkers/SConstruct	2007-11-06 04:39:41 UTC (rev 4398)
@@ -2,6 +2,7 @@
 from numpy.distutils.scons import GetNumpyEnvironment
 from numpy.distutils.scons.checkers.perflib import \
         CheckATLAS, CheckAccelerate, CheckMKL, CheckSunperf
+from numpy.distutils.scons.checkers.custom_checkers import CheckCBLAS
 
 env = GetNumpyEnvironment(ARGUMENTS)
 
@@ -16,6 +17,7 @@
     {'CheckATLAS' : CheckATLAS,
     'CheckMKL' : CheckMKL,
     'CheckAccelerate' : CheckAccelerate,
+    'CheckCBLAS' : CheckCBLAS,
     'CheckSunperf' : CheckSunperf})
 
 do_check = 1
@@ -30,9 +32,12 @@
     if st:
         print opts
     st, opts = config.CheckSunperf(autoadd = 0)
+    if st:
+        print opts
+    st = config.CheckCBLAS(autoadd = 0)
 
     if env.has_key('LIBS'):
-        print env.Dump('LIBS')
+        print "LIBS of env is %s" % env.Dump('LIBS')
     else:
         print "No LIBS in env"
 

Modified: branches/numpy.scons/test.sh
===================================================================
--- branches/numpy.scons/test.sh	2007-11-06 04:19:29 UTC (rev 4397)
+++ branches/numpy.scons/test.sh	2007-11-06 04:39:41 UTC (rev 4398)
@@ -1,5 +1,5 @@
 PREFIX=$PWD
 rm -rf $PREFIX/build
 rm -rf $PREFIX/tmp
-python setup.py scons --jobs=4 install --prefix=$PREFIX/tmp
+MKL=None python setup.py scons --jobs=4 install --prefix=$PREFIX/tmp
 (cd $PREFIX/tmp && PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python -c "import numpy; print numpy; numpy.test(level = 9999)")



More information about the Numpy-svn mailing list