-
Notifications
You must be signed in to change notification settings - Fork 1.5k
How to build OpenBLAS for Windows on ARM64
This page describes how to natively build OpenBLAS library for windows on arm64 targets.
See below for how to cross-compile OpenBLAS for WoA on an x86_64 Windows host.
While OpenBLAS can be built with Microsoft VisualStudio (Community Edition or commercial), you would only be able to build for the GENERIC target that does not use optimized assembly kernels, also the stock VisualStudio lacks the Fortran compiler necessary for building the LAPACK component. It is therefore highly recommended to download the free LLVM compiler suite and use it to compile OpenBLAS outside of VisualStudio.
a working installation of LLVM for Windows on Arm
Find the latest LLVM build for WoA on the LLVM release page - you want the package whose name ends in "woa64.exe". (This may not always be present in the very latest point release as it takes time to build and upload binaries.) E.g: The LLVM 19 build for WoA64 can be found here.
Run the LLVM installer and ensure that LLVM is added to the environment variable PATH. (If you do not want to add it to the PATH, you will need to specify both the C and Fortran compiler to Make or CMake with their full path later on)
The following steps describe how to build the static library for OpenBLAS with either Make or CMake:
- Build OpenBLAS with Make:
$ make CC=clang-cl FC=flang-new AR="llvm-ar" TARGET=ARMV8 ARCH=arm64 RANLIB="llvm-ranlib" MAKE=make
or 2. Build OpenBLAS with CMake:
$ mkdir build
$ cd build
$ cmake .. -G Ninja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang-new -DTARGET=ARMV8 -DCMAKE_BUILD_TYPE=Release
$ cmake --build .
a working installation of LLVM and Ninja (the versions included in the latest Visual Studio 2022 will do, if you install its optional Llvm.Clang component)
-
Load into the appropriate cross compiling developer shell (in this case powershell, for cmd.exe it would be vcvarsamd64_arm64.bat): 'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\Launch-VsDevShell.ps1' -Arch arm64 -HostArch amd64
-
Change to the folder where you unpacked the OpenBLAS sources if you haven't already, and create a subfolder for building. Then change into that folder.
-
Invoke the following CMake command
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DTARGET=ARMV8 -DCMAKE_CROSSCOMPILING=ON -DCMAKE_SYSTEM_NAME="Windows" -DARCH=arm -DBINARY=64 -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_C_COMPILER_TARGET=arm64-pc-windows-msvc -DCMAKE_ASM_COMPILER_TARGET=arm64-pc-windows-msvc.
(Note the use of clang-cl instead of clang, and adding in the _COMPILER_TARGET entries. Without C_COMPILER_TARGET, clang-cl will be trying to compile x64 machine code and not make it past the cmake generation step. Without ASM_COMPILER_TARGET the assembly files in openblas will fail to assemble because the assembler is trying to interpret them as x64 assembly.)
-
Invoke Ninja for the actual compilation