Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Need Help Porting XS Modules to Windows

by wbirkett (Acolyte)
on Sep 30, 2018 at 22:17 UTC ( [id://1223338]=perlquestion: print w/replies, xml ) Need Help??

wbirkett has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Experts. I have some generally useful Perl XS modules which I developed on the Mac OS platform. This work was originally used for my private consulting practice in the printing industry. Last March, my partner and I presented a technical paper about a technique we developed for calibrating printing devices. Now, we're getting requests for the apps and modules from potential users running Windows.

This code is generally useful because it accesses the BLAS and LAPACK libraries of the Accelerate framework, which are the basis for MATLAB. This brings some serious computing power to Perl, without the overhead and complexity of PDL.

You can see what we've done at optimal method The XS modules are here Color Tool Kit (optional modules for Mac OS)

I've gotten the non-XS modules to work on Strawberry Perl, but have no idea how to get the XS modules compiled. I'd really appreciate some help with this. Thanks

  • Comment on Need Help Porting XS Modules to Windows

Replies are listed 'Best First'.
Re: Need Help Porting XS Modules to Windows
by syphilis (Archbishop) on Oct 01, 2018 at 00:23 UTC
    but have no idea how to get the XS modules compiled.

    It's just a matter of running 'perl Build.pl', 'perl Build', 'perl Build test' and 'perl Build install', fixing errors as they arise.
    When I try to build ICC-Support-Lapack-0.6 on StrawberryPerl-5.28.0, I get the following error during the 'perl Build' stage:
    src\xs_arrays.c:13:10: fatal error: Accelerate/Accelerate.h: No such f +ile or directory #include <Accelerate/Accelerate.h> ^~~~~~~~~~~~~~~~~~~~~~~~~
    Where do I find Accelerate/Accelerate.h ?

    <UPDATE>
    I see that Accelerate/Accelerate.h is a macos system header.
    So the first thing that needs to be done is to provide a replacement of that part of the macos system library for Windows.
    </UPDATE>

    Trying to build ICC-Support-Levmar-0.50, I get (during 'perl Build' step):
    g++.exe -o "blib\arch\auto\ICC\Support\Levmar\Levmar.xs.dll" -Wl,--bas +e-file,"lib\ICC\Support\Levmar.base" -Wl,--image-base,0x2d170000 -mdl +l -s -L"C:\_64\strawberry-5.28.0\perl\lib\CORE" -L"C:\_64\strawberry- +5.28.0\c\lib" "lib\ICC\Support\Levmar.lds" -framework Accelerate "lib +\ICC\Support\Levmar.exp" g++.exe: error: Accelerate: No such file or directory g++.exe: error: unrecognized command line option '-framework' dlltool --def "lib\ICC\Support\Levmar.def" --output-exp "lib\ICC\Suppo +rt\Levmar.exp" --base-file "lib\ICC\Support\Levmar.base" dlltool: Unable to open base-file: lib\ICC\Support\Levmar.base g++.exe -o "blib\arch\auto\ICC\Support\Levmar\Levmar.xs.dll" -Wl,--ima +ge-base,0x2d170000 -mdll -s -L"C:\_64\strawberry-5.28.0\perl\lib\CORE +" -L"C:\_64\strawberry-5.28.0\c\lib" "lib\ICC\Support\Levmar.lds" -fr +amework Accelerate "lib\ICC\Support\Levmar.exp" g++.exe: error: Accelerate: No such file or directory g++.exe: error: unrecognized command line option '-framework'
    I think there's some macos-specific stuff in there that needs to be replaced. Also, just before the above-quoted excerpt of the Levmar build I see:
    Generating script 'lib\ICC\Support\Levmar.lds' dlltool --def "lib\ICC\Support\Levmar.def" --output-exp "lib\ICC\Suppo +rt\Levmar.exp"
    Neither of those commands generate an error, but neither 'lib\ICC\Support\Levmar.lds' nor 'lib\ICC\Support\Levmar.exp' are created.

    Cheers,
    Rob

      Accelerate is Apple's implementation of BLAS and LAPACK, very old linear algebra libraries. A good free implementation of BLAS (and a part of LAPACK) for Windows is OpenBLAS. (A very good one, but only available to academics or for a fee, is Intel MKL.) On non-Apple platforms C source code should #include <cblas.h> or mkl.h, depending on preprocessor directives. I'm not sure whether it's possible to get a free LAPACK implementation for Windows without having a Fortran compiler, though.

      The funny thing is that src\xs_arrays.c only uses the three constants CblasNoTrans,CblasTrans,CblasConjTrans from BLAS header and does the rest of the array manipulation by hand. (At least that's what it seemed to me while I skimmed the file.)

        The funny thing is that src\xs_arrays.c only uses the three constants CblasNoTrans,CblasTrans,CblasConjTrans from BLAS header and does the rest of the array manipulation by hand

        So, in src/xs_arrays.c, I've replaced:
        #include <Accelerate/Accelerate.h>
        with:
        typedef enum {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113} CB +LAS_TRANSPOSE;
        and that enables xs_arrays.c to be compiled.
        The same alteration needs also to be made to src/xs_stat.c.

        But lib/ICC/Support/Lapack.xs also includes Accelerate/Accelerate.h - only this time the above "typedef enum ..." is insufficient as a replacement.
        So I've included some additional definitions to Lapack.xs (from cblas.h):
        typedef enum {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113} CB +LAS_TRANSPOSE; typedef enum {CblasRowMajor=101, CblasColMajor=102} CBLAS_LAYOUT; typedef enum {CblasUpper=121, CblasLower=122} CBLAS_UPLO; typedef enum {CblasNonUnit=131, CblasUnit=132} CBLAS_DIAG; typedef enum {CblasLeft=141, CblasRight=142} CBLAS_SIDE; typedef int __CLPK_integer; typedef double __CLPK_doublereal;
        That just about enables the thing to compile, but having altered Lapack.xs, I inevitably get the following errors:
        lib\\ICC\\Support\\Lapack.xs:1:1: error: stray '\357' in program &#65279;/* ^ lib\\ICC\\Support\\Lapack.xs:1:2: error: stray '\273' in program &#65279;/* ^ lib\\ICC\\Support\\Lapack.xs:1:3: error: stray '\277' in program &#65279;/* ^
        and I don't know why such a complaint is being made about a file that appears to be entirely valid.

        I've run out of time for tonight.

        Cheers,
        Rob
Re: Need Help Porting XS Modules to Windows
by etj (Deacon) on May 07, 2022 at 00:47 UTC
    An alternative is just to use PDL and PDL::LinearAlgebra, which wraps LAPACK. It works great on Windows, MacOS, Linux, BSD, ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1223338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found