homebrew-core icon indicating copy to clipboard operation
homebrew-core copied to clipboard

openblas: use `cmake` and depend on `libomp`

Open ywwry66 opened this issue 7 months ago • 8 comments

  • [x] Have you followed the guidelines for contributing?
  • [x] Have you ensured that your commits follow the commit style guide?
  • [x] Have you checked that there aren't other open pull requests for the same formula update/change?
  • [x] Have you built your formula locally with HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • [x] Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • [x] Does your build pass brew audit --strict <formula> (after doing HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

Related to #209091, #129648, #129100. Upstream has added support for buiding with libomp through https://github.com/OpenMathLib/OpenBLAS/pull/5180, where one can also find multiple issues linked from downstream repositories that are caused by Homebrew's handling of OpenMP for OpenBLAS.

This change requires dependents of OpenBLAS also switched to libomp. For gromacs, cp2k and fftw, the switch seems relatively straightforward. However, I am not sure how to go about dynare. Currently, dynare is directly linked to libgomp and it also pulls in libomp through suite-sparse.

ywwry66 avatar Apr 11 '25 03:04 ywwry66

fatal error: posix_spawnp: Argument list too long

ywwry66 avatar Apr 11 '25 05:04 ywwry66

The failures on macOS 15-arm64 can be reproduced on my Sequoia macbook with the current OpenBLAS bottle, so they are not related to this PR.

  1. arpack: Minitest::Assertion: Expected /reached/ to match " ** On entry to DLASCL parameter number 4 had an illegal value\n ** On entry to DLASCL parameter number 4 had an illegal value\n \n Error with _naupd, info = -9999\n Check the documentation of _naupd\n \n". (https://github.com/opencollab/arpack-ng/issues/469)
  2. ~mlpack: /opt/homebrew/include/cereal/types/tuple.hpp:98:41: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw] (https://github.com/USCiLab/cereal/pull/835)~

~There is an error I didn't see before:~

  • ~shtools: make: *** [run-fortran-tests-no-timing] Error 137 (GH Runner out of memory? Cannot reproduce locally.)~

ywwry66 avatar Apr 20 '25 02:04 ywwry66

Should switching to libomp for dependents be done in this same PR or in separate PRs?

ywwry66 avatar Apr 23 '25 05:04 ywwry66

fftw's makefile does not support libomp directly, and its cmake system is not feature complete, e.g., no mpi support. Changes to cmake were not very well received upstream. So I am not sure how to proceed here. Ping @carlocab and @cho-m for suggestions.

ywwry66 avatar Apr 25 '25 22:04 ywwry66

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar May 17 '25 00:05 github-actions[bot]

Keep the PR open for now.

ywwry66 avatar May 19 '25 01:05 ywwry66

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Jun 09 '25 01:06 github-actions[bot]

probably worth a rebase after https://github.com/Homebrew/homebrew-core/pull/224410

chenrui333 avatar Jun 09 '25 05:06 chenrui333

fftw's makefile does not support libomp directly, and its cmake system is not feature complete, e.g., no mpi support. Changes to cmake were not very well received upstream. So I am not sure how to proceed here. Ping @carlocab and @cho-m for suggestions.

can you post more about fftw issue?

dimpase avatar Jul 16 '25 04:07 dimpase

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Aug 06 '25 12:08 github-actions[bot]

ping?

dimpase avatar Aug 06 '25 15:08 dimpase

fftw's makefile does not support libomp directly, and its cmake system is not feature complete, e.g., no mpi support. Changes to cmake were not very well received upstream. So I am not sure how to proceed here. Ping @carlocab and @cho-m for suggestions.

You could try autotools workaround of setting flags manually, e.g. maybe via OPENMP_CFLAGS and LIBS? https://github.com/FFTW/fftw3/blob/master/m4/ax_openmp.m4#L24-L25

I can't guarantee binary works as expected; however, these types of workarounds are common in other formulae, e.g.

https://github.com/Homebrew/homebrew-core/blob/03e68e13043c68af740de499f37074c0d680b576/Formula/f/fastme.rb#L35-L36

https://github.com/Homebrew/homebrew-core/blob/03e68e13043c68af740de499f37074c0d680b576/Formula/i/imagemagick.rb#L92-L94

cho-m avatar Aug 06 '25 21:08 cho-m

Added some workarounds for dependents. Not ideal though, e.g.

  • fftw will overlink to libomp. Shouldn't impact functionality and loading overhead should be minor but would be better to only have the _omp dylibs linked
  • dynare needs some patching to build as Meson doesn't allow using GCC with OpenMP. And dynare cannot be built with LLVM/Clang due to https://github.com/llvm/llvm-project/issues/33025

Would likely need further testing to make sure the OpenMP support is actually functional.

cho-m avatar Aug 15 '25 14:08 cho-m

Will need to rebase for gromacs. Also will split out some unrelated changes to make easier to review.

cho-m avatar Aug 30 '25 14:08 cho-m

Just a word of caution: the OpenBLAS upstream is considering reverting the change that has added and streamlined OpenMP customization enabled by cmake's built-in module (ref. https://github.com/OpenMathLib/OpenBLAS/pull/5413). If that is merged, it will also invalidate this PR, at least in its current form.

ywwry66 avatar Aug 31 '25 05:08 ywwry66

A Makefile workaround could be:

# Workaround to use OpenMP with Apple Clang
if ENV.compiler == :clang
  inreplace "Makefile.system", "+= -fopenmp", "+= -Xpreprocessor -fopenmp"
  inreplace "Makefile.install" do |s|
    s.gsub! ":= -fopenmp", ":= -Xpreprocessor -fopenmp"
    s.gsub! "+= -lgomp", "+= -L#{Formula["libomp"].opt_lib} -lomp"
  end
end

Can't comment if this functionally behaves as expected. But at least no mixed linkage

❯ brew linkage openblas
System libraries:
  /usr/lib/libSystem.B.dylib
Homebrew libraries:
  /opt/homebrew/opt/gcc/lib/gcc/current/libgfortran.5.dylib (gcc)
  /opt/homebrew/opt/gcc/lib/gcc/current/libquadmath.0.dylib (gcc)
  /opt/homebrew/opt/libomp/lib/libomp.dylib (libomp)
❯ PKG_CONFIG_PATH=/opt/homebrew/opt/openblas/lib/pkgconfig pkgconf --cflags openblas
-I/opt/homebrew/Cellar/openblas/0.3.30/include -Xpreprocessor -fopenmp

❯ PKG_CONFIG_PATH=/opt/homebrew/opt/openblas/lib/pkgconfig pkgconf --libs openblas
-L/opt/homebrew/Cellar/openblas/0.3.30/lib -lopenblas

❯ PKG_CONFIG_PATH=/opt/homebrew/opt/openblas/lib/pkgconfig pkgconf --libs --static openblas
-L/opt/homebrew/Cellar/openblas/0.3.30/lib -lopenblas -lpthread -lgfortran -lpthread -lgfortran -L/opt/homebrew/opt/libomp/lib -lomp

cho-m avatar Aug 31 '25 14:08 cho-m

Experimenting with Makefile alternative in

  • #236492

cho-m avatar Sep 07 '25 14:09 cho-m

I am trying to keep the upstream cmake improvements from being reverted so hopefully we don't need the Makefile alternative.

BTW, does the arrayfire test failure on Linux X86_64 need to be addressed?

ywwry66 avatar Sep 07 '25 15:09 ywwry66

BTW, does the arrayfire test failure on Linux X86_64 need to be addressed?

  • already fixed #235676

Also noting that I will be updating openblas test in separate PR to run cpp_thread_test to verify OpenMP is still functional:

  • #236505

cho-m avatar Sep 07 '25 19:09 cho-m

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Sep 28 '25 21:09 github-actions[bot]

is it still being worked on?

dimpase avatar Sep 28 '25 23:09 dimpase

is it still being worked on?

We first need confirmation that upstream won't revert CMake changes.

Afterward will need to decide if the odd quirks this can introduce are worth the change.

cho-m avatar Sep 29 '25 00:09 cho-m

We can revisit this once upstream makes a decision.

p-linnane avatar Nov 04 '25 00:11 p-linnane