Skip to content

Commit 4c39fde

Browse files
author
Diptorup Deb
committed
Merge tag '0.21.0dev1' into gold/2021
2 parents 32c7c40 + e7a4420 commit 4c39fde

File tree

110 files changed

+2920
-16426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2920
-16426
lines changed

.github/workflows/conda-package.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
strategy:
9292
matrix:
9393
python: ["3.8", "3.9", "3.10"]
94-
numba: ["0.56"]
94+
numba: ["0.57"]
9595
dpnp: ["0.11"]
9696

9797
steps:
@@ -139,7 +139,7 @@ jobs:
139139
source $CONDA/etc/profile.d/conda.sh
140140
conda activate numba_dpex_env
141141
# echo "libintelocl.so" | tee /etc/OpenCL/vendors/intel-cpu.icd
142-
python -m pytest -q -ra --disable-warnings --pyargs $MODULE_NAME -vv
142+
pytest -q -ra --disable-warnings --pyargs $MODULE_NAME -vv
143143
- name: Run examples
144144
run: |
145145
ls
@@ -209,7 +209,7 @@ jobs:
209209
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
210210
- name: Install numba-dpex
211211
run: |
212-
conda install ${{ env.PACKAGE_NAME }} pytest dpcpp_win-64 dpcpp-llvm-spirv python=${{ matrix.python }} dpctl ${{ matrix.dependencies }} -c $env:GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}
212+
conda install ${{ env.PACKAGE_NAME }} pytest dpcpp_win-64 dpcpp-llvm-spirv python=${{ matrix.python }} dpctl -c $env:GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}
213213
# Test installed packages
214214
conda list
215215
- name: Install opencl_rt
@@ -232,7 +232,7 @@ jobs:
232232
run: python -c "import dpcpp_llvm_spirv as p; print(p.get_llvm_spirv_path())"
233233
- name: Run tests
234234
run: |
235-
python -m pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv
235+
pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv
236236
237237
upload_linux:
238238
needs: test_linux

conda-recipe/meta.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ requirements:
1818
- python
1919
- setuptools >=63.*
2020
- cython
21-
- numba 0.56*
21+
- numba 0.57*
2222
- dpctl >=0.14*
2323
- dpnp >=0.11*
2424
- dpcpp-llvm-spirv
2525
- wheel
2626
run:
2727
- python
28-
- numba >=0.56*
28+
- numba >=0.57*
2929
- dpctl >=0.14*
3030
- spirv-tools
3131
- dpcpp-llvm-spirv

environment/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
- gxx_linux-64
1313
- dpcpp_linux-64
1414
- cython
15-
- numba 0.56*
15+
- numba 0.57*
1616
- dppy/label/dev:dpctl
1717
- dppy/label/dev:dpnp
1818
- spirv-tools

environment/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
- gxx_linux-64
1212
- dpcpp_linux-64
1313
- cython
14-
- numba 0.56*
14+
- numba 0.57*
1515
- dpctl 0.14*
1616
- dpnp >=0.10.2
1717
- spirv-tools

numba_dpex/__init__.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414

1515
import dpctl
1616
import llvmlite.binding as ll
17-
import numba
18-
from numba.core import ir_utils
17+
from numba import __version__ as numba_version
1918
from numba.np import arrayobj
20-
from numba.np.ufunc import array_exprs
2119
from numba.np.ufunc.decorators import Vectorize
2220

23-
from numba_dpex._patches import _empty_nd_impl, _is_ufunc, _mk_alloc
21+
from numba_dpex._patches import _empty_nd_impl
2422
from numba_dpex.vectorizers import Vectorize as DpexVectorize
2523

24+
from .numba_patches import (
25+
patch_arrayexpr_tree_to_ir,
26+
patch_is_ufunc,
27+
patch_mk_alloc,
28+
)
29+
2630
# Monkey patches
27-
array_exprs._is_ufunc = _is_ufunc
28-
ir_utils.mk_alloc = _mk_alloc
31+
patch_is_ufunc.patch()
32+
patch_mk_alloc.patch()
33+
patch_arrayexpr_tree_to_ir.patch()
2934
arrayobj._empty_nd_impl = _empty_nd_impl
3035

3136

@@ -58,8 +63,6 @@ def load_dpctl_sycl_interface():
5863
else:
5964
raise ImportError
6065

