scipy: DOC: linking to custom BLAS/LAPACK locations is not clear

Issue with current documentation:

I have tried to figure out how the meson (new) build system understands the linking stages for BLAS and LAPACK. But there seems to some missing points. Perhaps it is my ignorance in how meson understands flags etc.

So I want to build my own scipy and NOT use pip or conda. I also want to forcefully go away from using distutils (to be prepared for 3.12).

**scipy version: 1.10.1 **

I have tried to understand this page: https://docs.scipy.org/doc/scipy/dev/contributor/building_faq.html#how-do-i-use-a-custom-blas-distribution-on-linux

However, when trying to build with meson:

scipy/meson.build:135:0: ERROR: Dependency "OpenBLAS" not found, tried pkgconfig and cmake
 meson setup build-dir -Dblas=blis
The Meson build system
Version: 1.0.1
Source dir: /home/software/bash-build/.compile/py-3.11/scipy-1.10.1
Build dir: /home/software/bash-build/.compile/py-3.11/scipy-1.10.1/build-dir
Build type: native build
Project name: SciPy
Project version: 1.10.1
C compiler for the host machine: gcc (gcc 12.2.0 "gcc (GCC) 12.2.0")
C linker for the host machine: gcc ld.bfd 2.40
C++ compiler for the host machine: g++ (gcc 12.2.0 "g++ (GCC) 12.2.0")
C++ linker for the host machine: g++ ld.bfd 2.40
Cython compiler for the host machine: cython (cython 0.29.33)
Host machine cpu family: x86_64
Host machine cpu: x86_64
Compiler for C supports arguments -Wno-unused-but-set-variable: YES 
Compiler for C supports arguments -Wno-unused-function: YES 
Compiler for C supports arguments -Wno-conversion: YES 
Compiler for C supports arguments -Wno-misleading-indentation: YES 
Compiler for C supports arguments -Wno-incompatible-pointer-types: YES 
Library m found: YES
Fortran compiler for the host machine: gfortran (gcc 12.2.0 "GNU Fortran (GCC) 12.2.0")
Fortran linker for the host machine: gfortran ld.bfd 2.40
Compiler for Fortran supports arguments -Wno-conversion: YES 
Checking if "-Wl,--version-script" : links: YES 
Program cython found: YES (/opt/gnu/12.2.0/python/packages/3.11.2/cython/0.29.33/bin/cython)
Program python3 found: YES (/opt/gnu/12.2.0/python/3.11.2/bin/python3)
Found pkg-config: /opt/generic/build-tools/1.0/bin/pkg-config (1.9.4)
Program pythran found: YES (/opt/gnu/12.2.0/python/packages/3.11.2/pythran/0.12.1/bin/pythran)
Run-time dependency threads found: YES
Library npymath found: YES
Library npyrandom found: YES
Run-time dependency blis found: YES 0.9.0
Found CMake: /opt/generic/build-tools/1.0/bin/cmake (3.25.3)
WARNING: CMake Toolchain: Failed to determine CMake compilers state
Run-time dependency openblas found: NO (tried pkgconfig and cmake)
Run-time dependency openblas found: NO (tried pkgconfig and cmake)

scipy/meson.build:135:0: ERROR: Dependency "OpenBLAS" not found, tried pkgconfig and cmake

basically regardless of the blas=<> argument. Tried, default, none and blis (my actual library). The above is actually a bit misleading since users may think that this is the blas option which is not discovered, it is not, it is the lapack option.

I have lapack installed in a directory with no pc or cmake files. Is it possible to link that library to meson?

meson setup build-d -Dblas=blis -Dlapack=lapack
...
WARNING: CMake Toolchain: Failed to determine CMake compilers state
WARNING: CMake Toolchain: Failed to determine CMake compilers state
Run-time dependency lapack found: NO (tried pkgconfig and cmake)

scipy/meson.build:135:0: ERROR: Dependency "lapack" not found, tried pkgconfig and cmake

