Skip to content

Commit bece9a4

Browse files
authored
Merge pull request #346 from IntelPython/remove_experimental
Removing usage from numba_dpex.experimental
2 parents 76da169 + b4a2502 commit bece9a4

File tree

17 files changed

+69
-53
lines changed

17 files changed

+69
-53
lines changed

.github/workflows/build_and_run.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
env:
1111
# sycl is not included. Add it manually if you need
12-
WORKLOADS: python,numpy,dpnp,numba_n,numba_np,numba_npr,numba_dpex_k,numba_dpex_n,numba_dpex_p,numba_mlir_k,numba_mlir_n,numba_mlir_p
12+
WORKLOADS: python,numpy,dpnp,numba_n,numba_np,numba_npr,numba_dpex_k,numba_dpex_n,numba_dpex_p
1313
PYTHONIOENCODING: 'utf-8'
1414

1515
jobs:
@@ -68,7 +68,6 @@ jobs:
6868
shell: bash -l {0}
6969
run: |
7070
find ./environments -type f | xargs sed -i 's/intel::numpy/numpy/'
71-
find ./environments -type f | xargs sed -i '/numba-mlir/d'
7271
find ./environments -type f | xargs sed -i 's/setuptools>=42,<64/setuptools/'
7372
7473
- name: Setup miniconda
@@ -168,8 +167,9 @@ jobs:
168167
- name: Run benchmarks
169168
run: dpbench -i ${{env.WORKLOADS}} run -r2 --no-print-results --precision=${{matrix.precision}} || exit 1
170169

171-
- name: Run rodinia benchmarks
172-
run: dpbench -i ${{env.WORKLOADS}} --last-run run -r2 --no-print-results --rodinia --no-dpbench --precision=${{matrix.precision}} || exit 1
170+
# TODO: Re-enable rodinia benchmarks in CI once workloads have been changed to new numba-dpex API
171+
# - name: Run rodinia benchmarks
172+
# run: dpbench -i ${{env.WORKLOADS}} --last-run run -r2 --no-print-results --rodinia --no-dpbench --precision=${{matrix.precision}} || exit 1
173173

174174
- name: Generate report
175175
run: dpbench -i ${{env.WORKLOADS}} report || exit 1

dpbench/benchmarks/default/black_scholes/black_scholes_numba_dpex_k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from math import erf, exp, log, sqrt
66

7-
import numba_dpex.experimental as dpex
7+
import numba_dpex as dpex
88
from numba_dpex import kernel_api as kapi
99

1010

dpbench/benchmarks/default/dbscan/dbscan_numba_dpex_k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import dpnp as np
66
import numba as nb
7-
import numba_dpex.experimental as dpex
7+
import numba_dpex as dpex
88
import numpy
99
from numba_dpex import kernel_api as kapi
1010

dpbench/benchmarks/default/gpairs/gpairs_numba_dpex_k.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import numba_dpex as dpex
6-
import numba_dpex.experimental as dpexexp
76
from numba_dpex import kernel_api as kapi
87

98
# This implementation is numba dpex kernel version with atomics.
109

1110