61-
Vectorize.target_registry.ondemand["dpex"] = lambda: DpexVectorize
62-
6366

6467
def parse_sem_version(version_string: str) -> Tuple[int, int, int]:
6568
"""Parse sem version into tuple of three integers. If there is a suffix like
@@ -76,25 +79,24 @@ def parse_sem_version(version_string: str) -> Tuple[int, int, int]:
7679
)
7780

7881

79-
numba_version = parse_sem_version(numba.__version__)
80-
if numba_version < (0, 56, 4):
82+
numba_sem_version = parse_sem_version(numba_version)
83+
if numba_sem_version < (0, 57, 0):
8184
logging.warning(
82-
"numba_dpex needs numba 0.56.4, using "
85+
"numba_dpex needs numba 0.57.0, using "
8386
f"numba={numba_version} may cause unexpected behavior"
8487
)
8588

8689

87-
dpctl_version = tuple(map(int, dpctl.__version__.split(".")[:2]))
88-
if dpctl_version < (0, 14):
90+
dpctl_sem_version = parse_sem_version(dpctl.__version__)
91+
if dpctl_sem_version < (0, 14):
8992
logging.warning(
9093
"numba_dpex needs dpctl 0.14 or greater, using "
91-
f"dpctl={dpctl_version} may cause unexpected behavior"
94+
f"dpctl={dpctl_sem_version} may cause unexpected behavior"
9295
)
9396

9497
from numba import prange # noqa E402
9598

9699
import numba_dpex.core.dpjit_dispatcher # noqa E402
97-
import numba_dpex.core.offload_dispatcher # noqa E402
98100

99101
# Initialize the _dpexrt_python extension
100102
import numba_dpex.core.runtime # noqa E402
@@ -111,16 +113,11 @@ def parse_sem_version(version_string: str) -> Tuple[int, int, int]:
111113
# Re-export all type names
112114
from numba_dpex.core.types import * # noqa E402
113115
from numba_dpex.dpnp_iface import dpnpimpl # noqa E402
114-
from numba_dpex.retarget import offload_to_sycl_device # noqa E402
115116

116117
if config.HAS_NON_HOST_DEVICE:
117118
# Re export
118119
from .core.targets import dpjit_target, kernel_target
119120
from .decorators import dpjit, func, kernel
120-
121-
# We are importing dpnp stub module to make Numba recognize the
122-
# module when we rename Numpy functions.
123-
from .dpnp_iface.stubs import dpnp
124121
from .ocl.stubs import (
125122
GLOBAL_MEM_FENCE,
126123
LOCAL_MEM_FENCE,
@@ -145,9 +142,11 @@ def parse_sem_version(version_string: str) -> Tuple[int, int, int]:
145142
else:
146143
raise ImportError("No non-host SYCL device found to execute kernels.")
147144

145+
Vectorize.target_registry.ondemand["dpex"] = lambda: DpexVectorize
146+
148147
from numba_dpex._version import get_versions # noqa E402
149148

150149
__version__ = get_versions()["version"]
151150
del get_versions
152151

153-
__all__ = types.__all__ + ["offload_to_sycl_device"] + ["Range", "NdRange"]
152+
__all__ = types.__all__ + ["Range", "NdRange"]

numba_dpex/_patches.py

Lines changed: 1 addition & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import numpy
65
from llvmlite import ir as llvmir
76
from llvmlite.ir import Constant
87
from numba.core import cgutils
98
from numba.core import config as numba_config
10-
from numba.core import ir, types
11-
from numba.core.ir_utils import (
12-
convert_size_to_var,
13-
get_np_ufunc_typ,
14-
mk_unique_var,
15-
)
9+
from numba.core import types
1610
from numba.core.typing import signature
1711
from numba.extending import intrinsic, overload_classmethod
1812
from numba.np.arrayobj import (
@@ -21,156 +15,10 @@
2115
make_array,
2216
populate_array,
2317
)
24-
from numba.np.ufunc.dufunc import DUFunc
2518

2619
from numba_dpex.core.runtime import context as dpexrt
2720
from numba_dpex.core.types import DpnpNdArray
2821

29-
# Numpy array constructors
30-
31-
32-
def _is_ufunc(func):
33-
return isinstance(func, (numpy.ufunc, DUFunc)) or hasattr(
34-
func, "is_dpnp_ufunc"
35-
)
36-
37-
38-
def _mk_alloc(
39-
typingctx, typemap, calltypes, lhs, size_var, dtype, scope, loc, lhs_typ
40-
):
41-
"""generate an array allocation with np.empty() and return list of nodes.
42-
size_var can be an int variable or tuple of int variables.
43-
lhs_typ is the type of the array being allocated.
44-
"""
45-
out = []
46-
ndims = 1
47-
size_typ = types.intp
48-
if isinstance(size_var, tuple):
49-
if len(size_var) == 1:
50-
size_var = size_var[0]
51-
size_var = convert_size_to_var(size_var, typemap, scope, loc, out)
52-
else:
53-
# tuple_var = build_tuple([size_var...])
54-
ndims = len(size_var)
55-
tuple_var = ir.Var(scope, mk_unique_var("$tuple_var"), loc)
56-
if typemap:
57-
typemap[tuple_var.name] = types.containers.UniTuple(
58-
types.intp, ndims
59-
)
60-
# constant sizes need to be assigned to vars
61-
new_sizes = [
62-
convert_size_to_var(s, typemap, scope, loc, out)
63-
for s in size_var
64-
]
65-
tuple_call = ir.Expr.build_tuple(new_sizes, loc)
66-
tuple_assign = ir.Assign(tuple_call, tuple_var, loc)
67-
out.append(tuple_assign)
68-
size_var = tuple_var
69-
size_typ = types.containers.UniTuple(types.intp, ndims)
70-
71-
if hasattr(lhs_typ, "__allocate__"):
72-
return lhs_typ.__allocate__(
73-
typingctx,
74-
typemap,
75-
calltypes,
76-
lhs,
77-
size_var,
78-
dtype,
79-
scope,
80-
loc,
81-
lhs_typ,
82-
size_typ,
83-
out,
84-
)
85-
86-
# g_np_var = Global(numpy)
87-
g_np_var = ir.Var(scope, mk_unique_var("$np_g_var"), loc)
88-
if typemap:
89-
typemap[g_np_var.name] = types.misc.Module(numpy)
90-
g_np = ir.Global("np", numpy, loc)
91-
g_np_assign = ir.Assign(g_np, g_np_var, loc)
92-
# attr call: empty_attr = getattr(g_np_var, empty)
93-
empty_attr_call = ir.Expr.getattr(g_np_var, "empty", loc)
94-
attr_var = ir.Var(scope, mk_unique_var("$empty_attr_attr"), loc)
95-
if typemap:
96-
typemap[attr_var.name] = get_np_ufunc_typ(numpy.empty)
97-
attr_assign = ir.Assign(empty_attr_call, attr_var, loc)
98-
# Assume str(dtype) returns a valid type
99-
dtype_str = str(dtype)
100-
# alloc call: lhs = empty_attr(size_var, typ_var)
101-
typ_var = ir.Var(scope, mk_unique_var("$np_typ_var"), loc)
102-
if typemap:
103-
typemap[typ_var.name] = types.functions.NumberClass(dtype)
104-
# If dtype is a datetime/timedelta with a unit,
105-
# then it won't return a valid type and instead can be created
106-
# with a string. i.e. "datetime64[ns]")
107-
if (
108-
isinstance(dtype, (types.NPDatetime, types.NPTimedelta))
109-
and dtype.unit != ""
110-
):
111-
typename_const = ir.Const(dtype_str, loc)
112-
typ_var_assign = ir.Assign(typename_const, typ_var, loc)
113-
else:
114-
if dtype_str == "bool":
115-
# empty doesn't like 'bool' sometimes (e.g. kmeans example)
116-
dtype_str = "bool_"
117-
np_typ_getattr = ir.Expr.getattr(g_np_var, dtype_str, loc)
118-
typ_var_assign = ir.Assign(np_typ_getattr, typ_var, loc)
119-
alloc_call = ir.Expr.call(attr_var, [size_var, typ_var], (), loc)
120-
121-
if calltypes:
122-
cac = typemap[attr_var.name].get_call_type(
123-
typingctx, [size_typ, types.functions.NumberClass(dtype)], {}
124-
)
125-
# By default, all calls to "empty" are typed as returning a standard
126-
# NumPy ndarray. If we are allocating a ndarray subclass here then
127-
# just change the return type to be that of the subclass.
128-
cac._return_type = (
129-
lhs_typ.copy(layout="C") if lhs_typ.layout == "F" else lhs_typ
130-
)
131-
calltypes[alloc_call] = cac
132-
if lhs_typ.layout == "F":
133-
empty_c_typ = lhs_typ.copy(layout="C")
134-
empty_c_var = ir.Var(scope, mk_unique_var("$empty_c_var"), loc)
135-
if typemap:
136-
typemap[empty_c_var.name] = lhs_typ.copy(layout="C")
137-
empty_c_assign = ir.Assign(alloc_call, empty_c_var, loc)
138-
139-
# attr call: asfortranarray = getattr(g_np_var, asfortranarray)
140-
asfortranarray_attr_call = ir.Expr.getattr(
141-
g_np_var, "asfortranarray", loc
142-
)
143-
afa_attr_var = ir.Var(
144-
scope, mk_unique_var("$asfortran_array_attr"), loc
145-
)
146-
if typemap:
147-
typemap[afa_attr_var.name] = get_np_ufunc_typ(numpy.asfortranarray)
148-
afa_attr_assign = ir.Assign(asfortranarray_attr_call, afa_attr_var, loc)
149-
# call asfortranarray
150-
asfortranarray_call = ir.Expr.call(afa_attr_var, [empty_c_var], (), loc)
151-
if calltypes:
152-
calltypes[asfortranarray_call] = typemap[
153-
afa_attr_var.name
154-
].get_call_type(typingctx, [empty_c_typ], {})
155-
156-
asfortranarray_assign = ir.Assign(asfortranarray_call, lhs, loc)
157-
158-
out.extend(
159-
[
160-
g_np_assign,
161-
attr_assign,
162-
typ_var_assign,
163-
empty_c_assign,
164-
afa_attr_assign,
165-
asfortranarray_assign,
166-
]
167-
)
168-
else:
169-
alloc_assign = ir.Assign(alloc_call, lhs, loc)
170-
out.extend([g_np_assign, attr_assign, typ_var_assign, alloc_assign])
171-
172-
return out
173-
17422

17523
def _empty_nd_impl(context, builder, arrtype, shapes):
17624
"""Utility function used for allocating a new array during LLVM code

