Commit ebc4d607 authored by Pierre Augier's avatar Pierre Augier
Browse files

Fix an issue with Numba in setup.py

parent 7dbe51bab3c4
......@@ -4,10 +4,17 @@ Future
See the `ROADMAP.rst file
<https://transonic.readthedocs.io/en/latest/roadmap.html>`_.
0.4.0 (not released)
0.4.0 (2019-09-20)
--------------------
- Python 3.8 support (gast>=0.3.0, beniget>=0.2.0, thus pythran>0.9.3post1)
- An API to describe types (big refactoring)
* memoryviews for Cython
* memory layout for arrays (C, Fortran, C_or_F and strided)
- More than one backend in one process + API to select the backend for modules
and functions
0.3.3 (2019-08-30)
------------------
......
Short term (Milestone for 0.4.0)
--------------------------------
setup.py & more than one backend at runtime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Good example: https://github.com/martibosch/pylandstats/pull/1
- [done] ``make_backend_files(backend_default="cython")``
- [done] More than one backend at runtime
- [done] "python" backend
- [done] ``TRANSONIC_BACKEND`` changes only ``backend_default``
- [done] Examples setup.py in documentation
- Warnings if file not compiled
- "compilation" of "numba pure-python files"?
Short term (Milestone for 0.4.1)
--------------------------------
- Use Cython for Windows and Pythran for Linux/macOS
(on this example https://github.com/martibosch/pylandstats/pull/1)
- alternative make_header_from_fdef_annotations for Cython
- More warnings if file not compiled
Cython backend (beta version)
......
# A package using Transonic (for extensions using Pythran and Cython)
```
rm -rf /tmp/venv_package_cythran
virtualenv /tmp/venv_package_cythran
. /tmp/venv_package_cythran/bin/activate
pip install -e .
......
import numpy as np
from transonic.aheadoftime import modules_backends
from numba.targets.registry import CPUDispatcher
from package_cythran.calcul import laplace
from package_cythran.util import func
from package_cythran.other import func_numba
laplace(np.ones((2, 2), dtype=np.int32))
func(1)
......@@ -15,4 +17,9 @@ assert ts.backend.name == "pythran"
ts = modules_backends["cython"]["package_cythran.util"]
assert ts.backend.name == "cython"
ts = modules_backends["numba"]["package_cythran.other"]
assert ts.backend.name == "numba"
assert isinstance(func_numba, CPUDispatcher)
print("everything looks alright!")
from transonic import boost, set_backend_for_this_module
set_backend_for_this_module("numba")
@boost
def func_numba(a):
return a ** 2
......@@ -37,14 +37,20 @@ pack_dir = here / pack_name
version = run_path(pack_name + "/_version.py")
__version__ = version["__version__"]
install_requires = ["transonic", "numpy", "matplotlib"]
install_requires = ["transonic", "black", "numpy", "matplotlib", "numba"]
relative_paths = ["calcul.py"]
make_backend_files([pack_dir / path for path in relative_paths], backend="pythran")
make_backend_files(
[pack_dir / path for path in relative_paths], backend="pythran"
)
relative_paths = ["util.py"]
make_backend_files([pack_dir / path for path in relative_paths], backend="cython")
relative_paths = ["other.py"]
make_backend_files([pack_dir / path for path in relative_paths], backend="numba")
extensions = []
if "egg_info" not in sys.argv:
compile_arch = os.getenv("CARCH", "native")
......@@ -55,6 +61,7 @@ if "egg_info" not in sys.argv:
compile_args=("-O3", f"-march={compile_arch}", "-DUSE_XSIMD"),
)
extensions.extend(init_transonic_extensions(pack_name, backend="cython"))
init_transonic_extensions(pack_name, backend="numba")
setup(
version=__version__,
......
......@@ -37,7 +37,7 @@ pack_dir = here / pack_name
version = run_path(pack_name + "/_version.py")
__version__ = version["__version__"]
install_requires = ["transonic", "numpy", "matplotlib"]
install_requires = ["transonic", "black", "numpy", "matplotlib"]
relative_paths = ["util.py", "calcul.py"]
make_backend_files([pack_dir / path for path in relative_paths])
......
......@@ -44,7 +44,7 @@ else:
from .util import modification_date
from transonic.config import backend_default
from transonic.backends import make_backend_files
from transonic.backends import make_backend_files, backends
from transonic.util import can_import_accelerator
__all__ = [
......@@ -89,7 +89,7 @@ def detect_transonic_extensions(
present in the current working directory.
"""
if not can_import_accelerator(backend):
if backend != "numba" and not can_import_accelerator(backend):
return []
ext_names = []
if not os.path.exists(str(name_package)):
......@@ -159,7 +159,12 @@ def init_transonic_extensions(
if not modules:
return []
if backend == "pythran":
if backend == "numba":
# very special case for Numba
paths = [Path(mod.replace(".", os.path.sep) + ".py") for mod in modules]
backends["numba"].compile_extensions(paths, None)
return []
elif backend == "pythran":
BackendExtension = PythranExtension
elif backend == "cython":
BackendExtension = Extension
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment