Calling scipy blas from cython is extremely slow
Hi,
following the excellent advice of V. Armando Sole, I have finally succeeded in
calling the blas routines shipped with scipy from cython.
I am doing this to avoid shipping an extra blas library for some project of
mine that uses scipy but has some things coded in cython for extra speed.
So far I managed getting things working on Linux. Here is what I do:
The following code snippet gives me the dgemv pointer (which is a pointer to a
fortran function, even if it comes from scipy.linalg.blas.cblas, weird).
from cpython cimport PyCObject_AsVoidPtr
import scipy as sp
__import__('scipy.linalg.blas')
ctypedef void (*dgemv_ptr) (char *trans, int *m, int *n,\
double *alpha, double *a, int *lda, double *x,\
int *incx,\
double *beta, double *y, int *incy)
cdef dgemv_ptr dgemv=
... and it is not deterministic too... About 1 time over 6 the code calling the scipy blas gives a completely wrong result. How can this be?
Partially fixed. I was messing the row, column order. For some reason this was working in some case. Now I've fixed it and it *always* works. However, it is still slower than the cblas cblas > 0.69 sec scipy blas > 0.74 sec Any clue why?
On Sat, 23 Feb 2013 18:31:42 +0000 (UTC)
Sergio Callegari
However, it is still slower than the cblas
cblas > 0.69 sec scipy blas > 0.74 sec
if you are using scipy blas, the real question is which blas is underneath ? OpenBlas, GotoBlas, Atlas, MKL ? Under Debian I observed a x17 in speed from 35s to 2s with an "aptget install atlas" on Armando's code. Cheers,  Jérôme Kieffer Data analysis unit  ESRF
23.02.2013 20:31, Sergio Callegari kirjoitti:
Partially fixed.
I was messing the row, column order. For some reason this was working in some case. Now I've fixed it and it *always* works.
However, it is still slower than the cblas
cblas > 0.69 sec scipy blas > 0.74 sec
The possible explanations are that either the routine called is different in the two cases, or, the benchmark if somehow faulty.  Pauli Virtanen
participants (3)

Jerome Kieffer

Pauli Virtanen

Sergio Callegari