[Numpy-svn] r4310 - in branches/numpy.scons/numpy: distutils/scons linalg

numpy-svn@scip... numpy-svn@scip...
Fri Oct 26 07:29:28 CDT 2007


Author: cdavid
Date: 2007-10-26 07:29:20 -0500 (Fri, 26 Oct 2007)
New Revision: 4310

Modified:
   branches/numpy.scons/numpy/distutils/scons/__init__.py
   branches/numpy.scons/numpy/distutils/scons/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/fortran_scons.py
   branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py
   branches/numpy.scons/numpy/linalg/SConstruct
Log:
Add preliminary LAPACK checker, used in linalg

Modified: branches/numpy.scons/numpy/distutils/scons/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-10-26 09:20:16 UTC (rev 4309)
+++ branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-10-26 12:29:20 UTC (rev 4310)
@@ -2,7 +2,7 @@
 from libinfo_scons import NumpyCheckLib
 from libinfo import get_paths as scons_get_paths
 from custom_checkers import CheckMKL, CheckATLAS, CheckCBLAS, \
-        CheckAccelerate, CheckMKL, CheckSunperf
+        CheckAccelerate, CheckMKL, CheckSunperf, CheckLAPACK
 from extension import get_python_inc, get_pythonlib_dir
 from utils import isstring
 from fortran_scons import CheckF77Verbose, CheckF77Clib, CheckF77Mangling

Modified: branches/numpy.scons/numpy/distutils/scons/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/custom_checkers.py	2007-10-26 09:20:16 UTC (rev 4309)
+++ branches/numpy.scons/numpy/distutils/scons/custom_checkers.py	2007-10-26 12:29:20 UTC (rev 4310)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Fri Oct 26 02:00 PM 2007 J
+# Last Change: Fri Oct 26 09:00 PM 2007 J
 
 # Module for custom, common checkers for numpy (and scipy)
 import sys
@@ -9,8 +9,11 @@
 
 from libinfo import get_config, get_config_from_section
 from libinfo_scons import NumpyCheckLib
-from testcode_snippets import cblas_sgemm as cblas_src, c_sgemm as sunperf_src
+from testcode_snippets import cblas_sgemm as cblas_src, \
+        c_sgemm as sunperf_src, lapack_sgesv
 
+from fortran_scons import CheckF77Mangling, CheckF77Clib
+
 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"
@@ -38,8 +41,8 @@
     #----------------------------
     oldCPPPATH = (env.has_key('CPPPATH') and deepcopy(env['CPPPATH'])) or []
     oldCFLAGS = (env.has_key('CFLAGS') and deepcopy(env['CFLAGS'])) or []
-    env.Append(CPPPATH = cpppath)
-    env.Append(CFLAGS = cflags)
+    env.AppendUnique(CPPPATH = cpppath)
+    env.AppendUnique(CFLAGS = cflags)
     # XXX: handle context
     hcode = ['#include <%s>' % h for h in headers]
     # HACK: we add cpppath in the command of the source, to add dependency of
@@ -62,10 +65,10 @@
     # 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.Append(LIBPATH = libpath)
-    env.Append(LIBS = libs)
-    env.Append(RPATH = libpath)
-    env.Append(LINKFLAGS = linkflags)
+    env.AppendUnique(LIBPATH = libpath)
+    env.AppendUnique(LIBS = libs)
+    env.AppendUnique(RPATH = libpath)
+    env.AppendUnique(LINKFLAGS = linkflags)
 
     # HACK: we add libpath and libs at the end of the source as a comment, to
     # add dependency of the check on those.
