Skip to content

Commit

Permalink
Merge pull request #15 from ev-br/master
Browse files Browse the repository at this point in the history
Use 64-bit LAPACK
  • Loading branch information
ev-br authored Sep 10, 2024
2 parents 06963b0 + ac0fc6b commit 54b07c1
Show file tree
Hide file tree
Showing 30 changed files with 1,315 additions and 3,267 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/linux.meson.pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Linux pypi openblas64

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test_meson:
name: build and run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
numpy-version: ["", "==1.26.4", "==1.24.4", "==1.22.4"]

steps:
- uses: actions/[email protected]
with:
submodules: recursive

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Build and test gulinalg
shell: bash -l {0}
run: |
pip install numpy meson meson-python ninja scipy-openblas64
# pkg-config
python -c'import scipy_openblas64 as sc; print(sc.get_pkg_config())' > openblas.pc
export PKG_CONFIG_PATH=$PWD
echo "\n OpenBLAS PKG-CONFIG FILE\n"
cat openblas.pc
pip install . -Csetup-args="-Dopenmp=gnu" -Csetup-args="-Dblas=scipy-openblas64" --no-build-isolation -v
# test
pip install numpy${{ matrix.numpy-version }}
cd /tmp
export OMP_NUM_THREADS=2
python -c'import numpy; print(f"{numpy.__version__ = }")'
python -c'import gulinalg as g; g.test(verbosity=2)'
55 changes: 55 additions & 0 deletions .github/workflows/linux.meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Linux conda MKL

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test_meson:
name: build and run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
numpy-version: ["", "==1.26.4", "==1.24.4", "==1.22.4"]

steps:
- uses: actions/[email protected]
with:
submodules: recursive

- name: Setup Conda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
channels: conda-forge
channel-priority: true
activate-environment: gulinalg
use-only-tar-bz2: false
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true

- name: Update Conda Environment
run: mamba env update -n gulinalg -f environment.yml

- name: Build and test gulinalg
shell: bash -l {0}
run: |
conda activate gulinalg
pip install numpy meson meson-python ninja mkl mkl-devel
mamba list
# build
pip install . --no-build-isolation -v -Csetup-args="-Dopenmp=gnu" -Csetup-args="-Dblas=mkl"
# test
pip install numpy${{ matrix.numpy-version }}
cd /tmp
python -c'import numpy; print(f"{numpy.__version__ = }")'
OMP_NUM_THREADS=2 python -c'import gulinalg as g; g.test(verbosity=2)'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
*.dylib
*.pyd
*.pdb
build/
build/
build-install
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,66 @@
gulinalg
gulinalg
========

Linear algebra functions as Generalized Ufuncs.


Uses ILP64 (64-bit) LAPACK from MKL or OpenBLAS, has optional OpenMP support
to parallelize the outer gufunc loop via the `workers` argument.

Build the package
--------------------

To build with MKL, do

```
$ pip install numpy meson meson-python ninja
$ pip install mkl mkl-devel
$ pip install . --no-build-isolation -Csetup-args='-Dopenmp=gnu' -Csetup-args='-Dblas=mkl'
```

To disable the OpenMP support, remove `-Csetup-args='-Dopenmp=gnu'` from the
pip invocation.

To build with OpenBLAS, install `scipy-openblas64` instead of MKL,

```
$ pip install scipy-openblas64 # instead of mkl mkl-devel
```

generate the `pkg-config` file,

```
$ python -c'import scipy_openblas64 as sc; print(sc.get_pkg_config())' > openblas.pc
$ export PKG_CONFIG_PATH=$PWD
```

and build the package

```
$ pip install . --no-build-isolation -Csetup-args='-Dopenmp=gnu' -Csetup-args='-Dblas=scipy-openblas64'
```

Test the package
----------------

```
$ python -P -c'import gulinalg as g; g.test(verbosity=2)'
```

or use the standard `pytest` invocations.


--------------------------------------------------------------------------------


Below is the documentation for the older version of the package (v0.1.6).
=========================================================================

This version is using `numpy.distutils`, and is therefore limited to
python versions `<= 3.11` and compatible NumPy versions.



Notes about building
====================

Expand Down
72 changes: 72 additions & 0 deletions buildscripts/process_src_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
"""
Vendored from numpy verbatim,
https://github.com/numpy/numpy/tree/main/numpy/_build_utils
"""

import sys
import os
import argparse
import importlib.util


def get_processor():
# Convoluted because we can't import from numpy.distutils
# (numpy is not yet built)
conv_template_path = os.path.join(
os.path.dirname(__file__),
'..', 'distutils', 'conv_template.py'
)
spec = importlib.util.spec_from_file_location(
'conv_template', conv_template_path
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod.process_file


def process_and_write_file(fromfile, outfile):
"""Process tempita templated file and write out the result.
The template file is expected to end in `.src`
(e.g., `.c.src` or `.h.src`).
Processing `npy_somefile.c.src` generates `npy_somefile.c`.
"""
process_file = get_processor()
content = process_file(fromfile)
with open(outfile, 'w') as f:
f.write(content)


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"infile",
type=str,
help="Path to the input file"
)
parser.add_argument(
"-o",
"--outfile",
type=str,
help="Path to the output file"
)
parser.add_argument(
"-i",
"--ignore",
type=str,
help="An ignored input - may be useful to add a "
"dependency between custom targets",
)
args = parser.parse_args()

if not args.infile.endswith('.src'):
raise ValueError(f"Unexpected extension: {args.infile}")

outfile_abs = os.path.join(os.getcwd(), args.outfile)
process_and_write_file(args.infile, outfile_abs)


if __name__ == "__main__":
main()
Loading

0 comments on commit 54b07c1

Please sign in to comment.