[Numpy-discussion] Problems when using ACML with numpy

Thomas Unterthiner thomas_unterthiner at web.de
Sat May 12 13:35:01 EDT 2012


On 05/12/2012 05:34 PM, Pauli Virtanen wrote:
> 12.05.2012 17:30, Thomas Unterthiner kirjoitti:
> [clip]
>> However it didn't seem to work. The same 5000x5000 matrix-multiply is
>> still spinning at 100% CPU usage. I attached to the process after I let
>> it run for over 3 minutes, and the stacktrace looked like this:
>>
>> #0  DOUBLE_dot (ip1=<optimized out>, is1=8, ip2=
>>      [...gibberish...], is2=40000, op=0x7f8633086000 "",
>>      n=5000, __NPY_UNUSED_TAGGEDignore=0x23f40f0) at
>> numpy/core/src/multiarray/arraytypes.c.src:3077
>> #1  0x00007f864dea1466 in PyArray_MatrixProduct2 (op1=<optimized out>,
>> op2=<optimized out>, out=<optimized out>)
>>      at numpy/core/src/multiarray/multiarraymodule.c:847
> This is also not using ACML. You'll need to adjust things until the line
>
> 	from numpy.core._dotblas import dot
>
> works. CBLAS is indeed needed.
>

It seems like I just can't get it to work. Here is what I did:

I downloaded cblas from netlib, and changed the Makefile.LINUX to read:

BLLIB = /opt/acml5.1.0/gfortran64_fma4/lib/libacml.so
CBLIB = ../lib/cblas.a
CFLAGS = -O3 -DADD_ -march=native -flto -fPIC
FFLAGS = -O3  -march=native -flto
RANLIB = ranlib

Then renamed Makefile.LINUX to Makefile.in, and built cblas.  I copied 
the resulting libcblas.a  to /opt/acml5.1.0/gfortran64_fma4/lib/ .  I 
also copied the files in $CBLAS_DIR/include  to 
/opt/acml5.1.0/gfortran64_fma4/include  (not sure if that was needed).

I then modified my .bashrc by adding the line

export LD_LIBRARY_PATH=/opt/acml5.1.0/gfortran64_fma4/lib

I started a new shell afterwards to make sure the variable was set.

Next, I downloaded the numpy-1.6.1  source distribution. I then created 
the following 'site.cfg':

[blas]
blas_libs = cblas,acml
library_dirs = /opt/acml5.1.0/gfortran64_fma4/lib
include_dirs =  /opt/acml5.1.0/gfortran64_fma4/include

[lapack]
language = f77
lapack_libs = acml
library_dirs = /opt/acml5.1.0/gfortran64_fma4/lib
include_dirs = /opt/acml5.1.0/gfortran64_fma4/include


I'm not sure where 'site.cfg' is supposed to go, so I placed one copy in 
the root-directory of the package, one in ./numpy/ and one in 
./numpy/distutils/

I then did  'sudo python setup.py install --prefix=/usr/local'  which 
built and installed without a hitch. (Sidenote: in other tries, I 
noticed that if I export CFLAGS and LDFLAGS before calling this, there 
will be an error, is that normal? How am I supposed to set CFLAGS when 
building?)

Anyways, when I don't export any environment variables and just do   
'sudo python setup.py install --prefix=/usr/local', evertying works 
smoothly. Amongst other things, I get the following output while compiling:

$ sudo python setup.py install --prefix=/usr/local 2>&1

[...]

/media/scratch/software/numpy/numpy-1.6.1/numpy/distutils/system_info.py:1414: 
UserWarning:
     Atlas (http://math-atlas.sourceforge.net/) libraries not found.
     Directories to search for the libraries can be specified in the
     numpy/distutils/site.cfg file (section [atlas]) or by setting
     the ATLAS environment variable.
   warnings.warn(AtlasNotFoundError.__doc__)
blas_info:
   FOUND:
     libraries = ['cblas', 'acml']
     library_dirs = ['/opt/acml5.1.0/gfortran64_fma4/lib']
     language = f77

   FOUND:
     libraries = ['cblas', 'acml']
     library_dirs = ['/opt/acml5.1.0/gfortran64_fma4/lib']
     define_macros = [('NO_ATLAS_INFO', 1)]
     language = f77
[...]
lapack_info:
   FOUND:
     libraries = ['acml']
     library_dirs = ['/opt/acml5.1.0/gfortran64_fma4/lib']
     language = f77

   FOUND:
     libraries = ['acml', 'cblas', 'acml']
     library_dirs = ['/opt/acml5.1.0/gfortran64_fma4/lib']
     define_macros = [('NO_ATLAS_INFO', 1)]
     language = f77

[...]

'build/src.linux-x86_64-2.7/numpy/core/include/numpy/__multiarray_api.h', 'build/src.linux-x86_64-2.7/numpy/core/include/numpy/__ufunc_api.h']
building extension "numpy.core._dotblas" sources
building extension "numpy.core.umath_tests" sources
conv_template:> 
build/src.linux-x86_64-2.7/numpy/core/src/umath/umath_tests.c
[...]
/usr/bin/gfortran -Wall -Wall -shared 
build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o 
build/temp.linux-x86_64-2.7/numpy/linalg/python_xerbla.o 
-L/opt/acml5.1.0/gfortran64_fma4/lib -Lbuild/temp.linux-x86_64-2.7 
-lacml -lcblas -lacml -lgfortran -o 
build/lib.linux-x86_64-2.7/numpy/linalg/lapack_lite.so



The output contains no other mention of anything BLAS-related. Notice 
the absense of any calls to gcc/gfortran after the 'building extension 
"numpy.core._dotblas" sources' message.

After the build is done, the directory 
./build/lib.linux-x86_64-2.7/numpy/core/  does not contain any "dotblas" 
files, and neither does  
/usr/local/lib/python2.7/dist-packages/numpy/core/  afterwards.  Thus it 
is no surprise that the following still fails:


tom at blucomp:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from numpy.core._dotblas import dot
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named _dotblas






More information about the NumPy-Discussion mailing list