X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=README.md;h=3a76ed759591ba1d24279207bc61f10ef2a704fa;hb=44e367a4225200fe0dc796f0ace2b5748e6a90b5;hp=673d640588d528acf0e49503752cba3c1df86c30;hpb=4803938f2aeb7c826020fa979aecfed23f94223a;p=sfpy.git diff --git a/README.md b/README.md index 673d640..3a76ed7 100644 --- a/README.md +++ b/README.md @@ -1,158 +1,64 @@ # sfpy softfloat and softposit in Python * support for softfloat float16, float32, and float64 - * support for softposit posit8, quire8, posit16, and quire16 + * support for softposit posit8, quire8, posit16, quire16, posit32, and quire32 -## Demo -``` -# WIP -``` - -## Building (on Linux x86_64, with bash) - -### Python Environment -First, make sure a virtual environment is set up with Cython and twine: - -``` -$ python -m venv .env -$ source .env/bin/activate -(.env) $ pip install --upgrade -r requirements.txt -[...] -(.env) $ -``` - -### Cython extensions -Compile the Cython extensions to C: - -``` -(.env) $ cython sfpy/*.pyx -(.env) $ -``` - -### Static libraries -The extension module depends on the softposit and softfloat static libraries. -They can be built with the following: +## Installation +On most linux distros with CPython 2.7, 3.4, 3.5, 3.6, or 3.7, sfpy should work out of the box: ``` -(.env) $ (cd SoftPosit/build/Linux-x86_64-GCC/; make clean; make) -[...] -(.env) $ (cd berkeley-softfloat-3/build/Linux-x86_64-GCC/; make clean; make) -[...] -(.env) $ +pip install sfpy ``` -Note that some changes are needed to the Makefiles so that the libraries are -compiled with the correct options. Both libraries need to use -fPIC, and -SoftPosit may need -std=c99 to work on older versions of GCC. See the -diff below. - -### Building locally -The extension modules can be built in place in the usual way: - -``` -(.env) $ python setup.py build_ext --inplace -[...] -(.env) $ -``` - -A local wheel (compatible with the python version installed in the virtual -environment) can be built with the following: - -``` -(.env) $ python setup.py bdist_wheel -[...] -(.env) $ -``` - -The local wheel will be created in the dist/ directory. This is the recommended -way to install the package when building it from source locally: +Under the hood, sfpy uses Cython to create bindings for the softposit and softfloat C libraries. +The building instructions are tested on Ubuntu 16.04 - for other platforms they may need some +adaptation. +## Demo ``` -$ pip install dist/sfpy*.whl -[...] -$ python +>>> import sfpy >>> from sfpy import * ->>> Posit8(1.3) -Posit8(1.3125) +>>> a, b = Float16(1.3), Float16(1.4) +>>> a * b - a / b +Float16(0.89208984375) +>>> sfpy.float.flag_get_inexact() +True +>>> a += b +>>> a +Float16(2.69921875) >>> -``` - -### Building manylinux1 wheels for distribution -Widely compatible linux wheels can be built with the help of PyPA's manylinux -docker image. This requires that Docker is installed, and that the host can pull -the proper docker image. - -To build the manylinux wheels, run: - -``` -$ sudo docker run -u $(id -u) --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/docker-build-wheels.sh -[...] -$ -``` - -This will create a set of manylinux1 wheel files in the wheelhouse/ directory. - -The docker build will make its own static libraries as part of the build process, -and delete any existing static libraries with `make clean`. - -The wheels can be uploaded to PyPI (if you're the package maintainer) with - -``` -(.env) $ twine upload --repository-url https://test.pypi.org/legacy/ wheelhouse/* -[...] -(.env) $ -``` - -to test on test PyPI, or - -``` -(.env) $ twine upload wheelhouse/* -[...] -(.env) $ -``` - -for a release. - -### Makefile customizations -The Makefiles used to build the static libraries need a few small tweaks to -make sure that all the right flags are given to gcc. The changes are shown -in the following diffs. - -SoftPosit/build/Linux-x86_64/Makefile - -``` -diff --git a/build/Linux-x86_64-GCC/Makefile b/build/Linux-x86_64-GCC/Makefile -index 4409e43..46bb877 100644 ---- a/build/Linux-x86_64-GCC/Makefile -+++ b/build/Linux-x86_64-GCC/Makefile -@@ -60,9 +60,9 @@ LINK_PYTHON = \ - - DELETE = rm -f - C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include --OPTIMISATION = -march=core-avx2 -O2 -+OPTIMISATION = -fPIC -O2 ^M - COMPILE_C = \ -- gcc -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 \ -+ gcc -std=c99 -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 \^M - $(SOFTPOSIT_OPTS) $(C_INCLUDES) $(OPTIMISATION) \ - -o $@ - MAKELIB = ar crs $@ -``` - -berkeley-softfloat-3/build/Linux-x86_64/Makefile - -``` -diff --git a/build/Linux-x86_64-GCC/Makefile b/build/Linux-x86_64-GCC/Makefile -index 2ee5dad..b175964 100644 ---- a/build/Linux-x86_64-GCC/Makefile -+++ b/build/Linux-x86_64-GCC/Makefile -@@ -45,7 +45,7 @@ DELETE = rm -f - C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include - COMPILE_C = \ - gcc -c -Werror-implicit-function-declaration -DSOFTFLOAT_FAST_INT64 \ -- $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -o $@ -+ $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -fPIC -o $@ - MAKELIB = ar crs $@ - - OBJ = .o -``` +>>> x, y = Posit16(3.0), Posit16(3) +>>> x +Posit16(3.0) +>>> x.bits +22528 +>>> y +Posit16(2.9802322387695312e-08) +>>> y.bits +3 +>>> x * y +Posit16(8.940696716308594e-08) +>>> acc = Posit16(0) +>>> for i in range(10000): +... acc = acc.fma(x, y) +... +>>> acc +Posit16(1.9073486328125e-06) +>>> acc.bits +24 +>>> q = Quire16(0) +>>> for i in range(10000): +... q.iqma(x, y) +... +>>> q +Quire16(0.00089263916015625) +>>> q.bits +64424509440000 +>>> q.to_posit() +Posit16(0.00089263916015625) +>>> q.to_posit().bits +490 +``` + +## Building +See [BUILDING](https://github.com/billzorn/sfpy/blob/master/BUILDING.md).