There is little documentation on how to bypass the dependency checking, and even with env-vars (not going to be supported: https://github.com/mesonbuild/meson/issues/9). The whole problem of fixing names for dependencies makes it difficult to customize the build. I.e. if -Dblas=<argument> where <argument> has the restriction that it must be a name that used via pkg-config, i.e. pkg-conf --libs <argument>. So it seems to me that I have to provide a manual *.pc file for customizing a library usage? Really? šŸ˜ž

I tried:

  • put everything in FC flags etc., but this also fails since the dependency is forcefully added regardless of whether linking can occur
  • put complete information in the -Dlapack='-L/path/to/lapack/... -llapack option, to no avail

python setup.py works but

I can get scipy to be installed using the regular setup.py installation, but that will use my numpy site.cfg which I am not keen on.

Idea or request for content:

It would be really valuable if the documentation showed how to link to a BLAS library located in a custom folder, without a pc file. That would show end-users how to play around with settings, and/or test various BLAS implementations (lets for now forget about flexiblas šŸ˜‰ ).

Additional context (e.g. screenshots, GIFs)

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

I’ll have a go at cleaning up the docs today. There’s also still a bunch of places with very detailed explanations on distutils usage; I’ll replace those with ā€œlook at examples in current meson.build filesā€.

We had a good discussion at the community meeting with both some new contributors and some old hands. The most popular idea was to replace the ā€œGetting Startedā€ tile on the front page of the docs (http://scipy.github.io/devdocs/), which is basically empty, with a dedicated ā€œBuilding from sourceā€ section. We’d then still have four tiles:

User guide                API reference

Building from source      Developer guide

I probably won’t get started on that this week, but it’d be good to hear any concerns with that plan.

You mean that we could have a page which is just the output of all help commands?

No, quite the opposite. This always goes out of date, as the current state of our docs shows. I want to explain the principle only, and then say something like ā€œfor any details on build options and how to use them, see dev.py build --helpā€.

or even discuss it during our next community meeting.

next community meeting sounds good to me

Related question to maintainers: should we clean the docs now? The ā€œadvanced Mesonā€ page is quite difficult to find, and the setup.py content basically is no longer relevant even though it’s still possible to trigger that build (but not via pip for example).

I totally see and feel the pain here, but if it helps: I’m quite confident we’re near the end of that very long tunnel. Most projects and all build tools (except Poetry, which will follow soon) have adopted PEP 517. For compiled code, everyone is dropping distutils/setuptools at a good pace, and we will have only two serious general-purpose build systems left: Meson/meson-python and CMake/scikit-build-core. Those are not that dissimilar and are even collaborating on design of UX and features.

Ok, I’ll try and adapt to scikit-build-core then. More work 😃

Could I suggest that the Note in https://docs.scipy.org/doc/scipy/dev/contributor/meson_advanced.html#select-a-different-blas-or-lapack-library is complimented by the filename of the pkg-config file and the resulting meson commandline for building it. It is relatively clear, but… 😃

Thanks for the suggestion! I’ll fix that. Also, I haven’t forgotten that you’re the author of part of the more advanced BLAS/LAPACK selection knobs in numpy.distutils (thanks again!). If I may ping you for a review of the docs/behavior of the like-for-like replacements in Meson once I’m done with those, it’d be great to get your input on that.

Happy to help. 😃
And yes, please do ping me!

Another thing, on the documentation pages it is not easy to go back and forth in the pages

Agreed, I want to fix this in one go with my proposed restructure above. The sidebar content will also be much more organized then.

Great!

It would also be nice to discuss how to change CFLAGS etc.

Thanks, I’ll add that. It should be included in Build types (debug/release builds, optimization levels, etc.)

For the basics:

* Meson understands all the most standard env vars, like `CC`, `FC`, `CFLAGS`, `LDFLAGS`

* It uses CLI flags for everything else, and those can be passed through `config_settings` when using `pip`/`build`

* When using `dev.py`, that level of customization is available only for the most commonly used things, e.g. `python dev.py build --werror --debug` does what you expect there (selects a debug build and passes `-Werror` in a compiler-independent way)
  
  * If you want to get fancy beyond what `dev.py build --help` shows, you can separately run `meson setup build <options-you-want>` followed by `dev.py build`. I'll admit that this is okay but not ideal, and it could benefit from a way to directly pass any flag through to `meson setup` (e.g., add `dev.py build --setup-arg <your-desired-arg-here>`).

Ok.

meson -Dc_args='-g' ... CFLAGS="-O3" python dev.py

I hope the above answer helps. I’ll note that you should not pass -g or -O3 like that with Meson, it has better CLI flags for this. You want to do it in one line ideally:

* what works right now is: `CFLAGS="-O3" python dev.py build --debug`

* what it should become is one of:
  
  * `python dev.py build --debug --optimization 3` (for an option like `-O3` that is common enough to have its own flag)
  * `python dev.py build --debug --setup-arg b_lto=true` (e.g., for enabling link-time-optimization, or any other [Meson build option](https://mesonbuild.com/Builtin-options.html#base-options))

Yes, this would be great to have! 😃
It was just a contrived example 😃

Don’t get me wrong I struggled to build scipy on windows for months and I’m supposed to be a maintainer. So I hope you don’t think I’m being dismissive. I really mean it when I say these are brand new tools we are dealing with and meson team was exceptionally receptive. This doesn’t mean that all is unicorns and rainbows.

Thanks for this sentiment. I am continuously struggling to find a path in the package nightmare of python. There are too many tools and too few standards… 😦 I know this isn’t easy and I can see this frustration across the Python community. I truly hope that the coming years will try to manage a more standardized approach, pep 517 + friends. And then meson + scikit-build and others are another layer of complexity. I am not blaming anybody, but I can just see that the obfuscation and very diverse avocations of different build-tools, ends up being a problem for the small dev’s who cannot figure out what is the endorsed approach.

However we have to start with a minimum number of assumptions to make sure certain things are, at least, in place. Then we would consoder the edge cases slowly.

Agreed!

Like I mentioned there are certain options in meson to achieve custom linking and dependencies but our tools are not ready yet. So it is instrumental that you fiddle with it too. Or someone who knows how to do it tells how it is. But we are not ready to document what’s allowed and what’s not.

Ok. I will do then. 😃

Let me note one thing about meson that is not clear for builders. Environment variables. One expects that env-vars are obeyed, CC, CFLAGS. Now meson is very particular here to never allowing env-vars. I understand their concerns and decisions, but perhaps this needs a clarification in the documentation (here as well). References: https://github.com/mesonbuild/meson/issues/9 and https://github.com/mesonbuild/meson/pull/2796 Yet, some of the flags are still read: https://github.com/mesonbuild/meson/issues/4664 Finding this in the documentation is not easy… 😦

I have tried to understand this page: https://docs.scipy.org/doc/scipy/dev/contributor/building_faq.html#how-do-i-use-a-custom-blas-distribution-on-linux

Could you please have a look at https://docs.scipy.org/doc/scipy/dev/contributor/meson_advanced.html#select-a-different-blas-or-lapack-library instead? That should be the right page, and I think it should answer your questions. If not, please point out the gaps and I’ll try to address them.

Yes, this is much better, thanks! Could I suggest that the Note in https://docs.scipy.org/doc/scipy/dev/contributor/meson_advanced.html#select-a-different-blas-or-lapack-library is complimented by the filename of the pkg-config file and the resulting meson commandline for building it. It is relatively clear, but… 😃

Another thing, on the documentation pages it is not easy to go back and forth in the pages. For instance, if I just follow your link to the advanced meson page, I cannot easily find this https://docs.scipy.org/doc/scipy/dev/contributor/meson.html, no links to that page? And vice-versa. No link from the simple -> advanced. There is only an ā€œon this pageā€ in the right block.

It seems to me that the section structure is missing, somehow? (this is a generic problem I think)

Unfortunately we have two sets of build docs right now - we’ll get rid of the setup.py related ones very soon; hopefully it’ll be easier to find then.

That would be great! The older versions documentations still works, so one could link to prior versions documentations in a simple statement where it is then much clearer that it is deprecated. Basically what @tupul said 😃

Fixing this up completely is a little messy. I’m going to simplify the ā€œbuild from sourceā€ docs a lot. We’ve got the same instructions (or different variants) in about ten different places. The ā€œsystem-level dependenciesā€ part is quite nice, and then it goes downhill quickly. I’m going to get rid of the ā€œthis is Meson, and here is how it compares to the old thingā€ parts too. We can simplify it down to:

1. System dependencies and how to install them (already in good shape)

2. Install from source for production with `pip` or local development with `dev.py` (already in good shape too)

3. Relevant build customizations users may need:


* BLAS/LAPACK selection

* Compiler selection

* Build types (debug/release builds, optimization levels, etc.)

* Controlling the Fortran ABI used

* Cross compilation


4. Info for packagers/redistributors

5. Background content on how Meson works and FAQ entries (trim that down, but some stuff is relevant)

There is very little of use left in the macOS/Windows/Ubuntu/Conda parts, once the ā€œsystem dependenciesā€ part is done, everything else is effectively the same.

It would also be nice to discuss how to change CFLAGS etc. It is not clear to me whether the CFLAGS from meson build-setup or from the dev.py file are used. So if I do:

meson -Dc_args='-g' ...
CFLAGS="-O3" python dev.py ...

what would happen where?

Thanks for all of the discussion!