[Numpy-svn] r4320 - in branches/numpy.scons/numpy: core distutils/scons

numpy-svn@scip... numpy-svn@scip...
Sun Oct 28 23:21:16 CDT 2007


Author: cdavid
Date: 2007-10-28 23:21:06 -0500 (Sun, 28 Oct 2007)
New Revision: 4320

Modified:
   branches/numpy.scons/numpy/core/SConstruct
   branches/numpy.scons/numpy/distutils/scons/__init__.py
   branches/numpy.scons/numpy/distutils/scons/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/libinfo.py
   branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py
Log:
Generic BLAS and LAPACK checkers.

Modified: branches/numpy.scons/numpy/core/SConstruct
===================================================================
--- branches/numpy.scons/numpy/core/SConstruct	2007-10-29 01:07:46 UTC (rev 4319)
+++ branches/numpy.scons/numpy/core/SConstruct	2007-10-29 04:21:06 UTC (rev 4320)
@@ -1,4 +1,4 @@
-# Last Change: Fri Oct 26 02:00 PM 2007 J
+# Last Change: Mon Oct 29 01:00 PM 2007 J
 # vim:syntax=python
 import os
 import sys
@@ -8,7 +8,7 @@
 from numpy.distutils.scons import get_python_inc, get_pythonlib_dir
 from numpy.distutils.scons import GetNumpyEnvironment
 from numpy.distutils.scons import NumpyCheckLib
-from numpy.distutils.scons.custom_checkers import CheckCBLAS, CheckMKL, CheckATLAS
+from numpy.distutils.scons.custom_checkers import CheckCBLAS, CheckMKL, CheckATLAS, CheckGenericBLAS, CheckGenericLAPACK
 
 from scons_support import CheckBrokenMathlib, define_no_smp, \
     generate_config_header, generate_config_header_emitter, \
@@ -29,6 +29,8 @@
 config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib,
     'CheckMathlib' : CheckMathlib, 
     'CheckCBLAS' : CheckCBLAS, 
+    'CheckGenericBLAS' : CheckGenericBLAS, 
+    'CheckGenericLAPACK' : CheckGenericLAPACK, 
     'NumpyCheckLib' : NumpyCheckLib})
 
 # Convention: list of tuples (definition, value). value:
@@ -139,6 +141,9 @@
 #--------------
 # Checking Blas
 #--------------
+config.CheckGenericBLAS()
+config.CheckGenericLAPACK()
+
 # TODO
 if config.CheckCBLAS():
     build_blasdot = 1

Modified: branches/numpy.scons/numpy/distutils/scons/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-10-29 01:07:46 UTC (rev 4319)
+++ branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-10-29 04:21:06 UTC (rev 4320)
@@ -3,7 +3,7 @@
 from libinfo import get_paths as scons_get_paths
 from custom_checkers import CheckMKL, CheckATLAS, CheckCBLAS, \
         CheckAccelerate, CheckMKL, CheckSunperf, CheckLAPACK, \
-        CheckNetlibBLAS, CheckNetlibLAPACK
+        CheckGenericBLAS, CheckGenericLAPACK
 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-29 01:07:46 UTC (rev 4319)
+++ branches/numpy.scons/numpy/distutils/scons/custom_checkers.py	2007-10-29 04:21:06 UTC (rev 4320)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Fri Oct 26 09:00 PM 2007 J
+# Last Change: Mon Oct 29 01:00 PM 2007 J
 
 # Module for custom, common checkers for numpy (and scipy)
 import sys
@@ -7,7 +7,7 @@
 from copy import deepcopy
 from distutils.util import get_platform
 
-from libinfo import get_config, get_config_from_section
+from libinfo import get_config, get_config_from_section, get_func_link_src
 from libinfo_scons import NumpyCheckLib
 from testcode_snippets import cblas_sgemm as cblas_src, \
         c_sgemm as sunperf_src, lapack_sgesv
@@ -210,6 +210,7 @@
         return 0
     else:
         # Get fortran stuff
