Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pkg-config for OpenBLAS #1778

Merged
merged 5 commits into from Mar 29, 2024

Conversation

przemoc
Copy link
Contributor

@przemoc przemoc commented Jan 17, 2024

Information can be found in commit messages. There are various tweaks done along the way.
Makefile changes are simpler. CMakeLists.txt changes are a bit more complex.

This may not be perfect, but overall should be a noticeable improvement over what we had before regarding OpenBLAS handling.
OPENBLAS_PATH remains supported. BLAS_HOME is no longer supported. I don't believe in kitchen sink approach to support any possible ad hoc conventions created out there. As long as we expose sufficient knobs to control build process, downstream can adapt appropriately.

Most likely some CI checks will fail. Will try to fix it some other day. MacOS may blow up as usual.
(My CMake experience is small, and the more I learn about it, the less I like it. And I do not want to rewrite some of the batteries they provide...).

I will also appreciate some testing. I did limited testing in one of MSYS2 environments (UCRT64), Alpine Linux 3.18.5 (w/ WHISPER_OPENBLAS_INTERFACE64=0), Ubuntu 22.04.


It's not clear to me if WHISPER_OPENBLAS_INTERFACE64 should be really enabled by default, I just followed existing intention expressed via set(BLA_SIZEOF_INTEGER 8). I think having it disabled (using OpenBLAS w/ 32-bit interface) would be a better out of the box experience for most folks out there, but maybe I'm missing something?

Another thing, that I definitely do not intend to address in this PR, is support for OpenBLAS built w/ SYMBOLSUFFIX=64_, which I have not yet researched how it should be dealt. That's also a reason why OpenBLAS w/ 32-bit interface is a "safer" choice by default.

@przemoc
Copy link
Contributor Author

przemoc commented Jan 17, 2024

