diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 1b200b7dba..b0776fd1f2 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -1,24 +1,7 @@ -%PYTHON% setup.py install --single-version-externally-managed --record=record.txt -if errorlevel 1 exit 1 - echo "Activating oneAPI compiler environment..." call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" if errorlevel 1 exit 1 REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. set ERRORLEVEL= -echo on - -set "CC=clang.exe" - -%CC% -flto -target spir64-unknown-unknown -c -x cl -emit-llvm -cl-std=CL2.0 -Xclang -finclude-default-header numba_dppy/ocl/atomics/atomic_ops.cl -o numba_dppy/ocl/atomics/atomic_ops.bc -llvm-spirv -o numba_dppy/ocl/atomics/atomic_ops.spir numba_dppy/ocl/atomics/atomic_ops.bc -xcopy numba_dppy\ocl\atomics\atomic_ops.spir %SP_DIR%\numba_dppy\ocl\atomics /E /Y - -rem Build wheel package -if NOT "%WHEELS_OUTPUT_FOLDER%"=="" ( - %PYTHON% setup.py bdist_wheel - if errorlevel 1 exit 1 - copy dist\numba_dppy*.whl %WHEELS_OUTPUT_FOLDER% - if errorlevel 1 exit 1 -) +%PYTHON% setup.py install --single-version-externally-managed --record=record.txt diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index d80b152301..83d3c51569 100644 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -1,26 +1,10 @@ #!/bin/bash -${PYTHON} setup.py install --single-version-externally-managed --record=record.txt - if [ ! -z "${ONEAPI_ROOT}" ]; then source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh - export CC=clang else echo "DPCPP is needed to build OpenCL kernel. Abort!" fi -${CC} -flto -target spir64-unknown-unknown -c -x cl -emit-llvm -cl-std=CL2.0 -Xclang -finclude-default-header numba_dppy/ocl/atomics/atomic_ops.cl -o numba_dppy/ocl/atomics/atomic_ops.bc -llvm-spirv -o numba_dppy/ocl/atomics/atomic_ops.spir numba_dppy/ocl/atomics/atomic_ops.bc -cp numba_dppy/ocl/atomics/atomic_ops.spir ${SP_DIR}/numba_dppy/ocl/atomics/ - -# Build wheel package -if [ "$CONDA_PY" == "36" ]; then - WHEELS_BUILD_ARGS="-p manylinux1_x86_64" -else - WHEELS_BUILD_ARGS="-p manylinux2014_x86_64" -fi -if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then - $PYTHON setup.py bdist_wheel ${WHEELS_BUILD_ARGS} - cp dist/numba_dppy*.whl ${WHEELS_OUTPUT_FOLDER} -fi +${PYTHON} setup.py install --single-version-externally-managed --record=record.txt diff --git a/setup.py b/setup.py index 5ce0234bb8..990292e3b1 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,9 @@ import os +import sys +import setuptools.command.install as orig_install +import setuptools.command.develop as orig_develop +import subprocess +import shutil from setuptools import Extension, find_packages, setup from Cython.Build import cythonize @@ -6,6 +11,15 @@ import sys +IS_WIN = False +IS_LIN = False + +if "linux" in sys.platform: + IS_LIN = True +elif sys.platform in ["win32", "cygwin"]: + IS_WIN = True + + def get_ext_modules(): ext_modules = [] @@ -46,6 +60,64 @@ def get_ext_modules(): return ext_modules +class install(orig_install.install): + def run(self): + super().run() + spirv_compile() + + +class develop(orig_develop.develop): + def run(self): + super().run() + spirv_compile() + + +def _get_cmdclass(): + cmdclass = versioneer.get_cmdclass() + cmdclass["install"] = install + cmdclass["develop"] = develop + return cmdclass + + +def spirv_compile(): + if IS_LIN: + os.environ["CC"] = os.path.join( + os.environ.get("ONEAPI_ROOT"), "compiler/latest/linux", "bin/clang" + ) + if IS_WIN: + os.environ["CC"] = os.path.join( + os.environ.get("ONEAPI_ROOT"), "compiler/latest/windows", "bin/clang.exe" + ) + clang_args = [ + os.environ.get("CC"), + "-flto", + "-target", + "spir64-unknown-unknown", + "-c", + "-x", + "cl", + "-emit-llvm", + "-cl-std=CL2.0", + "-Xclang", + "-finclude-default-header", + "numba_dppy/ocl/atomics/atomic_ops.cl", + "-o", + "numba_dppy/ocl/atomics/atomic_ops.bc", + ] + spirv_args = [ + "llvm-spirv", + "-o", + "numba_dppy/ocl/atomics/atomic_ops.spir", + "numba_dppy/ocl/atomics/atomic_ops.bc", + ] + if IS_LIN: + subprocess.check_call(clang_args, stderr=subprocess.STDOUT, shell=False) + subprocess.check_call(spirv_args, stderr=subprocess.STDOUT, shell=False) + if IS_WIN: + subprocess.check_call(clang_args, stderr=subprocess.STDOUT, shell=True) + subprocess.check_call(spirv_args, stderr=subprocess.STDOUT, shell=True) + + packages = find_packages(include=["numba_dppy", "numba_dppy.*"]) build_requires = ["cython"] install_requires = [ @@ -56,6 +128,7 @@ def get_ext_modules(): metadata = dict( name="numba-dppy", version=versioneer.get_version(), + cmdclass=_get_cmdclass(), description="Numba extension for Intel CPU and GPU backend", url="https://github.com/IntelPython/numba-dppy", packages=packages, @@ -75,7 +148,6 @@ def get_ext_modules(): "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Compilers", ], - cmdclass=versioneer.get_cmdclass(), entry_points={ "numba_extensions": [ "init = numba_dppy.numpy_usm_shared:numba_register",