12-
@dpexexp.kernel
11+
@dpex.kernel
1312
def count_weighted_pairs_3d_intel_no_slm_ker(
1413
nd_item: kapi.NdItem,
1514
n,
@@ -151,7 +150,7 @@ def gpairs(
151150
ceiling_quotient(nbins, private_hist_size) * private_hist_size
152151
)
153152

154-
dpexexp.call_kernel(
153+
dpex.call_kernel(
155154
count_weighted_pairs_3d_intel_no_slm_ker,
156155
kapi.NdRange(dpex.Range(*gwsRange), dpex.Range(*lwsRange)),
157156
nopt,

dpbench/benchmarks/default/kmeans/kmeans_initialize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(npoints, niters, seed, ndims, ncentroids, types_dict):
1717
arrayP = default_rng.uniform(XL, XH, (npoints, ndims)).astype(f_dtype)
1818
arrayPclusters = np.ones(npoints, dtype=i_dtype)
1919
arrayC = np.empty((ncentroids, ndims), dtype=f_dtype)
20-
arrayCnumpoint = np.ones(ncentroids, dtype=i_dtype)
20+
arrayCnumpoint = np.ones(ncentroids, dtype=np.int64)
2121

2222
arrayC[:] = arrayP[:ncentroids]
2323

dpbench/benchmarks/default/kmeans/kmeans_numba_dpex_k.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from math import sqrt
77

88
import numba_dpex as dpex
9-
import numba_dpex.experimental as dpexexp
109
from dpctl import tensor as dpt
1110
from numba_dpex import kernel_api as kapi
1211

@@ -23,9 +22,7 @@ def Align(value, base):
2322
def getGroupByCluster( # noqa: C901
2423
dims, num_centroids, dtyp, WorkPI, local_size_
2524
):
26-
local_copies = min(4, max(1, DivUp(local_size_, num_centroids)))
27-
28-
@dpexexp.kernel
25+
@dpex.kernel
2926
def groupByCluster(
3027
nd_item: kapi.NdItem,
3128
arrayP,
@@ -34,15 +31,12 @@ def groupByCluster(
3431
NewCentroids,
3532
NewCount,
3633
last,
34+
local_copies,
35+
localCentroids,
36+
localNewCentroids,
37+
localNewCount,
3738
):
3839
numpoints = arrayP.shape[0]
39-
localCentroids = dpex.local.array((dims, num_centroids), dtype=dtyp)
40-
localNewCentroids = dpex.local.array(
41-
(local_copies, dims, num_centroids), dtype=dtyp
42-
)
43-
localNewCount = dpex.local.array(
44-
(local_copies, num_centroids), dtype=dpt.int32
45-
)
4640

4741
grid = nd_item.get_group().get_group_id(0)
4842
lid = nd_item.get_local_id(0)
@@ -121,20 +115,19 @@ def groupByCluster(
121115

122116
@lru_cache(maxsize=1)
123117
def getUpdateCentroids(dims, num_centroids, dtyp, local_size_):
124-
@dpexexp.kernel
118+
@dpex.kernel
125119
def updateCentroids(
126120
nd_item: kapi.NdItem,
127121
diff,
128122
arrayC,
129123
arrayCnumpoint,
130124
NewCentroids,
131125
NewCount,
126+
local_distance,
132127
):
133128
lid = nd_item.get_local_id(0)
134129
local_size = nd_item.get_local_range(0)
135130

136-
local_distance = dpex.local.array(local_size_, dtype=dtyp)
137-
138131
max_distance = dtyp.type(0)
139132
for c in range(lid, num_centroids, local_size):
140133
numpoints = NewCount[c]
@@ -168,10 +161,11 @@ def updateCentroids(
168161

169162
@lru_cache(maxsize=1)
170163
def getUpdateLabels(dims, num_centroids, dtyp, WorkPI):
171-
@dpexexp.kernel
172-
def updateLabels(nd_item: kapi.NdItem, arrayP, arrayPcluster, arrayC):
164+
@dpex.kernel
165+
def updateLabels(
166+
nd_item: kapi.NdItem, arrayP, arrayPcluster, arrayC, localCentroids
167+
):
173168
numpoints = arrayP.shape[0]
174-
localCentroids = dpex.local.array((dims, num_centroids), dtype=dtyp)
175169

176170
grid = nd_item.get_group().get_group_id(0)
177171
lid = nd_item.get_local_id(0)
@@ -245,16 +239,31 @@ def kmeans_kernel(
245239
for i in range(niters):
246240
last = i == (niters - 1)
247241
if diff_host < tolerance:
248-
dpexexp.call_kernel(
242+
localCentroids = kapi.LocalAccessor(
243+
(dims, num_centroids), dtype=arrayP.dtype
244+
)
245+
246+
dpex.call_kernel(
249247
updateLabels,
250248
kapi.NdRange((global_size,), (local_size,)),
251249
arrayP,
252250
arrayPcluster,
253251
arrayC,
252+
localCentroids,
254253
)
255254
break
256255

257-
dpexexp.call_kernel(
256+
local_copies = min(4, max(1, DivUp(local_size, num_centroids)))
257+
localCentroids = kapi.LocalAccessor(
258+
(dims, num_centroids), dtype=arrayP.dtype
259+
)
260+
localNewCentroids = kapi.LocalAccessor(
261+
(local_copies, dims, num_centroids), dtype=arrayP.dtype
262+
)
263+
localNewCount = kapi.LocalAccessor(
264+
(local_copies, num_centroids), dtype=dpt.int64
265+
)
266+
dpex.call_kernel(
258267
groupByCluster,
259268
kapi.NdRange((global_size,), (local_size,)),
260269
arrayP,
@@ -263,17 +272,23 @@ def kmeans_kernel(
263272
NewCentroids,
264273
NewCount,
265274
last,
275+
local_copies,
276+
localCentroids,
277+
localNewCentroids,
278+
localNewCount,
266279
)
267280

281+
local_distance = kapi.LocalAccessor(local_size, dtype=arrayP.dtype)
268282
update_centroid_size = min(num_centroids, local_size)
269-
dpexexp.call_kernel(
283+
dpex.call_kernel(
270284
updateCentroids,
271285
kapi.NdRange((update_centroid_size,), (update_centroid_size,)),
272286
diff,
273287
arrayC,
274288
arrayCnumpoint,
275289
NewCentroids,
276290
NewCount,
291+
local_distance,
277292
)
278293
diff_host = dpt.asnumpy(diff)[0]
279294

dpbench/benchmarks/default/kmeans/kmeans_numba_dpex_p.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dpnp as np
66
import numba as nb
77
import numba_dpex as dpex
8+
from numba_dpex import kernel_api as kapi
89

910

1011
# determine the euclidean distance from the cluster center to each point
@@ -40,12 +41,17 @@ def calCentroidsSum(
4041

4142

4243
@dpex.kernel
43-
def calCentroidsSum2(arrayP, arrayPcluster, arrayCsum, arrayCnumpoint):
44-
i = dpex.get_global_id(0)
44+
def calCentroidsSum2(
45+
item: kapi.Item, arrayP, arrayPcluster, arrayCsum, arrayCnumpoint
46+
):
47+
i = item.get_id(0)
4548
ci = arrayPcluster[i]
46-
dpex.atomic.add(arrayCsum, (ci, 0), arrayP[i, 0])
47-
dpex.atomic.add(arrayCsum, (ci, 1), arrayP[i, 1])
48-
dpex.atomic.add(arrayCnumpoint, ci, 1)
49+
arrayCsum_aref = kapi.AtomicRef(arrayCsum, index=(ci, 0))
50+
arrayCsum_aref.fetch_add(arrayP[i, 0])
51+
arrayCsum_aref = kapi.AtomicRef(arrayCsum, index=(ci, 1))
52+
arrayCsum_aref.fetch_add(arrayP[i, 1])
53+
arrayCnumpoint_aref = kapi.AtomicRef(arrayCnumpoint, index=ci)
54+
arrayCnumpoint_aref.fetch_add(1)
4955

5056

5157
# update the centriods array after computation
@@ -86,8 +92,13 @@ def kmeans_numba(arrayP, arrayPcluster, arrayC, arrayCnumpoint, niters):
8692
num_centroids,
8793
)
8894

89-
calCentroidsSum2[dpex.Range(num_points)](
90-
arrayP, arrayPcluster, arrayCsum, arrayCnumpoint
95+
dpex.call_kernel(
96+
calCentroidsSum2,
97+
kapi.Range(num_points),
98+
arrayP,
99+
arrayPcluster,
100+
arrayCsum,
101+
arrayCnumpoint,
91102
)
92103

93104
# TODO: get rid of it once prange supports dtype

dpbench/benchmarks/default/kmeans/kmeans_sycl_native_ext/kmeans_sycl/_kmeans_sycl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ void kmeans_sync(dpctl::tensor::usm_ndarray arrayP,
3737
throw std::runtime_error("All arrays must have the same precision");
3838
}
3939

40-
if (arrayPclusters.get_typenum() != arrayCnumpoint.get_typenum()) {
41-
throw std::runtime_error("All arrays must have the same precision");
42-
}
43-
4440
auto npoints = arrayP.get_shape(0);
4541
auto ncentroids = arrayC.get_shape(0);
4642
auto ndims = arrayC.get_shape(1);

dpbench/benchmarks/default/knn/knn_numba_dpex_k.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
from math import sqrt
66

77
import numba_dpex as dpex
8-
import numba_dpex.experimental as dpexexp
98
import numpy as np
109
from numba_dpex import kernel_api as kapi
1110

1211

13-
@dpexexp.kernel
12+
@dpex.kernel
1413
def _knn_kernel( # noqa: C901: TODO: can we simplify logic?
1514
item: kapi.Item,
1615
train,
@@ -109,7 +108,7 @@ def knn(
109108
votes_to_classes,
110109
data_dim,
111110
):
112-
dpexexp.call_kernel(
111+
dpex.call_kernel(
113112
_knn_kernel,
114113
kapi.Range(test_size),
115114
x_train,

dpbench/benchmarks/default/l2_norm/l2_norm_numba_dpex_k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import math
66

7-
import numba_dpex.experimental as dpex
7+
import numba_dpex as dpex
88
from numba_dpex import kernel_api as kapi
99

1010

0 commit comments

Comments
 (0)