12 Replies Latest reply on Nov 25, 2012 8:12 PM by yangkunlun

    CBLAS and CLAPACK for ACML

    matthieu.brucher
      How to build the wrappers for CBLAS and/or CLAPACK

      Hi,

      I want to be able to use the ACML with numpy, but for this purpose, I need to have at least the CBLAS module. Is there a way to get it ?

      Is there a plan to provide the CLAPACK module as well ?
        • CBLAS and CLAPACK for ACML
          MattBro
          It seems that the libraries naming conventions for interfacing to C are not quite up to the standard. Most other BLAS libraries that I know of, Intels, Atlas, Goto's etc. provide a c interface that always prepends the symbol cblas_ to the usual fortran name. All my code that uses blas uses this standard and I haven't switched to the acml library because of this.

          So for example from the atlas library we have from cblas.h the standard interface,
          void cblas_daxpy(const int N, const double alpha, const double *X,
          const int incX, double *Y, const int incY);

          Now from the acml library, if you want a 32 bit library running under windows you are forced to use a library compiled with fortran. The multi-processor library acml.h interface provides us with,
          extern void daxpy(int n, double alpha, double *x, int incx, double *y, int incy);

          This is weird to me both because it fails to have the cblas_ prefix, but also because it otherwise matches the cblas.h version. I had thought that fortran passes everything by reference, though I'm not a fortran programmer so maybe my memory is failing me. Maybe all we need here is an include file with a bunch of defines that renames cblas_daxpy to daxpy if everything else is the same.
            • CBLAS and CLAPACK for ACML
              chipf
              ACML includes two ways for C programs to call: A native C interface using "by-value" calling conventions, and a Fortran "by-reference" method which is awkward to use from C (but possible). These are documented in the user guide.

              Programs that rely on a CBLAS interface can still use ACML, even though AMD has not provided the CBLAS library itself.
              First, grab the CBLAS from the link at www.netlib.org/blas.
              Next create a Makefile.in from one of the examples. A good start is the .LINUX makefile. Change the BLLIB line to point at the ACML library. For example:
              BLLIB=/opt/acml4.0.1/gfortran64/lib/libacml.a

              Then just make sure the compiler choices are correct:
              CC=gcc
              FC=gfortran

              These settings are what I just used to verify that it works with gfortran 4.1.2.

              When in doubt, actually look at the README file. It took me about 1 minute to get this to work.
              The result will be a cblas .a file that you can link with your application. You would also need to link libacml.a, as you can see from how the CBLAS test applications are built.
                • CBLAS and CLAPACK for ACML
                  MattBro
                  Well I tried to get it to work as you suggested but I ran into a number of nasty issues.
                  The first is that I had downloaded the 32 bit libraries that I think were compiled with the 32 bit intel fortran compiler since I need to link against 32 bit software in windows. It may be, for this reason, that the fortran interface was considerably different than that which was expected in the cblas C code that implements the cblas interface. For example in acml.h the return values appear at the end of the argument list instead of the beginning and also in many cases there are extra arguments for the length of strings that are not declared in the cblas code. I attempted to modify the cblas code to fix this issues. (Not exactly trivial due to the size of the code.)

                  Unfortunately my new problem is that at least for the static acml library, it requires a bunch of Intel ifort run time libraries that are not exported in the provided acml library. This is annoying if you don't have this somewhat expensive product and just want to use your Microsoft C/C++ infrastructure and have access to BLAS. It would great if AMD could provide static ACML libraries that don't require third party compilers to link against. You would think that if you paid all that money for ifort, that they would allow you to distribute libraries that don't require your customers to buy ifort.
                  • CBLAS and CLAPACK for ACML
                    ddreyfus

                    How do you compile and link CBLAS from www.netlib.org/blas with ACML 4.3.0 (iFort compilation) on Windows (XP) using the gnu gfortran and gcc compilers (4.3.2)? In particular, I'm interested in the multi-threaded versions.

                    I get errors running the examples in the ACML 4.3.0 distribution using the gnu compilers. "ACML error: on entry to drandinitialize parameter number 1 had an illegal value."

                • CBLAS and CLAPACK for ACML
                  MattBro
                  I have ported the standard cblas interface to the acml library after a lot of hacking. Much of the Fortran interface was different and so it took some time. I'd be happy to give it away perhaps to an acml developer if they would wish to provide a more standard C interface.
                    • CBLAS and CLAPACK for ACML
                      MeMo_oMeM
                      Hi,

                      I am a little confused. Once regular BLAS libraries are compiled, they can be called from C codes as well. Why do we need a C interface then?

                      In fact, to prove this I tried to use a toy code, but couldn't make it work. I have GOTO BLAS installed on my Opteron machine. But the call to the dgemv gives Segmentation Error! I will appreciate your comments. Thanks!

                      Here's the toy code:
                      ==================

                      #include <stdio.h>

                      double m[] = {
                      3, 1, 3,
                      1, 5, 9,
                      2, 6, 5
                      };

                      double x[] = {
                      -1, -1, 1
                      };

                      double y[] = {
                      0, 0, 0
                      };

                      int
                      main()
                      {
                      int i, j;

                      dgemv('N', 3, 3, 1.0, m, 3, x, 1, 0.0, y, 1);

                      for (i=0; i<3; ++i)
                      printf("%5.1f\n", y);

                      return 0;
                      }
                        • CBLAS and CLAPACK for ACML
                          chipf
                          For this dgemv example, it works with two modifications. First, include acml.h (or just the dgemv prototype). This first mod isn't strictly necessary since the data types assumed by the compiler work out to be correct.

                          Second, the y variable in the printf needs to be indexed. I just changed y to y and the printf started working.

                          The dgemv C style calling sytax is done correctly in the example.
                          • CBLAS and CLAPACK for ACML
                            MattBro
                            The primary reason for the standard CBLAS interface is to comply to the calling convention standard established by the BLAS committee. This standard is adhered to by most of the other major BLAS libraries out there, atlas, MKL etc. Usually the calls will have a "cblas_" prepended to the call and then a standard calling interface that differs quite a bit from both the Fortran calls and the current acml blas C interface.

                            Thus if you are like me and have libraries with hundreds of calls into cblas, it becomes rather tricky to switch to the ACML library. At any rate after a lot of hacking I got the reference BLAS Fortran to CBLAS interface to compile. It required some guesswork as to how to fix some of the Fortran calling conventions, which themselves are different when calling from C. (By virtue of where to put string length arguments and return arguments etc.)

                            If you are interested in this, I handed it over to the folks working on this C++ math library.
                            http://www.osl.iu.edu/research/mtl/mtl4/

                              • CBLAS and CLAPACK for ACML
                                lytles

                                I agree MattBro. This is really a pain. The acml calling convention is actually pretty well thought out and a bit nicer to use than the standard, but by not following the standard they've made it almost unusable. What we've got now is our own abstraction to make acml look like the standard. At this point, we don't expose the blas or lapack directly so this works, but going forward we'd like to , and we need to find a solution or fall back to another implementation on amd.

                                i looked for your code at the mtl4 site, but didn't find it (though i did see a pretty good ppt presentation that mentioned it). I'm going to try the netlib cblas and see if i can get it to build on top of acml myself.

                                did amd follow the netlib standard for the fortran interfaces atleast ?

                                  • CBLAS and CLAPACK for ACML
                                    chipf

                                    ACML uses the standard netlib blas and lapack calling interfaces. These are FORTRAN interfaces. We chose not to include the cblas interfaces because CBLAS is VERY SIMPLE to build.

                                    If you are using C interfaces such as listed in the example posted on this topic, then you can use the C function prototypes as provided in acml.h. These prototypes are simple C wrappers that call the FORTRAN functions. If you are masochistic, you can call the FORTRAN functions directly from C, being sure to pass all values by reference and get the char lengths correct. This is all described in the documentation.


                                    However...
                                    You can also write your application to the cblas interface. An example would be to substitute this into the above example:

                                    cblas_dgemv(CblasRowMajor,CblasNoTrans,3,3,1.0,m,3,x,0.0,y,1)

                                    and include cblas.h from the netlib cblas.

                                    After building the cblas library as described earlier, link it to your application. You will have to include both libcblas and libacml in the link.