Calling blas ddot from Cython

Viewed 806

I'm trying to use the dot product from BLAS library using Cython, but when the compiled module is called appears the following traceback "undefined symbol: cblas_ddot". Executing the np.config.show() to see the linked libraries:

lapack_info:
       libraries = ['lapack', 'lapack']
       library_dirs = ['/usr/lib64']
       language = f77

lapack_info:
    libraries = ['lapack', 'lapack']
    library_dirs = ['/usr/lib64']
    language = f77

openblas_lapack_info:
  NOT AVAILABLE

blas_info:
    libraries = ['cblas', 'blas']
    library_dirs = ['/usr/lib64']
    define_macros = [('HAVE_CBLAS', None)]
    language = c

atlas_3_10_blas_threads_info:
  NOT AVAILABLE

atlas_threads_info:
  NOT AVAILABLE

atlas_3_10_threads_info:
  NOT AVAILABLE

atlas_blas_info:
  NOT AVAILABLE

atlas_3_10_blas_info:
  NOT AVAILABLE

atlas_blas_threads_info:
  NOT AVAILABLE

openblas_info:
  NOT AVAILABLE

blas_mkl_info:
  NOT AVAILABLE

blas_opt_info:
    libraries = ['cblas', 'blas']
    library_dirs = ['/usr/lib64']
    language = c
    define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]

blis_info:
  NOT AVAILABLE

atlas_info:
  NOT AVAILABLE
atlas_3_10_info:
  NOT AVAILABLE

lapack_mkl_info:
  NOT AVAILABLE

And the ldd /usr/lib/python2.7/site-packages/numpy/core/multiarray.so and readlink -e /usr/lib/libblas.so.3 shows: /usr/lib/libblas.so.3.7.0

So apparently the BLAS libraries are linked, but don't find the cblas_ddot. The pyx file:

import numpy as np
cimport numpy as np

cdef extern from "cblas.h":
    double ddot "cblas_ddot"(int N,
                             double *X, int incX,
                             double *Y, int incY)

ctypedef np.float64_t dtype_t
def matmul(np.ndarray[dtype_t, ndim=2] A,
           np.ndarray[dtype_t, ndim=2] B):
    cdef Py_ssize_t i, j
    cdef np.ndarray[dtype_t,ndim=2] out = np.zeros((A.shape[0],B.shape[1]))
    cdef np.ndarray[dtype_t, ndim=1] A_row, B_col
    for i in range(A.shape[0]):
        A_row = A[i,:]
        for j in range(B.shape[1]):
            B_col = B[:, j]
            out[i,j] = ddot(
                A_row.shape[0],
                <dtype_t*>A_row.data,
                A_row.strides[0] // sizeof(dtype_t),
                <dtype_t*>B_col.data,
                B_col.strides[0] // sizeof(dtype_t))

The compiling file looks like: import numpy

if __name__ == '__main__':

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext


    # The Cython modules to setup
    ext_modules = [
        Extension('matmul', ['matmul.pyx'], include_dirs=
        [numpy.get_include()])
    ]

    # Run the setup command
    setup(
        cmdclass = {'build_ext': build_ext},
        ext_modules = ext_modules
    )
1 Answers
Related