Skip to content

Move spirv #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -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
18 changes: 1 addition & 17 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -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
74 changes: 73 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
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
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 = []

Expand Down Expand Up @@ -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 = [
Expand All @@ -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,
Expand All @@ -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",
Expand Down