{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "building:blas_lapack",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "BLAS and LAPACK"
        }
      ],
      "level": 0,
      "target": "building-blas-and-lapack"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When a NumPy build is invoked, BLAS and LAPACK library detection happens automatically. The build system will attempt to locate a suitable library, and try a number of known libraries in a certain order - most to least performant. A typical order is: MKL, Accelerate, OpenBLAS, FlexiBLAS, BLIS, plain "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "libblas"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "/"
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "liblapack"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This may vary per platform or over releases. That order, and which libraries are tried, can be changed through the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "blas-order"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lapack-order"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " build options, for example      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "$ python -m pip install . -Csetup-args=-Dblas-order=openblas,mkl,blis -Csetup-args=-Dlapack-order=openblas,mkl,lapack",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The first suitable library that is found will be used. In case no suitable library is found, the NumPy build will print a warning and then use (slow!) NumPy-internal fallback routines. In order to disallow use of those slow routines, the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "allow-noblas"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " build option can be used      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "$ python -m pip install . -Csetup-args=-Dallow-noblas=false",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default the LP64 (32-bit integer) interface to BLAS and LAPACK will be used. For building against the ILP64 (64-bit integer) interface, one must use the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "use-ilp64"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " build option      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "$ python -m pip install . -Csetup-args=-Duse-ilp64=true",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Default behavior for BLAS and LAPACK selection"
        }
      ],
      "level": 1,
      "target": "blas-lapack-selection"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "blas"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lapack"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " build options are set to \"auto\" by default, which means trying all known libraries. If you want to use a specific library, you can set these build options to the library name (typically the lower-case name that "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pkg-config"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " expects). For example, to select plain "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "libblas"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "liblapack"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (this is typically Netlib BLAS/LAPACK on Linux distros, and can be dynamically switched between implementations on conda-forge), use      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "$ # for a development build\n$ spin build -C-Dblas=blas -C-Dlapack=lapack\n\n$ # to build and install a wheel\n$ python -m build -Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack\n$ pip install dist/numpy*.whl\n\n$ # Or, with pip>=23.1, this works too:\n$ python -m pip install . -Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Other options that should work (as long as they're installed with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pkg-config"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " support; otherwise they may still be detected but things are inherently more fragile) include "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "openblas"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "mkl"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "accelerate"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "atlas"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "blis"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Selecting specific BLAS and LAPACK libraries"
        }
      ],
      "level": 1,
      "target": "accelerated-blas-lapack-libraries"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The way BLAS and LAPACK detection works under the hood is that Meson tries to discover the specified libraries first with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pkg-config"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and then with CMake. If all you have is a standalone shared library file (e.g., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "armpl_lp64.so"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "/a/random/path/lib/"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a corresponding header file in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "/a/random/path/include/"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), then what you have to do is craft your own pkg-config file. It should have a matching name (so in this example, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "armpl_lp64.pc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") and may be located anywhere. The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "PKG_CONFIG_PATH"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " environment variable should be set to point to the location of the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".pc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file. The contents of that file should be      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "libdir=/path/to/library-dir      # e.g., /a/random/path/lib\nincludedir=/path/to/include-dir  # e.g., /a/random/path/include\nversion=1.2.3                    # set to actual version\nextralib=-lm -lpthread -lgfortran   # if needed, the flags to link in dependencies\nName: armpl_lp64\nDescription: ArmPL - Arm Performance Libraries\nVersion: ${version}\nLibs: -L${libdir} -larmpl_lp64      # linker flags\nLibs.private: ${extralib}\nCflags: -I${includedir}",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To check that this works as expected, you should be able to run      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "$ pkg-config --libs armpl_lp64\n-L/path/to/library-dir -larmpl_lp64\n$ pkg-config --cflags armpl_lp64\n-I/path/to/include-dir",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Using pkg-config to detect libraries in a nonstandard location"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "BLAS and LAPACK are complex dependencies. Some libraries have more options that are exposed via build options (see "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "meson.options"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the root of the repo for all of NumPy's build options)."
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "blas"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": name of the BLAS library to use (default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "auto"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lapack"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": name of the LAPACK library to use (default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "auto"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "allow-noblas"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": whether or not to allow building without external   BLAS/LAPACK libraries (default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "true"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "blas-order"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": order of BLAS libraries to try detecting (default may vary per platform),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lapack-order"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": order of LAPACK libraries to try detecting,"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "use-ilp64"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": whether to use the ILP64 interface (default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "false"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "blas-symbol-suffix"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": the symbol suffix to use for the detected libraries (default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "auto"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "mkl-threading"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ": which MKL threading layer to use, one of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "seq"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "iomp"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "gomp"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "tbb"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "auto"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ")."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Full list of BLAS and LAPACK related build options"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}