Hi,
Is there a way to detect the size of integers (ie 32 or 64 bit) used by a library?
I am using LAPACK/BLAS (ATLAS) libraries via CFFI. Recently, my tests failed, and to my surprise, the solution was to use 32-bit ints. Note that I am on a 64-bit platform, using the Ubuntu libraries, so why this happens is a mystery. But it would be great if I could detect it somehow from within Lisp.
Thanks,
Tamas
On Wed, May 26, 2010 at 1:42 PM, Tamas K Papp tkpapp@gmail.com wrote:
Is there a way to detect the size of integers (ie 32 or 64 bit) used by a library?
The point is that you cannot even detect it so simply in C. If the library is FORTRAN then you definitely have to introduce the knowledge of the type size "by hand", because different compilers and different compiler options will force the use of different type sizes.
If the library is in C and you have access to the headers then maybe cffi-grovel can traverse the header and find it out, but I am not familiar enough with that component and its preprocessing abilities (Atlas is likely to use #defines and #ifdefs to choose the appropriate size).
Otherwise the usual and most reliable way to detect it is to do something like autoconf does, which is to create a tiny C program, compile it with the same flags as the library and detect the type size. You may even automate this from lisp.
Juanjo
On Wed, 2010-05-26 at 11:42 +0000, Tamas K Papp wrote:
Hi,
Is there a way to detect the size of integers (ie 32 or 64 bit) used by a library?
I am using LAPACK/BLAS (ATLAS) libraries via CFFI. Recently, my tests failed, and to my surprise, the solution was to use 32-bit ints. Note that I am on a 64-bit platform, using the Ubuntu libraries, so why this happens is a mystery.
Linux uses the LP64 data model, in which ints are 32bit: http://en.wikipedia.org/wiki/64-bit#Specific_C-language_data_models
But it would be great if I could detect it somehow from within Lisp.
cffi:foreign-type-size will return the size of the builtin types
On Wed, May 26, 2010 at 05:42, Tamas K Papp tkpapp@gmail.com wrote:
I am using LAPACK/BLAS (ATLAS) libraries via CFFI. Recently, my tests failed, and to my surprise, the solution was to use 32-bit ints. Note that I am on a 64-bit platform, using the Ubuntu libraries, so why this happens is a mystery. But it would be great if I could detect it somehow from within Lisp.
In the particular case of LAPACK and the BLAS: the default LAPACK and BLAS should always use 32-bit ints (Fortran's INTEGER type, a.k.a. "INTEGER(4)"). There are versions of both libraries that use 64-bit ints ("INTEGER(8)"), but the system should always identify them specially: either as separate, differently named libraries, or as differently named functions within the same library. (I've seen both possibilities.)
In general: Of course it would be nicer to be able to do everything in Lisp, but have you taken a look at CMake's CheckTypeSize module?
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#module:CheckTypeSize
mfh
Tamas,
Here's what I have in GSLL
(case (cffi:foreign-type-size :long) (8 (push :int64 *features*) #+fsbv (fsbv:defsynonym sizet :uint64)) (4 (push :int32 *features*) #+fsbv (fsbv:defsynonym sizet :uint32)))
Liam
On Wed, May 26, 2010 at 7:42 AM, Tamas K Papp tkpapp@gmail.com wrote:
Hi,
Is there a way to detect the size of integers (ie 32 or 64 bit) used by a library?
I am using LAPACK/BLAS (ATLAS) libraries via CFFI. Recently, my tests failed, and to my surprise, the solution was to use 32-bit ints. Note that I am on a 64-bit platform, using the Ubuntu libraries, so why this happens is a mystery. But it would be great if I could detect it somehow from within Lisp.
Thanks,
Tamas
cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel