Skip to content

Commit 1ba0129

Browse files
authored
Merge branch 'main' into package
2 parents 9493442 + 7d809cd commit 1ba0129

File tree

54 files changed

+1862
-1304
lines changed

Some content is hidden

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

54 files changed

+1862
-1304
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ repos:
5050
hooks:
5151
- id: pydocstyle
5252
# TODO: add packages one by one to enforce pydocstyle eventually
53-
files: (^dpbench/config/|^scripts/|^dpbench/console/)
53+
files: (^dpbench/config/|^scripts/|^dpbench/console/|^dpbench/infrastructure/benchmark_runner.py|^dpbench/infrastructure/benchmark_validation.py)
5454
args: ["--convention=google"]
5555
# D417 does not work properly:
5656
# https://github.com/PyCQA/pydocstyle/issues/459

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
88
[![pre-commit](https://github.com/IntelPython/dpbench/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/IntelPython/dpbench/actions/workflows/pre-commit.yml)
99

10-
# DPBench - Benchmarks to evaluate Data-parallel Extensions for Python
10+
# DPBench - Benchmarks to evaluate Data-Parallel Extensions for Python
1111

1212
* __*_numba_*.py__ : This file contains Numba implementations of the benchmarks. There are three modes: nopython-mode, nopython-mode-parallel and nopython-mode-parallel-range.
1313
* __*_numba_dpex_*.py__ : This file contains Numba-Dpex implementations of the benchmarks. There are three modes: kernel-mode, numpy-mode and prange-mode.

dpbench/benchmarks/black_scholes/black_scholes_initialize.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ def initialize(nopt, seed, types_dict):
77
import numpy as np
88
import numpy.random as default_rng
99

10-
dtype = types_dict["float"]
11-
S0L = 10.0
12-
S0H = 50.0
13-
XL = 10.0
14-
XH = 50.0
15-
TL = 1.0
16-
TH = 2.0
17-
RISK_FREE = 0.1
18-
VOLATILITY = 0.2
10+
dtype: np.dtype = types_dict["float"]
11+
S0L = dtype.type(10.0)
12+
S0H = dtype.type(50.0)
13+
XL = dtype.type(10.0)
14+
XH = dtype.type(50.0)
15+
TL = dtype.type(1.0)
16+
TH = dtype.type(2.0)
17+
RISK_FREE = dtype.type(0.1)
18+
VOLATILITY = dtype.type(0.2)
1919

2020
default_rng.seed(seed)
2121
price = default_rng.uniform(S0L, S0H, nopt).astype(dtype)

dpbench/benchmarks/black_scholes/black_scholes_numba_dpex_k.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

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

7+
import dpnp as np
78
import numba_dpex as dpex
89

910

1011
@dpex.kernel
1112
def _black_scholes_kernel(nopt, price, strike, t, rate, volatility, call, put):
13+
dtype = price.dtype
1214
mr = -rate
13-
sig_sig_two = volatility * volatility * 2
15+
sig_sig_two = volatility * volatility * dtype.type(2)
1416

1517
i = dpex.get_global_id(0)
1618

@@ -22,14 +24,14 @@ def _black_scholes_kernel(nopt, price, strike, t, rate, volatility, call, put):
2224
b = T * mr
2325

2426
z = T * sig_sig_two
25-
c = 0.25 * z
26-
y = 1.0 / sqrt(z)
27+
c = dtype.type(0.25) * z
28+
y = dtype.type(1.0) / sqrt(z)
2729

2830
w1 = (a - b + c) * y
2931
w2 = (a - b - c) * y
3032

31-
d1 = 0.5 + 0.5 * erf(w1)
32-
d2 = 0.5 + 0.5 * erf(w2)
33+
d1 = dtype.type(0.5) + dtype.type(0.5) * erf(w1)
34+
d2 = dtype.type(0.5) + dtype.type(0.5) * erf(w2)
3335

3436
Se = exp(b) * S
3537

dpbench/benchmarks/dbscan/dbscan_initialize.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ class Params(NamedTuple):
6464
data_size, Params(eps=DEFAULT_EPS, minpts=DEFAULT_MINPTS)
6565
)
6666

67+
dtype: np.dtype = types_dict["float"]
68+
6769
return (
68-
X.flatten().astype(types_dict["float"]),
69-
params.eps,
70+
X.flatten().astype(dtype),
71+
dtype.type(params.eps),
7072
params.minpts,
7173
)

dpbench/benchmarks/dbscan/dbscan_numba_dpex_k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_neighborhood(n, dim, data, eps, ind_lst, sz_lst, block_size, nblocks):
6363
i2 = n if ii + 1 == nblocks1 else i1 + block_size1
6464
for j in range(start, stop):
6565
for k in range(i1, i2):
66-
dist = 0.0
66+
dist = data.dtype.type(0.0)
6767
for m in range(dim):
6868
diff = data[k * dim + m] - data[j * dim + m]
6969
dist += diff * diff

dpbench/benchmarks/gpairs/gpairs_dpnp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def _gpairs_impl(x1, y1, z1, w1, x2, y2, z2, w2, rbins):
1212
+ np.square(z2 - z1[:, None])
1313
)
1414
return np.array(
15-
[np.outer(w1, w2)[dm <= rbins[k]].sum() for k in range(len(rbins))]
15+
[np.outer(w1, w2)[dm <= rbins[k]].sum() for k in range(len(rbins))],
16+
device=x1.device,
1617
)
1718

