Sarat Sreepathi
 
Home
Research
Resume
- - - - - - -
Current Projects
- - - - - - -
Energy Modeling
Secure Water
- - - - - - -
Earlier
- - - - - - -
Blue Brain
Pflotran
Cyberinfrastructure
Course Projects
Neptune
Gyro
GenASiS
- - - - - - -
Articles
 
 
BLAS Print

There are some differences among the various BLAS interfaces available, especially ACML and the rest. If you ever need to work with multiple BLAS libraries, TRUST ME THIS WILL SAVE YOUR LIFE.

Specifically there are usage notes for Intel Math Kernel Library(MKL), AMD Core Math Library (ACML), Cray's Scientific libraries (xt-libsci), GotoBLAS and IBM's ESSL libaries.



GENERAL NOTES

Netlib BLAS dgemm (http://www.netlib.org/clapack/cblas/dgemm.c)

int dgemm_(char *transa, char *transb, integer *m, integer *

n, integer *k, doublereal *alpha, doublereal *a, integer *lda,

doublereal *b, integer *ldb, doublereal *beta, doublereal *c, integer

*ldc)

Intel MKL (mkl.h)

void dgemm(char *transa,char *transb,int *m,int *n,int *k,double *alpha,double *a,int *lda,double *b,int *ldb,double *beta,double *c,int *ldc);

GotoBLAS (common_interface.h)

GEMMRETTYPE BLASFUNC(dgemm)(char *, char *, blasint *, blasint *, blasint *, double *,

double *, blasint *, double *, blasint *, double *, double *, blasint *);


ACML
(acml.h)

Note: _ suffix means it uses the Fortran interface

extern void dgemm(char transa, char transb, int m, int n, int k, double alpha, double *a, int lda, double *b, int ldb, double beta, double *c, int ldc);

extern void dgemm_(char *transa, char *transb, int *m, int *n, int *k, double *alpha, double *a, int *lda, double *b, int *ldb, double *beta, double *c, int *ldc, int transa_len, int transb_len);

IBM ESSL (essl.h)

Eg. http://www.nersc.gov/nusers/resources/software/ibm/hpmcount/ex3.c.html

#define dgemm esvdgemm

void esvdgemm(const char *, const char *, _ESVINT, _ESVINT, _ESVINT,

double, const void *, _ESVINT, const void *, _ESVINT, double, void *,

_ESVINT);

 


Cray xt-libsci

 

(from http://docs.cray.com/cgi-bin/craydoc.cgi?mode=View;id=S-2396-22;idx=books_search;this_sort=;q=xt-libsci;type=books;title=Cray%20XT%20Programming%20Environment%20User%27s%20Guide)

The BLAS and LAPACK libraries include routines from the 64-bit libGoto library from the University of Texas.

If you require a C interface to BLAS and LAPACK but want to use Cray XT-LibSci BLAS or LAPACK routines, you must use the Fortran interfaces.

You can access the Fortran interfaces from a C program by adding an underscore to the respective routine names and passing arguments by reference (rather than by value in the traditional way). For example, you can call the dgetrf() function as follows:

dgetrf_(&uplo, &m, &n, a, &lda, ipiv, work, &lwork, &info);

Note: C programmers using the Fortran interface must order arrays in Fortran column-major order.

Specific example:

char transa, transb;

int size;

double alpha,beta;

double **a, **b, **c;

-----------------------------------------------------------

GotoBLAS

-----------------------------------------------------------

dgemm_(&transa,&transb,&size,&size,&size,&alpha,*a,&size,*b,&size,&beta,*c,&size);

-----------------------------------------------------------

MKL

-----------------------------------------------------------

dgemm(&transa,&transb,&size,&size,&size,&alpha,*a,&size,*b,&size,&beta,*c,&size);

you can use dgemm_ in place of dgemm ,you won't find the prototype for dgemm_ in mkl_blas.h though :)

-----------------------------------------------------------

ACML

-----------------------------------------------------------

dgemm(transa,transb,size,size,size,alpha,*a,size,*b,size,beta,*c,size);

or

dgemm_(&transa,&transb,&size,&size,&size,&alpha,*a,&size,*b,&size,&beta,*c,&size);

-----------------------------------------------------------

ACML More Notes:

-----------------------------------------------------------

/*

This is the ACML header file. It contains function prototypes

to allow a C programmer to call ACML routines via their C

or Fortran interfaces.

C interfaces to ACML routines differ from FORTRAN interfaces in the following major respects:

(i) The FORTRAN interface names are appended by an underscore. (ii) The C interfaces contain no workspace arguments; all workspace memory is allocated internally.

(iii) Scalar input arguments are passed by value in C interfaces.

FORTRAN interfaces pass all arguments (except for character string "length" arguments that are normally hidden from FORTRAN programmers) by reference.

(iv) Most arguments that are passed as character string pointers to FORTRAN interfaces are passed by value as single characters to C interfaces. The character string "length" arguments of FORTRAN interfaces are not required in the C interfaces.

It is important to note that in both the FORTRAN and C interfaces, 2-dimensional arrays are assumed to be stored in column-major order.

e.g. the matrix A = [ 1.0 2.0 ]

[ 3.0 4.0 ]

would be stored in memory as 1.0, 3.0, 2.0, 4.0. This storage order corresponds to a FORTRAN-style 2-D array declaration A(2,2), but not to an array declared as a[2][2] in C which would be stored in row-major order as 1.0, 2.0, 3.0, 4.0.

As an example, compare the FORTRAN and C interfaces of LAPACK routine dsytrf as implemented in ACML.

FORTRAN:

void dsytrf_(char *uplo, int *n, double *a, int *lda, int *ipiv,

double *work, int *lwork, int *info, int uplo_len);

C:

void dsytrf(char uplo, int n, double *a, int lda, int *ipiv, int *info);

C code calling both the above variants might look like this:

double *a;

int *ipiv;

double *work;

int n, lda, lwork, info;

// Assume that all arrays and variables are allocated and initialized as required by dsytrf.

// Call the FORTRAN version of dsytrf. The first argument is a character

// string, and the last argument is the length of that string. The input

// scalar arguments n, lda and lwork, as well as the output scalar

// argument info, are all passed by reference.

dsytrf_("Upper", &n, a, &lda, ipiv, work, &lwork, &info, 5);

 

// Call the C version of dsytrf. The first argument is a character,

// workspace is not required, and input scalar arguments n and lda are passed by value. Output scalar argument info is passed by reference.

dsytrf('U', n, a, lda, ipiv, &info);

*/


 
 
 

 

© 2005 - 2011 Sarat Sreepathi
Green Web Hosting! This site hosted by DreamHost.