|
From: | Jarno Rajahalme |
Subject: | Wrapper dylib to fix OSX libBLAS & libLAPACK with -m64 (Re: 3.5.0+ compiled on Mac OSX 10.6.6) |
Date: | Thu, 27 Jan 2011 13:01:50 +0200 |
On Jan 26, 2011, at 7:50 , ext Jarno Rajahalme wrote:
I made a wrapper (libBLASWRAP.dylib) allowing the use of Apple provided BLAS and LAPACK with 64-bit builds. With this Octave builds and tests fine without additional atlas or lapack. No compilation changes are needed, but -lBLASWRAP needs to be specified for the linker, before Apple's own libraries, or preferably instead of them to avoid any confusion. The wrapper (blaswrap.c) is included (attachment), comments include instructions for building (using Apple-provided gcc and ld). |
blaswrap.c
Description: Binary data
Distribution of this wrapper is free under GPL license. Supposedly all libBLAS functions should have been exported with F2C calling convention, but some are exported in native gfortran calling convention (hence no go with *or* without -ff2c). This wrapper introduces stubs that offer gfortran native calling convention to those BLAS and LAPACK functions that are originally exported via vecLib with F2C calling convention. In most cases this is only 2 lines of inline assembly calling the original function and transforming the returned double to a float, so this is about as efficient as it can be (without recompiling the calling programs). The wrapper re-exports all BLAS and LAPACK (well, the whole vecLib) functions, so it should be used *instead* of e.g. "-framework vecLib" or "-framework Accelerate" (which includes vecLib, which includes both BLAS and LAPACK) to build e.g. Octave. I have included my diff to arpack Portfile (from macports) as an example, please note the removal of -ff2c option, so that arpack is compiled with native gfortran calling convention. For building octave --with-blas="-lBLASWRAP" is enough, if building with macports provided compiler. Otherwise "-L/opt/local/lib" may also be needed. Wrapper itself is built with Apple provided GCC 4.2 to make sure no extra dependencies are brought in: $ otool -L /opt/local/lib/libBLASWRAP.dylib /opt/local/lib/libBLASWRAP.dylib: /opt/local/lib/libBLASWRAP.dylib (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 268.0.1) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1) $ Regards, Jarno Example portfile changes (arpack): *** /opt/local/var/macports/sources/rsync.macports.org/release/ports/math/arpack/Portfile Thu Jun 10 02:00:45 2010 --- math/arpack/Portfile Thu Jan 27 12:47:29 2011 *************** *** 22,27 **** --- 22,36 ---- use_configure no worksrcdir ARPACK patchfiles patch-arpack.diff + post-patch { + # + # BLASWRAP is built with: + # gcc-4.2 -c -O3 -m64 -fomit-frame-pointer -W -Wall blaswrap.c + # sudo ld -arch x86_64 -dylib -x blaswrap.o -o /opt/local/lib/libBLASWRAP.dylib -init _initVecLibWrappers -reexport_framework vecLib -lSystem + # + reinplace "s|-framework Accelerate|-L/opt/local/lib -lBLASWRAP|" ${worksrcpath}/ARmake.inc + reinplace "s|-ff2c||" ${worksrcpath}/ARmake.inc + } use_parallel_build no *************** *** 95,104 **** set dir ${worksrcpath}-${arch} } ! make_dylib arpack ${dir} ${arch} "-latlas -llapack -lblas -lgfortran -lSystem" ${version} if { [variant_isset mpi] } { ! make_dylib parpack ${dir} ${arch} "-latlas -llapack -lblas -lgfortran -lmpi_f77 -lSystem -larpack.1" ${version} } } } --- 104,113 ---- set dir ${worksrcpath}-${arch} } ! make_dylib arpack ${dir} ${arch} "-lBLASWRAP -lgfortran -lSystem" ${version} if { [variant_isset mpi] } { ! make_dylib parpack ${dir} ${arch} "-lBLASWRAP -lgfortran -lmpi_f77 -lSystem -larpack.1" ${version} } } } |
[Prev in Thread] | Current Thread | [Next in Thread] |