1819

dpbench/benchmarks/gpairs/gpairs_numba_dpex_k.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import math
6-
75
import numba_dpex as dpex
8-
import numpy as np
96

107
# This implementation is numba dpex kernel version with atomics.
118

@@ -27,6 +24,7 @@ def count_weighted_pairs_3d_intel_no_slm_ker(
2724
rbins_squared,
2825
result,
2926
):
27+
dtype = x0.dtype
3028
lid0 = dpex.get_local_id(0)
3129
gr0 = dpex.get_group_id(0)
3230

@@ -38,9 +36,9 @@ def count_weighted_pairs_3d_intel_no_slm_ker(
3836

3937
n_wi = 20
4038

41-
dsq_mat = dpex.private.array(shape=(20 * 20), dtype=np.float32)
42-
w0_vec = dpex.private.array(shape=(20), dtype=np.float32)
43-
w1_vec = dpex.private.array(shape=(20), dtype=np.float32)
39+
dsq_mat = dpex.private.array(shape=(20 * 20), dtype=dtype)
40+
w0_vec = dpex.private.array(shape=(20), dtype=dtype)
41+
w1_vec = dpex.private.array(shape=(20), dtype=dtype)
4442

4543
offset0 = gr0 * n_wi * lws0 + lid0
4644
offset1 = gr1 * n_wi * lws1 + lid1
@@ -80,7 +78,7 @@ def count_weighted_pairs_3d_intel_no_slm_ker(
8078

8179
# update slm_hist. Use work-item private buffer of 16 tfloat elements
8280
for k in range(0, slm_hist_size, private_hist_size):
83-
private_hist = dpex.private.array(shape=(16), dtype=np.float32)
81+
private_hist = dpex.private.array(shape=(16), dtype=dtype)
8482
for p in range(private_hist_size):
8583
private_hist[p] = 0.0
8684

@@ -95,7 +93,9 @@ def count_weighted_pairs_3d_intel_no_slm_ker(
9593
pk = k
9694
for p in range(private_hist_size):
9795
private_hist[p] += (
98-
pw if (pk < nbins and dsq <= rbins_squared[pk]) else 0.0
96+
pw
97+
if (pk < nbins and dsq <= rbins_squared[pk])
98+
else dtype.type(0.0)
9999
)
100100
pk += 1
101101

dpbench/benchmarks/kmeans/kmeans_initialize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ def initialize(npoints, niters, seed, ndims, ncentroids, types_dict):
77
import numpy as np
88
import numpy.random as default_rng
99

10-
f_dtype = types_dict["float"]
11-
i_dtype = types_dict["int"]
12-
XL = 1.0
13-
XH = 5.0
10+
f_dtype: np.dtype = types_dict["float"]
11+
i_dtype: np.dtype = types_dict["int"]
12+
XL = f_dtype.type(1.0)
13+
XH = f_dtype.type(5.0)
1414

1515
default_rng.seed(seed)
1616

dpbench/benchmarks/kmeans/kmeans_numba_dpex_k.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
def groupByCluster(arrayP, arrayPcluster, arrayC, num_points, num_centroids):
1212
idx = dpex.get_global_id(0)
1313
# if idx < num_points: # why it was removed??
14-
minor_distance = -1
14+
dtype = arrayC.dtype
15+
minor_distance = dtype.type(-1)
1516
for i in range(num_centroids):
1617
dx = arrayP[idx, 0] - arrayC[i, 0]
1718
dy = arrayP[idx, 1] - arrayC[i, 1]
@@ -41,8 +42,9 @@ def calCentroidsSum2(arrayP, arrayPcluster, arrayCsum, arrayCnumpoint):
4142
@dpex.kernel
4243
def updateCentroids(arrayC, arrayCsum, arrayCnumpoint, num_centroids):
4344
i = dpex.get_global_id(0)
44-
arrayC[i, 0] = arrayCsum[i, 0] / arrayCnumpoint[i]
45-
arrayC[i, 1] = arrayCsum[i, 1] / arrayCnumpoint[i]
45+
dtype = arrayC.dtype
46+
arrayC[i, 0] = arrayCsum[i, 0] / dtype.type(arrayCnumpoint[i])
47+
arrayC[i, 1] = arrayCsum[i, 1] / dtype.type(arrayCnumpoint[i])
4648

4749

4850
@dpex.kernel

0 commit comments

Comments
 (0)