Capturing logs from failing steps in Windows builds for further analysis on some other day (as I don't know log retention policies here):

windows-blas (Release, Win32, ON, ON) (pull_request)

Configure
Run cmake -S . -B ./build -A Win32 -DCMAKE_BUILD_TYPE=Release -DWHISPER_OPENBLAS=ON -DCMAKE_LIBRARY_PATH="$env:OPENBLAS_PATH/lib" -DWHISPER_SDL2=ON -DWHISPER_CLBLAST=OFF
  cmake -S . -B ./build -A Win32 -DCMAKE_BUILD_TYPE=Release -DWHISPER_OPENBLAS=ON -DCMAKE_LIBRARY_PATH="$env:OPENBLAS_PATH/lib" -DWHISPER_SDL2=ON -DWHISPER_CLBLAST=OFF
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    ubuntu_image: ubuntu:22.04
    OPENBLAS_PATH: D:\a\whisper.cpp\whisper.cpp/blas
    SDL2_DIR: D:\a\whisper.cpp\whisper.cpp/SDL2-2.28.5/cmake
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.37.32826.1
-- The CXX compiler identification is MSVC 19.37.32826.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/bin/HostX64/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/bin/HostX64/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/bin/git.exe (found version "2.43.0.windows.1") 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE  
-- BLAS compatible library path provided
-- Libraries D:\a\whisper.cpp\whisper.cpp/blas/lib/openblas64.lib
-- Include dirs D:\a\whisper.cpp\whisper.cpp/blas/include
CMake Error at CMakeLists.txt:207 (message):
  BLAS library was not found.  Environment variable OPENBLAS_PATH misdefined.


-- Configuring incomplete, errors occurred!
Error: Process completed with exit code 1.
-- BLAS compatible library path provided
-- Libraries D:\a\whisper.cpp\whisper.cpp/blas/lib/openblas64.lib
-- Include dirs D:\a\whisper.cpp\whisper.cpp/blas/include
CMake Error at CMakeLists.txt:207 (message):
  BLAS library was not found.  Environment variable OPENBLAS_PATH misdefined.

windows-blas (Release, x64, ON, ON) (pull_request)

Configure
Run cmake -S . -B ./build -A x64 -DCMAKE_BUILD_TYPE=Release -DWHISPER_OPENBLAS=ON -DCMAKE_LIBRARY_PATH="$env:OPENBLAS_PATH/lib" -DWHISPER_SDL2=ON -DWHISPER_CLBLAST=ON
  cmake -S . -B ./build -A x64 -DCMAKE_BUILD_TYPE=Release -DWHISPER_OPENBLAS=ON -DCMAKE_LIBRARY_PATH="$env:OPENBLAS_PATH/lib" -DWHISPER_SDL2=ON -DWHISPER_CLBLAST=ON
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    ubuntu_image: ubuntu:22.04
    OPENBLAS_PATH: D:\a\whisper.cpp\whisper.cpp/blas
    SDL2_DIR: D:\a\whisper.cpp\whisper.cpp/SDL2-2.28.5/cmake
    CLBlast_DIR: D:\a\whisper.cpp\whisper.cpp/CLBlast-1.6.1-windows-x64/lib/cmake/CLBlast
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.37.32826.1
-- The CXX compiler identification is MSVC 19.37.32826.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/bin/HostX64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/bin/HostX64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/bin/git.exe (found version "2.43.0.windows.1") 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE  
-- BLAS compatible library path provided
-- Libraries D:\a\whisper.cpp\whisper.cpp/blas/lib/openblas64.lib
-- Include dirs D:\a\whisper.cpp\whisper.cpp/blas/include
CMake Error at CMakeLists.txt:207 (message):
  BLAS library was not found.  Environment variable OPENBLAS_PATH misdefined.


-- Configuring incomplete, errors occurred!
Error: Process completed with exit code 1.
-- BLAS compatible library path provided
-- Libraries D:\a\whisper.cpp\whisper.cpp/blas/lib/openblas64.lib
-- Include dirs D:\a\whisper.cpp\whisper.cpp/blas/include
CMake Error at CMakeLists.txt:207 (message):
  BLAS library was not found.  Environment variable OPENBLAS_PATH misdefined.

Passing builds from recent commit 1f50a7d have:

-- Libraries D:\a\whisper.cpp\whisper.cpp/blas/lib/libopenblas.dll.a

(before this PR there were fewer things messaged related to OpenBLAS)

which makes me wonder what, where and how is built for Windows, because AFAIK .dll.a is not a native Windows thing (MSYS2 environments are closer to *nix than Windows, so .dll.a would be fine there). I may need to analyze environment setup steps in CI to better understand what's going on. I hope to be able to do that without MS tools (but in the worst case I may end up polluting my Windows by installing Visual Studio for the first time since ~20y or so).

Maybe some tweaks in CI config / workflow steps or actions will be also necessary to clean things up. Hard to tell at this stage.

@ggerganov
Copy link
Owner

Thanks for looking into this! I don't have access to Windows systems, so I won't be able to provide much help about the build process. But let me know if you hit any roadblocks along the way

@tamo
Copy link
Contributor

tamo commented Jan 20, 2024

which makes me wonder what, where and how is built for Windows, because AFAIK .dll.a is not a native Windows thing (MSYS2 environments are closer to *nix than Windows, so .dll.a would be fine there). I may need to analyze environment setup steps in CI to better understand what's going on. I hope to be able to do that without MS tools (but in the worst case I may end up polluting my Windows by installing Visual Studio for the first time since ~20y or so).

build.yml uses a downloaded openblas, which has libopenblas.dll.a.
It seems that the pre-compiled openblas is built with MSYS2: https://github.com/OpenMathLib/OpenBLAS/blob/develop/.github/workflows/dynamic_arch.yml

Our current build.yml doesn't use MSYS2, so our LIB_SUFFIX/PREFIX are different from those of openblas.
https://github.com/przemoc/whisper.cpp/blob/f010a92eedbd467b9af7bf1a3f72f39f1fcb31d0/CMakeLists.txt#L197-L202

                set(WHISPER_BLAS_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
                set(WHISPER_BLAS_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
            endif ()
        endif ()
        message(STATUS "BLAS compatible library path provided")
        set(BLAS_LIBRARIES "$ENV{OPENBLAS_PATH}/lib/${WHISPER_BLAS_LIB_PREFIX}${WHISPER_BLAS_LIB}${WHISPER_BLAS_LIB_SUFFIX}")

Maybe we shouldn't use such PREFIX/SUFFIX.

Or maybe we should set BLAS_LIBRARIES only when find_package(BLAS) fails, because BLAS_LIBRARIES is listed in "Result Variables" on https://cmake.org/cmake/help/latest/module/FindBLAS.html
I suppose that the correct way is to input "Input Variables", run find_package(BLAS), and check "Result Variables"

edit: Reading through the CMakeLists.txt, I guess OPENBLAS_PATH is for bypassing pkg-config, so we can safely hardcode filenames according to the distributed zips if OPENBLAS_PATH is set.

@przemoc
Copy link
Contributor Author

przemoc commented Jan 20, 2024

Sure, @ggerganov, appreciated!

@tamo, thank you for useful pointers and your PR (przemoc/pull/1) with suggested changes to my PR. Your changes seem to be overfit for particular environment and assumptions regarding OpenBLAS (similar sin that is present in whisper.cpp nowadays until my PR will improve that).

I didn't have time yet to investigate Windows build process in whisper.cpp and OpenBLAS builds, but just wanted to reply now regardless.

It's a shame if OpenBLAS really does use only MSYS2 and does not provide MSVC-based builds. Mixing MSVC and non-MSVC binaries is literally asking for trouble. It was true for msvcrt-based MinGW / MinGW-w64 and I suspect it's true for ucrt-based MinGW-w64. Well, at least for GCC, as CLANG actually aims for MSVC compatibility, so it's safer to mix MSVC and CLANG binaries on Windows.

OpenBLAS's CI configuration does not necessarily reflect how assets added to releases are built, though. In workflows they build using both UCRT64 and CLANG64 (among other variants), but in each .zip file there is only one .dll, and it's not clear from which compiler it comes from. Maybe it's from MSVC after all? In CI they build with both BINARY64=1 and INTERFACE64=1 in UCRT64 and CLANG64.

x64-64 started being provided in OpenBLAS v0.3.25. OpenBLAS prebuilt binaries variants are:

  • x86 - 32-bit build
  • x64 - 64-bit build
  • x64-64 - 64-bit build with INTERFACE64=1
    (USE_64BITINT=1 exposed in openblas_config.h via empty define OPENBLAS_USE64BITINT)

(surprisingly I didn't find anywhere clear information that I provided above, had to dig into differences between .zip files)

What is also sad is that their variants do not differ by any suffix for actual library, which is called libopenblas.dll in all cases. :( I was not aware of that. This means that using OpenBLAS prebuilt binaries may require extra logic vs rest of the world, i.e. *nix (including MSYS2 environments, where libopenblas.so and libopenblas64.so can coexist).

And those .zip files have both *nix-like libopenblas.a and "hybrid" libopenblas.dll.a, but also libopenblas.lib (I checked only filenames, have not analyzed their content), so revising whisper.cpp environment setup may be what's necessary here too.

My PR is meant to make stuff work in native Windows (MSVC), MSYS2 environment, and *nix, at least to the extent possible by what CMake provides (versus make that by convention is meant for *nix-like environments only, so don't have to bother with MSVC). MSYS2 started working with my changes, but I broke MSVC builds due to not spending any time with them and not being familiar with existing whisper.cpp build flow for Windows.

Regarding prefix, if everyone in Windows world builds OpenBLAS with lib in front (which is not common for libraries in Windows) - to be investigated, then prefix for library can be hardcoded to lib.

Regarding suffix, they are different between MSVC, MSYS2 and *nix, so we cannot get rid of it.

Regarding FindBLAS, I already looked into it back then, and left various comments regarding it in the code.

IMHO CMake is not a good build solution, users are inclined to use its batteries, but they seem to be not well-maintained, and if you happen to have older CMake, which may have older versions of the modules, you're even more screwed. But it's unrealistic to expect anyone to support various CMake versions with varying degree of features their modules provide...


After spending as little time as necessary for writing this comment and glancing at OpenBLAS .zip files (and not really researching anything more yet), I think PR fails right now for Windows using CMake due to:

  • not hardcoding lib prefix for OpenBLAS library
    (OpenBLAS prebuilt binaries deviate from native Windows conventions, which normally do not have prefixes for libraries)
  • not hardcoding WHISPER_BLAS_LIB=openblas for MSVC
    (it has to be openblas regardless of INTERFACE64 setting for OpenBLAS prebuilt binaries)
  • defaulting to WHISPER_OPENBLAS_INTERFACE64=on
    (whisper.cpp is build with x86 and x64 OpenBLAS variants only)

I will do some quick fixes to address those issues, but even if the build will successfully pass, please do not merge it yet, as I may need to think about it more whether we're achieving LGTM state where potential further tweaks can be done via separate PRs, or if some basic tweaks still need to be done before merging.

@tamo
Copy link
Contributor

tamo commented Jan 20, 2024

Completely agreed.

@przemoc przemoc force-pushed the use-pkg-config-for-openblas branch from fa9dfc9 to 5b845f4 Compare March 22, 2024 13:57
@przemoc
Copy link
Contributor Author

przemoc commented Mar 22, 2024

Rebased and resolved minor merge conflict. No other changes.

Sorry for letting it rot for 2 months. To be honest, I was not pondering more on the PR during this timeframe.
I won't claim PR is perfect, there may be some corner cases I am not aware of, but it seems we have mostly sufficient knobs exposed that folks can tweak their build options to achieve desired outcome (commit messages may be helpful for them).

I do think it is a step up over what we currently have in whisper.cpp, so I would suggest to merge it unless there are some particular concerns. In the worst case it can be always improved later via another PR.

@przemoc
Copy link
Contributor Author

przemoc commented Mar 22, 2024

Looks like GH checks are somehow stuck.
@ggerganov, is it something you're able to poke to make it run properly?

That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.

Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled.  Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N).  make is not CMake.

By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.

If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.

If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`).  If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.

Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
…ries needed by OpenBLAS

That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.

Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.

By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.

Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.

Get rid of supporting BLAS_HOME environment variable.  If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
@przemoc przemoc force-pushed the use-pkg-config-for-openblas branch from 5b845f4 to b6ee38b Compare March 29, 2024 12:09
@przemoc
Copy link
Contributor Author

przemoc commented Mar 29, 2024

Rebased and resolved minor merge conflict.

@ggerganov ggerganov merged commit 1e8f28c into ggerganov:master Mar 29, 2024
47 checks passed
@przemoc przemoc deleted the use-pkg-config-for-openblas branch April 12, 2024 16:28
jiahansu pushed a commit to OOPRY/whisper.cpp that referenced this pull request Apr 17, 2024
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS

That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.

Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled.  Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N).  make is not CMake.

By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.

If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.

If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`).  If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.

Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.

* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS

That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.

Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.

By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.

Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.

Get rid of supporting BLAS_HOME environment variable.  If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.

* make / cmake : use OpenBLAS with 32-bit interface by default.

OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.

* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)

* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)

Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
viktor-silakov pushed a commit to viktor-silakov/whisper_node_mic.cpp that referenced this pull request May 11, 2024
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS

That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.

Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled.  Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N).  make is not CMake.

By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.

If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.

If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`).  If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.

Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.

* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS

That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.

Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.

By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.

Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.

Get rid of supporting BLAS_HOME environment variable.  If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.

* make / cmake : use OpenBLAS with 32-bit interface by default.

OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.

* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)

* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)

Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants