From 23ebaab7aeda1b315333fee44452eb69e2c01662 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Tue, 17 Nov 2020 15:58:41 +0300 Subject: [PATCH] Add support for dpNP (#12) * Add support for dpNP Support for dpNP requires biulding of Cython module. * Small fixes Add dpnp in conda build dependencies. Add missing comma in setup.py. Import module os and Extension class. --- conda-recipe/meta.yaml | 1 + setup.py | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 62fe7ff61d..920f79cfe7 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -20,6 +20,7 @@ requirements: - llvm-spirv - numba - dpctl + - dpnp run: - python - numba >=0.51 diff --git a/setup.py b/setup.py index af363407ef..2a7efb7205 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,39 @@ -from setuptools import find_packages, setup +import os +from setuptools import Extension, find_packages, setup +from Cython.Build import cythonize -packages = find_packages(include=["numba_dppy", "numba_dppy.*"]) +def get_ext_modules(): + ext_modules = [] + + dpnp_present = False + try: + import dpnp + except: + pass + else: + dpnp_present = True + + if dpnp_present: + dpnp_lib_path = [] + dpnp_lib_path += [os.path.dirname(dpnp.__file__)] + ext_dpnp_glue = Extension(name='numba_dppy.dpnp_glue.dpnp_fptr_interface', + sources=['numba_dppy/dpnp_glue/dpnp_fptr_interface.pyx'], + include_dirs=[dpnp.get_include()], + libraries=['dpnp_backend_c'], + library_dirs=dpnp_lib_path, + runtime_library_dirs=dpnp_lib_path, + language="c++") + ext_modules += [ext_dpnp_glue] + + if dpnp_present: + return cythonize(ext_modules) + else: + return ext_modules + + +packages = find_packages(include=["numba_dppy", "numba_dppy.*"]) +build_requires = ["cython"] install_requires = [ "numba", "dpctl", @@ -13,7 +45,9 @@ description="Numba extension for Intel CPU and GPU backend", url="https://github.com/IntelPython/numba-dppy", packages=packages, + setup_requires=build_requires, install_requires=install_requires, + ext_modules=get_ext_modules(), author="Intel Corporation", classifiers=[ "Development Status :: 4 - Beta",