Skip to content

Extending packaged dot to support matmul ufunc #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,37 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libmpfr-dev libssl-dev libfftw3-dev

- name: Install SLEEF
run: |
sudo apt-get update -y
sudo apt-get install -y cmake gcc g++ make git pkg-config
git clone --branch 3.8 https://github.com/shibatch/sleef.git
cd sleef
cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
cmake --build build/ --clean-first -j
sudo cmake --install build --prefix /usr
sudo cmake --install build --prefix /usr/local

- name: Install quaddtype
working-directory: quaddtype
run: |
LDFLAGS="-Wl,-rpath,/usr/lib" python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v' -Csetup-args="-Dbuildtype=debug"
# Initialize submodules first
git submodule update --init --recursive
ls -la numpy_quaddtype/QBLAS/

# Set environment variables with proper export and correct paths
export CFLAGS="-I/usr/local/include -I$(pwd)/numpy_quaddtype/QBLAS/include"
export CXXFLAGS="-I/usr/local/include -I$(pwd)/numpy_quaddtype/QBLAS/include -fext-numeric-literals"
export LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -Wl,-rpath,/usr/local/lib64 -Wl,-rpath,/usr/local/lib -fopenmp"
export LD_LIBRARY_PATH="/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH"

# Install with meson args to ensure the C++ flags are passed through
python -m pip install . -v --no-build-isolation \
-Cbuilddir=build \
-C'compile-args=-v' \
-Csetup-args="-Dbuildtype=debug" \
-Csetup-args="-Dcpp_args=-fext-numeric-literals"

- name: Run quaddtype tests
working-directory: quaddtype
run: |
Expand Down
8 changes: 6 additions & 2 deletions quaddtype/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ np.array([1,2,3], dtype=QuadPrecDType("longdouble"))

The code needs the quad precision pieces of the sleef library, which
is not available on most systems by default, so we have to generate
that first. The below assumes one has the required pieces to build
that first. The below assumes one has the required pieces to build
sleef (cmake and libmpfr-dev), and that one is in the package
directory locally.

Expand All @@ -40,6 +40,7 @@ cd ..
```

Building the `numpy-quaddtype` package from locally installed sleef:

```bash
export SLEEF_DIR=$PWD/sleef/build
export LIBRARY_PATH=$SLEEF_DIR/lib
Expand All @@ -57,10 +58,13 @@ export LDFLAGS="-Wl,-rpath,$SLEEF_DIR/lib -fopenmp -latomic -lpthread"
export CFLAGS="-fPIC"
export CXXFLAGS="-fPIC"

# To build without QBLAS (default for MSVC)
# export CFLAGS="-fPIC -DDISABLE_QUADBLAS"
# export CXXFLAGS="-fPIC -DDISABLE_QUADBLAS"

python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v'

# Run the tests
cd ..
python -m pytest
```

15 changes: 12 additions & 3 deletions quaddtype/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ srcs = [
'numpy_quaddtype/src/scalar_ops.h',
'numpy_quaddtype/src/scalar_ops.cpp',
'numpy_quaddtype/src/ops.hpp',
'numpy_quaddtype/src/umath.h',
'numpy_quaddtype/src/umath.cpp',
'numpy_quaddtype/src/dragon4.h',
'numpy_quaddtype/src/dragon4.c',
'numpy_quaddtype/src/quadblas_interface.h',
'numpy_quaddtype/src/quadblas_interface.cpp'
'numpy_quaddtype/src/quadblas_interface.cpp',
'numpy_quaddtype/src/umath/umath.h',
'numpy_quaddtype/src/umath/umath.cpp',
'numpy_quaddtype/src/umath/binary_ops.h',
'numpy_quaddtype/src/umath/binary_ops.cpp',
'numpy_quaddtype/src/umath/unary_ops.h',
'numpy_quaddtype/src/umath/unary_ops.cpp',
'numpy_quaddtype/src/umath/comparison_ops.h',
'numpy_quaddtype/src/umath/comparison_ops.cpp',
'numpy_quaddtype/src/umath/promoters.hpp',
'numpy_quaddtype/src/umath/matmul.h',
'numpy_quaddtype/src/umath/matmul.cpp',
]

py.install_sources(
Expand Down
9 changes: 2 additions & 7 deletions quaddtype/numpy_quaddtype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
QuadPrecDType,
is_longdouble_128,
get_sleef_constant,
qblas_dot as dot,
set_num_threads,
get_num_threads,
get_quadblas_version
Expand All @@ -17,7 +16,7 @@
# Constants
'pi', 'e', 'log2e', 'log10e', 'ln2', 'ln10', 'max_value', 'min_value', 'epsilon',
# QuadBLAS related functions
'dot', 'set_num_threads', 'get_num_threads', 'get_quadblas_version'
'set_num_threads', 'get_num_threads', 'get_quadblas_version'
]

def SleefQuadPrecision(value):
Expand All @@ -40,8 +39,4 @@ def LongDoubleQuadPrecDType():
ln10 = get_sleef_constant("ln10")
max_value = get_sleef_constant("quad_max")
min_value = get_sleef_constant("quad_min")
epsilon = get_sleef_constant("epsilon")

num_cores = multiprocessing.cpu_count()
# set default number of threads for QuadBLAS
set_num_threads(num_cores)
epsilon = get_sleef_constant("epsilon")
Loading
Loading