@@ -103,6 +106,9 @@
     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(['lapack', 'mkl', 'guide', 'm'])
     headers = ['mkl.h']
 
     return _check_include_and_run(context, 'MKL', cpppath, headers,
@@ -194,3 +200,52 @@
                 return st
             st = CheckSunperf(context, autoadd)
             return st
+
+def CheckLAPACK(context, autoadd = 1):
+    # XXX: this whole thing is ugly. Think more about how to combine checkers
+    # in 'meta checker' like this.
+    if sys.platform == 'nt':
+        import warnings
+        warning.warn('FIXME: LAPACK checks not implemented yet on win32')
+        return 0
+    else:
+        # Get fortran stuff
+        if not CheckF77Mangling(context):
+            return 0
+        if not CheckF77Clib(context):
+            return 0
+
+        env = context.env
+
+        # Get the mangled name of our test function
+        sgesv_string = env['F77_NAME_MANGLER']('sgesv')
+        test_src = lapack_sgesv % sgesv_string
+
+        # Check MKL
+        st = CheckMKL(context, autoadd)
+        if st:
+            fdict = env.ParseFlags(context.env['F77_LDFLAGS'])
+            fdict['LIBS'].append('lapack')
+            if env.has_key('LIBS'):
+                fdict['LIBS'].extend(context.env['LIBS'])
+            if env.has_key('LIBPATH'):
+                fdict['LIBPATH'].extend(context.env['LIBPATH'])
+            st =_check_include_and_run(context, 'LAPACK (MKL)', [], [],
+                    test_src, fdict['LIBS'], fdict['LIBPATH'], [], [], autoadd = 1)
+            return st
+
+        # Check ATLAS
+        st = CheckATLAS(context, autoadd)
+        if st:
+            fdict = env.ParseFlags(context.env['F77_LDFLAGS'])
+            fdict['LIBS'].append('lapack')
+            if env.has_key('LIBS'):
+                fdict['LIBS'].extend(context.env['LIBS'])
+            if env.has_key('LIBPATH'):
+                fdict['LIBPATH'].extend(context.env['LIBPATH'])
+            st =_check_include_and_run(context, 'LAPACK (ATLAS)', [], [],
+                    test_src, fdict['LIBS'], fdict['LIBPATH'], [], [], autoadd = 1)
+            # XXX: Check complete LAPACK or not
+            return st
+
+    return 0

Modified: branches/numpy.scons/numpy/distutils/scons/fortran_scons.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/fortran_scons.py	2007-10-26 09:20:16 UTC (rev 4309)
+++ branches/numpy.scons/numpy/distutils/scons/fortran_scons.py	2007-10-26 12:29:20 UTC (rev 4310)
@@ -221,6 +221,10 @@
     return result, mangler, u, du, c
 
 def CheckF77Mangling(context):
+    """Find mangling of the F77 compiler.
+    
+    If sucessfull, env['F77_NAME_MANGLER'] is a function which given the C
+    name, returns the F77 name as seen by the linker."""
     env = context.env
     if not env.has_key('F77_DUMMY_MAIN'):
         CheckF77DummyMain(context)

Modified: branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py	2007-10-26 09:20:16 UTC (rev 4309)
+++ branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py	2007-10-26 12:29:20 UTC (rev 4310)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Thu Oct 25 01:00 PM 2007 J
+# Last Change: Fri Oct 26 08:00 PM 2007 J
 
 # This module should contains useful test code (as strings). They are mainly
 # useful for checkers who need to run the tests (to check the mere presence of
@@ -63,3 +63,43 @@
     return 0;  
 }
 """
+
+# Code which try sgesv (the exact symbol has to be given by lapack_sgsev % symbol)
+lapack_sgesv = r"""
+#define our_fancy_func %s
+
+extern int our_fancy_func(int *n, int *nrhs, float a[], int *lda, int ipiv[], 
+                  float b[], int *ldb, int *info);
+
+int compare(float A[], float B[], int sz)
+{
+        int i;
+
+        for(i = 0; i < sz; ++i) {
+                if ( (A[i] - B[i] > 0.01) || (A[i] - B[i] < -0.01)) {
+                        return -1;
+                }
+        }
+        return 0;
+}
+
+int main(void)
+{
+    int n = 2;
+    int nrhs = 2;
+    int lda = 2;
+    float A[] = { 1, 3, 2, 4};
+
+    int ldb = 2;
+    float B[] = { 1, 0, 0, 1};
+    float X[] = { -2, 1.5, 1, -0.5};
+
+    int ipov[] = {0, 0};
+    int info;
+
+    /* Compute X in A * X = B */
+    our_fancy_func(&n, &nrhs, A, &lda, ipov, B, &ldb, &info);
+
+    return compare(B, X, 4);
+}
+"""

Modified: branches/numpy.scons/numpy/linalg/SConstruct
===================================================================
--- branches/numpy.scons/numpy/linalg/SConstruct	2007-10-26 09:20:16 UTC (rev 4309)
+++ branches/numpy.scons/numpy/linalg/SConstruct	2007-10-26 12:29:20 UTC (rev 4310)
@@ -1,19 +1,30 @@
-# Last Change: Fri Oct 26 05:00 PM 2007 J
+# Last Change: Fri Oct 26 09:00 PM 2007 J
 # vim:syntax=python
-from numpy.distutils.misc_util import get_numpy_include_dirs
+from numpy.distutils.misc_util import get_numpy_include_dirs, get_mathlibs
 from numpy.distutils.scons import GetNumpyEnvironment, scons_get_paths
-from numpy.distutils.scons import CheckF77Mangling
+from numpy.distutils.scons import CheckLAPACK
 
 env = GetNumpyEnvironment(ARGUMENTS)
 env.Append(CPPPATH = scons_get_paths(env['include_bootstrap']))
 
 config = env.NumpyConfigure(custom_tests = 
-    {'CheckF77Mangling' : CheckF77Mangling})
+    {'CheckLAPACK' : CheckLAPACK})
 
-config.CheckF77Mangling()
+# XXX: this is ugly, better find the mathlibs with a checker 
+for i in scons_get_paths(env['include_bootstrap']):
+    try:
+        mlib =  get_mathlibs(i)
+        break
+    except IOError:
+        pass
+env.AppendUnique(LIBS = mlib)
+
+use_lapack = config.CheckLAPACK()
 config.Finish()
 
-sources = ['lapack_litemodule.c', 'zlapack_lite.c', 'dlapack_lite.c',
-          'blas_lite.c', 'dlamch.c', 'f2c_lite.c']
+sources = ['lapack_litemodule.c']
+if not use_lapack:
+    sources.extend(['zlapack_lite.c', 'dlapack_lite.c', 'blas_lite.c',
+                    'dlamch.c', 'f2c_lite.c'])
 lapack_lite = env.NumpyPythonExtension('lapack_lite', source = sources)
             



More information about the Numpy-svn mailing list