[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Numeric Lua 0.3
- From: Luis Carvalho <lexcarvalho@...>
- Date: Thu, 25 Aug 2011 17:14:43 -0400
Hi Dirk,
> I made a 5.1 and a 5.2 version, both doing this:
>
> > A=matrix{{1,2,3},{4,5,6}}
> > =A.pinv()
> Segmentation fault
It's hard to guess without details on your platform and libs, but I think this
is most probably a memory alignment issue with ATLAS. Some routines in ATLAS
expect 8-byte aligned arrays, which cannot be guaranteed when using vanilla
Lua on 32-bit systems since sizeof(Udata) = 20bytes (the payload is right
after the header.) There are then two types of solutions to this problem: one
is [1] to rebuild ATLAS and the other is [2] to pad Udata to fix the alignment.
[1] Try building your own ATLAS lib by specifying
-Fa alg -mpreferred-stack-boundary=2
(and `-b 32`) to `configure`. Then, pass LAPACK_LIBDIR to luarocks pointing to
the location where your ATLAS libs are installed. Note that you need to use,
in the rockspec,
libraries = {"hdf5", "fftw3", "plplotd",
"lapack", "f77blas", "cblas", "atlas"}
and, moreover, if the ATLAS libs are static,
libraries = {"hdf5", "fftw3", "plplotd",
"lapack", "f77blas", "cblas", "atlas", "gfortran"}
This has the advantage of getting you a nicely tuned linear algebra kernel!
Check
http://math-atlas.sourceforge.net/errata.html
"GCC's violation of the x86 ABI causes seg faults/bus errors when mixed with
other compilers", for more information.
[2] The other solution is to specify LUAI_USER_ALIGNMENT_T to attain the
8-byte boundary in luaconf.h. Minimal change:
#define LUAI_USER_ALIGNMENT_T union { double u[3]; void *s; long l; }
You can even use `double u[4]` for a 16-byte alignment that might improve
performance when using SIMD instructions, as suggested by FFTW:
http://www.fftw.org/doc/SIMD-alignment-and-fftw_005fmalloc.html
While you're at it, you might as well patch llex.c with your favorite
extension -- short lambda! -- or add token filters. :)
Another straightforward solution -- and a quick way to know if your problem is
memory alignment -- is to use LuaJIT since it guarantees 8-byte aligned
userdata. Actually, an even simpler check for your problem is to not use
ATLAS, but just an unoptimized BLAS/LAPACK!
If anybody would provide more insight or a better way of solving this problem,
I'd appreciate it! :)
Cheers,
Luis
--
Computers are useless. They can only give you answers.
-- Pablo Picasso
--
Luis Carvalho (Kozure)
lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'