numba_dpex/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def __getattr__(name):
5353
# Dump offload diagnostics
5454
OFFLOAD_DIAGNOSTICS = _readenv("NUMBA_DPEX_OFFLOAD_DIAGNOSTICS", int, 0)
5555

56-
FALLBACK_ON_CPU = _readenv("NUMBA_DPEX_FALLBACK_ON_CPU", int, 1)
57-
5856
# Activate Native floating point atomcis support for supported devices.
5957
# Requires llvm-spirv supporting the FP atomics extension
6058
NATIVE_FP_ATOMICS = _readenv("NUMBA_DPEX_ACTIVATE_ATOMICS_FP_NATIVE", int, 0)
@@ -89,3 +87,6 @@ def __getattr__(name):
8987
"NUMBA_DPEX_TESTING_SKIP_NO_DEBUGGING", int, 1
9088
)
9189
TESTING_LOG_DEBUGGING = _readenv("NUMBA_DPEX_TESTING_LOG_DEBUGGING", int, DEBUG)
90+
# Flag to turn on the ConstantSizeStaticLocalMemoryPass in the kernel pipeline.
91+
# The pass is turned off by default.
92+
STATIC_LOCAL_MEM_PASS = _readenv("NUMBA_DPEX_STATIC_LOCAL_MEM_PASS", int, 0)

numba_dpex/core/compiler.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
UnreachableError,
1515
)
1616
from numba_dpex.core.pipelines.kernel_compiler import KernelCompiler
17-
from numba_dpex.core.pipelines.offload_compiler import OffloadCompiler
1817

1918

2019
@global_compiler_lock
@@ -73,10 +72,6 @@ def compile_with_dpex(
7372
pipeline_class=KernelCompiler,
7473
)
7574
elif isinstance(pyfunc, ir.FunctionIR):
76-
# FIXME: Kernels in the form of Numba IR need to be compiled
77-
# using the offload compiler due to them retaining parfor
78-
# nodes due to the use of gufuncs. Once the kernel builder is
79-
# ready we should be able to switch to the KernelCompiler.
8075
cres = compiler.compile_ir(
8176
typingctx=typingctx,
8277
targetctx=targetctx,

0 commit comments

Comments
 (0)