Skip to content

How to build OpenBLAS for iPhone iOS (ARMv8)

Martin Kroeker edited this page Mar 12, 2017 · 10 revisions

How to build OpenBLAS for iPhone/iOS

Go to the directory where you unpacked OpenBLAS.
In file c_check look for the section that looks like
     $cross_suffix = "";

     if (dirname($compiler_name) ne ".") {
         $cross_suffix .= dirname($compiler_name) . "/";
     }

     if (basename($compiler_name) =~ /([^\s]*-)(.*)/) {
         $cross_suffix .= $1;
     }

and add the following line after it, adjusting the path as necessary for your Xcode installation:

    $cross_suffix = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/";

You need this because we will provide CC with arguments and Perl function for extracting directory doesn't work well.

Next, create a file with the following content:

     TOOLCHAIN_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
     SYSROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk
     make TARGET=ARMV8 BINARY=64 HOSTCC=clang CC="$TOOLCHAIN_PATH/clang -isysroot $SYSROOT_PATH -arch arm64" NOFORTRAN=1 libs

(again adjust the TOOLCHAIN_PATH and SYSROOT_PATH as necessary for your installation, e.g. change the version number of the SDK to what you have installed) and execute this file to build the library.

Note that ARMV8 is a generic implementation that should work on most arm64 hardware, for best performance try compiling with TARGET=CORTEXA57 or equivalent cpu-specific entry from TargetList.txt as appropriate for your hardware. Unfortunately it is unclear at the moment whether the Xcode assembler will accept the dialect used in the assembly files.