« Return to Thread: ATLAS on win32, pthreads, SSE and stack alignment

ATLAS on win32, pthreads, SSE and stack alignment

by Sébastien Kunz-Jacques-2 :: Rate this Message:

Reply to Author | View in Thread

I tried  to compile atlas 3.9.4 under Win32 with MinGW and pthreads.
While single threaded builds passed make check and make full_test just
fine, I encountered crashes in make ptcheck. After having investigated
the problem, I came to the conclusion that these crashes occur because
gcc always maintains a 16-byte aligned stack and pthreads-win32, in
accordance win the Win32 ABI, only guarantees a 4-byte aligned stack.

Since there is a function of the pthreads-win32 library that calls the
start function of a thread created with pthread_create, it is sufficient
to align the stack upon entry in that function to solve this
thread-related issues. It turns out there is a specific gcc attribute
for that,
__attribute__((force_align_arg_pointer))
make ptcheck then succeeds. However, there is no real reason why pthread
would align the stack itself. More importantly, this does not
necessarily solve the case where an ATLAS function compiled in a dll is
called from a compiler that does not align the stack as gcc does. So my
questions are as follows:

(a) Should ATLAS align itself the stack in any function called from
pthread_create? The alternative would be to make it in the pthread-win32
lib; I started a thread (no pun intended) on this topic at
http://sourceware.org/ml/pthreads-win32/2008/msg00053.html.

(b) does ATLAS already handle this stack alignment issue for interface
functions? I made a MSVC project that calls a ATLAS (actually LAPACK) in
a dll and it seems to work fine ; however this proves basically nothing
as most of the tests done by make ptcheck work ok despite the possible
alignment issues.

(c) if not, should it be fixed to do so ? There are two ways to do tha
(with a gcc 4.2 or more recent):
- give to each interface fonction the
__attribute__((force_align_arg_pointer)) ;
- compile each file containing interface functions with the option
-mstack-realign. This possibly realign stack for functions that do not
need it, but avoids modifying source files when they are not in the
ATLAS scope (e.g. LAPACK).

It seems to me the optimal solution would be to have pthread-win32
handle the alignment for internal ATLAS functions, and to add if
required alignment directives for interface functions when compiling
ATLAS with shared libraries on win32. What do you think ?

(d) If it is not easy to make the changes, would it be possible to add
an entry in the ATLAS FAQ/errata list to point to the issues described
here ?


BtW, I am willing to help in maintaining the on-line doc for ATLAS on
win32 for the topics that I understand (mostly configure/compile issues).

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Math-atlas-devel mailing list
Math-atlas-devel@...
https://lists.sourceforge.net/lists/listinfo/math-atlas-devel

 « Return to Thread: ATLAS on win32, pthreads, SSE and stack alignment