@@ -327,6 +327,163 @@ to what is provided by the C runtime libraries.
327327
328328` method` may be `auto`, `builtin` or `system`.
329329
330+ # # BLAS and LAPACK
331+
332+ *(numpy/meson#2)*
333+
334+ Enables compiling and linking against BLAS and LAPACK libraries. BLAS and
335+ LAPACK are generic APIs, which can be provided by a number of different
336+ implementations. It is possible to request either any implementation that
337+ provides the API, or a specific implementation like OpenBLAS or MKL.
338+ Furthermore, a preferred order may be specified, as well as the bitness (32 or
339+ 64) of the interface and whether to use the C or Fortran APIs.
340+
341+ Using the generic `'blas'` or `'lapack'` will try to find any matching
342+ implementation. The search order over implementations is not guaranteed; Meson
343+ aims to search them from higher to lower performance.
344+
345+ ` ` ` meson
346+ dependency('blas', interface : 'lp64', cblas : true)
347+ dependency('lapack', interface : 'ilp64', lapacke : false)
348+ ` ` `
349+
350+ Keywords :
351+ - `interface` : options are `lp64` for 32-bit LP64, and `ilp64` for 64-bit
352+ ILP64. Default is `lp64`.
353+ - `cblas` : ` true` or `false`. Default is `true`. (TBD: is `auto` needed?)
354+ - `lapacke` : ` true` or `false`. Default is `false`.
355+
356+ The search order can be controlled by explicitly specifying it :
357+
358+ ` ` ` meson
359+ # Specify what implementations to look for, and in what order
360+ blas_dep = dependency('accelerate', 'mkl', 'openblas', 'blis', 'atlas', 'netlib')
361+ lapack_dep = dependency('accelerate', 'mkl', 'openblas', 'atlas', 'netlib')
362+
363+ # You can also add the generic BLAS or LAPACK as a fallback, this may help
364+ # portability
365+ blas_dep = dependency('openblas', 'mkl', 'blis', 'netlib', 'blas')
366+ lapack_dep = dependency('openblas', 'mkl', 'atlas', 'netlib')
367+ ` ` `
368+
369+ Note that it is not necessary to specify both `'lapack'` and `'blas'` for the
370+ same build target, because LAPACK itself depends on BLAS. (TBD : is this okay
371+ for libflame?).
372+
373+
374+ # ## Specific BLAS and LAPACK implementations
375+
376+ # ### OpenBLAS
377+
378+ The `version` and `interface` keywords may be passed to request the use of a
379+ specific version and interface, correspondingly :
380+
381+ ` ` ` meson
382+ openblas_dep = dependency('openblas',
383+ version : '>=0.3.21',
384+ language: 'c', # can be c/cpp/fortran
385+ modules: [
386+ 'interface: ilp64', # can be lp64 or ilp64 (or auto?)
387+ 'symbol-suffix: 64_', # check/auto-detect? default to 64_ or no suffix?
388+ 'cblas',
389+ 'lapack', # OpenBLAS can be built without LAPACK support
390+ ]
391+ )
392+
393+ # Query properties as needed:
394+ has_cblas = openblas.get_variable('cblas')
395+ is_ilp64 = openblas_dep.get_variable('interface') == 'ilp64'
396+ blas_symbol_suffix = openblas_dep.get_variable('symbol-suffix')
397+ ` ` `
398+
399+ If OpenBLAS is installed in a nonstandard location *with* pkg-config files,
400+ you can set `PKG_CONFIG_PATH`. Alternatively, you can specify
401+ ` openblas_includedir` and `openblas_librarydir` in your native or cross machine
402+ file, this works also if OpenBLAS is installed *without* pkg-config files :
403+
404+ ` ` ` ini
405+ [properties]
406+ openblas_includedir = '/path/to/include_dir' # should contain openblas_config.h
407+ openblas_librarydir = '/path/to/library_dir'
408+ ` ` `
409+
410+ Note that OpenBLAS can be built with either pthreads or OpenMP. Information on
411+ this is not available through Meson.
412+
413+ # ### MKL
414+
415+ ` ` ` meson
416+ mkl_dep = dependency('mkl',
417+ version: '>=2021.1.0',
418+ modules: [
419+ interface: 'lp64', # options are 'lp64' or 'ilp64'
420+ threading: 'seq', # options are 'seq' or 'omp'
421+ library: 'dynamic', # options are 'dynamic' or 'static'
422+ ]
423+ )
424+ ` ` `
425+
426+ # ### Netlib BLAS and LAPACK
427+
428+ ` ` ` meson
429+ netlib_blas_dep = dependency('netlib-blas', version: '>=3.9.0')
430+ netlib_lapack_dep = dependency('netlib-lapack', version: '>=3.9.0')
431+ ` ` `
432+
433+ Note that this dependency will look for `libblas` or `liblapack`. No attempt is made
434+ to enforce that they're the original Netlib reference libraries; if another library
435+ is built with the same name, it's assumed that the APIs match.
436+
437+ TODO : the Netlib BLAS library typically ships CBLAS as a separate library and a separate
438+ cblas.pc file.
439+
440+
441+ # ### ArmPL
442+
443+ ` ` ` meson
444+ armpl_dep = dependency('armpl',
445+ version: '>=22.1',
446+ modules: [
447+ interface: 'lp64',
448+ threading: 'seq',
449+ library: 'dynamic',
450+ ]
451+ )
452+ ` ` `
453+
454+ The options for the `interface`, `threading` and `library` modules are the same
455+ as for MKL.
456+
457+
458+
459+ # ### ATLAS
460+
461+ TODO
462+
463+ # ### BLIS
464+
465+ TODO
466+
467+ # ## libflame
468+
469+ TODO
470+
471+ # ## Accelerate
472+
473+ Supports the BLAS and LAPACK components of macOS Accelerate, also referred to
474+ as the vecLib framework. ILP64 support is only available on macOS 13.3 and up.
475+ From macOS 13.3, Accelerate ships with two different builds of 32-bit (LP64)
476+ BLAS and LAPACK. Meson will default to the newer of those builds, by defining
477+ ` ACCELERATE_NEW_LAPACK` , unless `MACOS_DEPLOYMENT_TARGET` is set to a version
478+ lower than 13.3.
479+
480+ ` ` ` meson
481+ accelerate_dep = dependency('accelerate',
482+ version: '>818.60', # vecLib version (TODO: can this be determined?)
483+ modules: [interface: 'lp64']
484+ )
485+ ` ` `
486+
330487# # Blocks
331488
332489Enable support for Clang's blocks extension.
0 commit comments