[Numpy-discussion] Embedded NumPy LAPACK errors

Robin robince@gmail....
Tue Jan 8 08:06:17 CST 2013


On Sat, Jan 5, 2013 at 1:03 PM, Robin <robince@gmail.com> wrote:
>>> If not, is there a reasonable way to build numpy.linalg such that
>>> it interfaces with MKL correctly ?

I managed to get this to work in the end. Since Matlab uses MKL with
ILP64 interface it is not possible to get Numpy to use that without
modifications to all the lapack calls. However, I was able to keep the
two different versions of lapack seperate.

The first step is to build numpy to link statically against MKL. I
wasn't sure how to get distutils to do this so I copied all the mkl
static .a libaries to a temporary directory and pointed numpy to that
to force the issue (so dynamic linking wasn't an option).

Even with that it still uses the Lapack from the Matlab dynamic global
symbols. The trick was adding the linker flag "-Bsymbolic" which means
lapack_lite calls to lapack use the statically linked local copies.
With these changes everything appears to work. There are two test
failures (below) which do not appear when running the same Numpy build
outside of Matlab but they don't seem so severe.

So:
[robini@robini2-pc numpy]$ cat site.cfg
[mkl]
search_static_first = true
library_dirs = /tmp/intel64
include_dirs = /opt/intel/mkl/include
#mkl_libs = mkl_sequential, mkl_intel_lp64, mkl_core,
mkl_lapack95_lp64, mkl_blas95_lp64
mkl_libs = mkl_lapack95, mkl_blas95, mkl_intel_lp64, mkl_sequential,
mkl_core, svml, imf, irc
lapack_libs =

[robini@robini2-pc numpy]$ ls /tmp/intel64/
libimf.a                       libmkl_gnu_thread.a
libirc.a                       libmkl_intel_ilp64.a
libmkl_blacs_ilp64.a           libmkl_intel_lp64.a
libmkl_blacs_intelmpi_ilp64.a  libmkl_intel_sp2dp.a
libmkl_blacs_intelmpi_lp64.a   libmkl_intel_thread.a
libmkl_blacs_lp64.a            libmkl_lapack95_ilp64.a
libmkl_blacs_openmpi_ilp64.a   libmkl_lapack95_lp64.a
libmkl_blacs_openmpi_lp64.a    libmkl_pgi_thread.a
libmkl_blacs_sgimpt_ilp64.a    libmkl_scalapack_ilp64.a
libmkl_blacs_sgimpt_lp64.a     libmkl_scalapack_lp64.a
libmkl_blas95_ilp64.a          libmkl_sequential.a
libmkl_blas95_lp64.a           libmkl_solver_ilp64.a
libmkl_cdft_core.a             libmkl_solver_ilp64_sequential.a
libmkl_core.a                  libmkl_solver_lp64.a
libmkl_gf_ilp64.a              libmkl_solver_lp64_sequential.a
libmkl_gf_lp64.a               libsvml.a

in numpy/distutils/intelccompiler.py:
class IntelEM64TCCompiler(UnixCCompiler):
    """ A modified Intel x86_64 compiler compatible with a 64bit gcc
built Python.
    """
    compiler_type = 'intelem'
    cc_exe = 'icc -m64 -fPIC'
    cc_args = "-fPIC"
    def __init__ (self, verbose=0, dry_run=0, force=0):
        UnixCCompiler.__init__ (self, verbose,dry_run, force)
        self.cc_exe = 'icc -m64 -fPIC -O3 -fomit-frame-pointer'
        compiler = self.cc_exe
        self.set_executables(compiler=compiler,
                             compiler_so=compiler,
                             compiler_cxx=compiler,
                             linker_exe=compiler,
                             linker_so=compiler + ' -shared
-static-intel -Bsymbolic')

Test failures (test_special_values also fails outside Matlab, but the
other 2 only occur when embedded):
======================================================================
FAIL: test_umath.test_nextafterl
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/epd-7.3/lib/python2.7/site-packages/nose/case.py", line
197, in runTest
    self.test(*self.arg)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/testing/decorators.py",
line 215, in knownfailer
    return f(*args, **kwargs)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/core/tests/test_umath.py",
line 1123, in test_nextafterl
    return _test_nextafter(np.longdouble)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/core/tests/test_umath.py",
line 1108, in _test_nextafter
    assert np.nextafter(one, two) - one == eps
AssertionError

======================================================================
FAIL: test_umath.test_spacingl
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/epd-7.3/lib/python2.7/site-packages/nose/case.py", line
197, in runTest
    self.test(*self.arg)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/testing/decorators.py",
line 215, in knownfailer
    return f(*args, **kwargs)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/core/tests/test_umath.py",
line 1149, in test_spacingl
    return _test_spacing(np.longdouble)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/core/tests/test_umath.py",
line 1132, in _test_spacing
    assert np.spacing(one) == eps
AssertionError

======================================================================
FAIL: test_special_values (test_umath_complex.TestClog)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/testing/decorators.py",
line 146, in skipper_func
    return f(*args, **kwargs)
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/core/tests/test_umath_complex.py",
line 299, in test_special_values
    assert_almost_equal(np.log(np.conj(xa[i])), np.conj(np.log(xa[i])))
  File "/home/robini/slash/lib/python2.7/site-packages/numpy/testing/utils.py",
line 448, in assert_almost_equal
    raise AssertionError(msg)
AssertionError:
Arrays are not almost equal to 7 decimals
 ACTUAL: array([-inf+3.14159265j])
 DESIRED: array([-inf-3.14159265j])

----------------------------------------------------------------------
Ran 3571 tests in 10.897s

FAILED (KNOWNFAIL=5, SKIP=1, failures=3)

Cheers

Robin


More information about the NumPy-Discussion mailing list