+        # XXX: do not check if env variables are already here
         if not CheckF77Mangling(context):
             return 0
         if not CheckF77Clib(context):
@@ -250,20 +251,60 @@
 
     return 0
 
-def CheckNetlibBLAS(context):
+def _my_try_link(context, src, libs, libpath, autoadd = 0):
+    """Try to link the given text in src with libs and libpath."""
+    env = context.env
+
+    oldLIBS = (env.has_key('LIBS') and deepcopy(env['LIBS'])) or []
+    oldLIBPATH = (env.has_key('LIBPATH') and deepcopy(env['LIBPATH'])) or []
+
+    ret = 0
+    try:
+        env.AppendUnique(LIBS = libs, LIBPATH = libpath)
+        ret = context.TryLink(src, '.c')
+    finally:
+        if not ret or not autoadd:
+            env.Replace(LIBS = oldLIBS, LIBPATH = oldLIBPATH)
+
+    return ret
+
+def CheckGenericBLAS(context):
     # XXX: support site.cfg
+    libs = ['blas']
+    libpath = []
+
+    env = context.env
     # Get fortran mangling
-    if not CheckF77Mangling(context):
-        return 0
+    if not env.has_key('F77_NAME_MANGLER'):
+        if not CheckF77Mangling(context):
+            return 0
 
-    env = context.env
     test_func_name = env['F77_NAME_MANGLER']('dgemm')
 
-def CheckNetlibLAPACK(context):
+    src = get_func_link_src(test_func_name)
+    context.Message("Checking for Generic BLAS... ")
+    st =  _my_try_link(context, src, libs, libpath, 0)
+    context.Result(st)
+
+    return st
+
+def CheckGenericLAPACK(context):
     # XXX: support site.cfg
+    libs = ['lapack']
+    libpath = []
+
+    env = context.env
     # Get fortran mangling
-    if not CheckF77Mangling(context):
-        return 0
+    if not env.has_key('F77_NAME_MANGLER'):
+        if not CheckF77Mangling(context):
+            return 0
 
-    env = context.env
     test_func_name = env['F77_NAME_MANGLER']('dpotri')
+
+    src = get_func_link_src(test_func_name)
+    context.Message("Checking for Generic LAPACK... ")
+    st =  _my_try_link(context, src, libs, libpath, 0)
+    context.Result(st)
+
+    return st
+

Modified: branches/numpy.scons/numpy/distutils/scons/libinfo.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/libinfo.py	2007-10-29 01:07:46 UTC (rev 4319)
+++ branches/numpy.scons/numpy/distutils/scons/libinfo.py	2007-10-29 04:21:06 UTC (rev 4320)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Fri Oct 26 11:00 AM 2007 J
+# Last Change: Mon Oct 29 12:00 PM 2007 J
 
 # Module for support to look for external code (replacement of
 # numpy.distutils.system_info). KEEP THIS INDEPENDANT OF SCONS !
@@ -86,5 +86,31 @@
     else:
         return ([], [], []), 0
 
+def get_func_link_src(func, includes = None):
+    """Given a function, return the source code to compile and link to
+    test for this symbol.
+    
+    includes is a list of (optional) headers"""
+    src = []
+    if includes:
+        src.extend([r'#include <%s>\n' for h in includes])
+
+    src.append(r"""
+#undef %(func)s
+
+#ifdef __cplusplus
+extern "C"
+#endif
+char %(func)s ();
+
+int
+main ()
+{
+    return %(func)s();
+}
+""" % {'func' : func})
+
+    return '\n'.join(src)
+
 if __name__ == '__main__':
     pass

Modified: branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py	2007-10-29 01:07:46 UTC (rev 4319)
+++ branches/numpy.scons/numpy/distutils/scons/testcode_snippets.py	2007-10-29 04:21:06 UTC (rev 4320)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Fri Oct 26 08:00 PM 2007 J
+# Last Change: Mon Oct 29 12: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



More information about the Numpy-svn mailing list