From 1d2fc8ca2c1c5a63df8b89c38f2bff3c19d86c16 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 17 Dec 2020 06:12:15 -0600 Subject: [PATCH 1/4] move spirv for linux --- conda-recipe/build.sh | 7 +---- setup.py | 62 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index ae3422c46a..83d3c51569 100644 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -1,15 +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/ +${PYTHON} setup.py install --single-version-externally-managed --record=record.txt diff --git a/setup.py b/setup.py index 37ad0bfc68..d2c96f1280 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,23 @@ 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 import versioneer +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 = [] @@ -34,6 +47,53 @@ def get_ext_modules(): return ext_modules +class install(orig_install.install): + def run(self): + spirv_compile() + return super().run() + + +class develop(orig_develop.develop): + def run(self): + spirv_compile() + return super().run() + + +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") + 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", + ] + subprocess.check_call(clang_args, stderr=subprocess.STDOUT, shell=False) + spirv_args = [ + "llvm-spirv", + "-o", + "numba_dppy/ocl/atomics/atomic_ops.spir", + "numba_dppy/ocl/atomics/atomic_ops.bc", + ] + subprocess.check_call(spirv_args, stderr=subprocess.STDOUT, shell=False) + + packages = find_packages(include=["numba_dppy", "numba_dppy.*"]) build_requires = ["cython"] install_requires = [ @@ -44,6 +104,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, @@ -63,7 +124,6 @@ def get_ext_modules(): "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Compilers", ], - cmdclass=versioneer.get_cmdclass(), ) setup(**metadata) From 4a61f533ef97868dea5f413d5dbe7134d1392b1a Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 17 Dec 2020 17:15:38 +0300 Subject: [PATCH 2/4] Add spirv for win --- conda-recipe/bld.bat | 12 ++-------- setup.py | 54 ++++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index ce7809780c..90e64f8b50 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -1,16 +1,8 @@ -%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 +%PYTHON% setup.py install --single-version-externally-managed --record=record.txt +if errorlevel 1 exit 1 diff --git a/setup.py b/setup.py index d2c96f1280..25c670bc7d 100644 --- a/setup.py +++ b/setup.py @@ -49,14 +49,14 @@ def get_ext_modules(): class install(orig_install.install): def run(self): + super().run() spirv_compile() - return super().run() class develop(orig_develop.develop): def run(self): + super().run() spirv_compile() - return super().run() def _get_cmdclass(): @@ -68,30 +68,36 @@ def _get_cmdclass(): def spirv_compile(): if IS_LIN: os.environ["CC"] = os.path.join(os.environ.get("ONEAPI_ROOT"), "compiler/latest/linux", "bin/clang") - 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", - ] + 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) - spirv_args = [ - "llvm-spirv", - "-o", - "numba_dppy/ocl/atomics/atomic_ops.spir", - "numba_dppy/ocl/atomics/atomic_ops.bc", - ] 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.*"]) From e51d557db81c117b0066c91a2697410db7dcafcd Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 17 Dec 2020 17:18:51 +0300 Subject: [PATCH 3/4] Remove errorcheck --- conda-recipe/bld.bat | 1 - 1 file changed, 1 deletion(-) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 90e64f8b50..b0776fd1f2 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -5,4 +5,3 @@ REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted set ERRORLEVEL= %PYTHON% setup.py install --single-version-externally-managed --record=record.txt -if errorlevel 1 exit 1 From f857491b9fdb9205cf603b82977042de9fb59842 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 12 Jan 2021 07:01:24 -0600 Subject: [PATCH 4/4] fix black --- setup.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4e80b9b5a0..d80801742b 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ elif sys.platform in ["win32", "cygwin"]: IS_WIN = True + def get_ext_modules(): ext_modules = [] @@ -67,11 +68,16 @@ def _get_cmdclass(): 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") + 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") + os.environ["CC"] = os.path.join( + os.environ.get("ONEAPI_ROOT"), "compiler/latest/windows", "bin/clang.exe" + ) clang_args = [ os.environ.get("CC"), "-flto",