Skip to content

Commit 6cb14c8

Browse files
authored
Merge pull request #223 from IntelPython/feature/add_npbench_benchmarks
Add npbench benchmarks
2 parents a23114a + f540d03 commit 6cb14c8

File tree

493 files changed

+19804
-9
lines changed

Some content is hidden

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

493 files changed

+19804
-9
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
8+
def initialize(N):
9+
from numpy.random import default_rng
10+
11+
rng = default_rng(42)
12+
data, radius = rng.random((N,)), rng.random((N,))
13+
return data, radius
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
8+
"""
9+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
10+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
11+
7th European Conference on Python in Science (EuroSciPy 2014).
12+
"""
13+
14+
import cupy as np
15+
16+
17+
def azimint_hist(data, radius, npt):
18+
histu = np.histogram(radius, npt)[0]
19+
histw = np.histogram(radius, npt, weights=data)[0]
20+
return histw / histu
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
8+
"""
9+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
10+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
11+
7th European Conference on Python in Science (EuroSciPy 2014).
12+
"""
13+
14+
import dace as dc
15+
import numpy as np
16+
17+
N, bins, npt = (dc.symbol(s, dtype=dc.int64) for s in ("N", "bins", "npt"))
18+
19+
20+
@dc.program
21+
def get_bin_edges(a: dc.float64[N], bin_edges: dc.float64[bins + 1]):
22+
a_min = np.amin(a)
23+
a_max = np.amax(a)
24+
delta = (a_max - a_min) / bins
25+
for i in dc.map[0:bins]:
26+
bin_edges[i] = a_min + i * delta
27+
28+
bin_edges[bins] = a_max # Avoid roundoff error on last point
29+
30+
31+
@dc.program
32+
def compute_bin(x: dc.float64, bin_edges: dc.float64[bins + 1]):
33+
# assuming uniform bins for now
34+
a_min = bin_edges[0]
35+
a_max = bin_edges[bins]
36+
return dc.int64(bins * (x - a_min) / (a_max - a_min))
37+
38+
39+
@dc.program
40+
def histogram(a: dc.float64[N], bin_edges: dc.float64[bins + 1]):
41+
hist = np.ndarray((bins,), dtype=np.int64)
42+
hist[:] = 0
43+
get_bin_edges(a, bin_edges)
44+
45+
for i in dc.map[0:N]:
46+
bin = min(compute_bin(a[i], bin_edges), bins - 1)
47+
hist[bin] += 1
48+
49+
return hist
50+
51+
52+
@dc.program
53+
def histogram_weights(
54+
a: dc.float64[N], bin_edges: dc.float64[bins + 1], weights: dc.float64[N]
55+
):
56+
hist = np.ndarray((bins,), dtype=weights.dtype)
57+
hist[:] = 0
58+
get_bin_edges(a, bin_edges)
59+
60+
for i in dc.map[0:N]:
61+
bin = min(compute_bin(a[i], bin_edges), bins - 1)
62+
hist[bin] += weights[i]
63+
64+
return hist
65+
66+
67+
@dc.program
68+
def azimint_hist(data: dc.float64[N], radius: dc.float64[N]):
69+
# histu = np.histogram(radius, npt)[0]
70+
bin_edges_u = np.ndarray((npt + 1,), dtype=np.float64)
71+
histu = histogram(radius, bin_edges_u)
72+
# histw = np.histogram(radius, npt, weights=data)[0]
73+
bin_edges_w = np.ndarray((npt + 1,), dtype=np.float64)
74+
histw = histogram_weights(radius, bin_edges_w, data)
75+
return histw / histu
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import legate.numpy as np
14+
15+
16+
def azimint_hist(data, radius, npt):
17+
histu = np.histogram(radius, npt)[0]
18+
histw = np.histogram(radius, npt, weights=data)[0]
19+
return histw / histu
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import numba as nb
14+
import numpy as np
15+
16+
17+
@nb.jit(nopython=True, parallel=False, fastmath=True)
18+
def get_bin_edges(a, bins):
19+
bin_edges = np.zeros((bins + 1,), dtype=np.float64)
20+
a_min = a.min()
21+
a_max = a.max()
22+
delta = (a_max - a_min) / bins
23+
for i in range(bin_edges.shape[0]):
24+
bin_edges[i] = a_min + i * delta
25+
26+
bin_edges[-1] = a_max # Avoid roundoff error on last point
27+
return bin_edges
28+
29+
30+
@nb.jit(nopython=True, fastmath=True)
31+
def compute_bin(x, bin_edges):
32+
# assuming uniform bins for now
33+
n = bin_edges.shape[0] - 1
34+
a_min = bin_edges[0]
35+
a_max = bin_edges[-1]
36+
37+
# special case to mirror NumPy behavior for last bin
38+
if x == a_max:
39+
return n - 1 # a_max always in last bin
40+
41+
return int(n * (x - a_min) / (a_max - a_min))
42+
43+
44+
@nb.jit(nopython=True, parallel=False, fastmath=True)
45+
def histogram(a, bins, weights):
46+
hist = np.zeros((bins,), dtype=a.dtype)
47+
bin_edges = get_bin_edges(a, bins)
48+
49+
for i in range(a.shape[0]):
50+
bin = compute_bin(a[i], bin_edges)
51+
hist[bin] += weights[i]
52+
53+
return hist, bin_edges
54+
55+
56+
@nb.jit(nopython=True, parallel=False, fastmath=True)
57+
def azimint_hist(data, radius, npt):
58+
histu = np.histogram(radius, npt)[0]
59+
# histw = np.histogram(radius, npt, weights=data)[0]
60+
histw = histogram(radius, npt, weights=data)[0]
61+
return histw / histu
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import numba as nb
14+
import numpy as np
15+
16+
17+
@nb.jit(nopython=True, parallel=True, fastmath=True)
18+
def get_bin_edges_parallel(a, bins):
19+
bin_edges = np.zeros((bins + 1,), dtype=np.float64)
20+
a_min = a.min()
21+
a_max = a.max()
22+
delta = (a_max - a_min) / bins
23+
for i in range(bin_edges.shape[0]):
24+
bin_edges[i] = a_min + i * delta
25+
26+
bin_edges[-1] = a_max # Avoid roundoff error on last point
27+
return bin_edges
28+
29+
30+
@nb.jit(nopython=True, fastmath=True)
31+
def compute_bin(x, bin_edges):
32+
# assuming uniform bins for now
33+
n = bin_edges.shape[0] - 1
34+
a_min = bin_edges[0]
35+
a_max = bin_edges[-1]
36+
37+
# special case to mirror NumPy behavior for last bin
38+
if x == a_max:
39+
return n - 1 # a_max always in last bin
40+
41+
return int(n * (x - a_min) / (a_max - a_min))
42+
43+
44+
@nb.jit(nopython=True, parallel=True, fastmath=True)
45+
def histogram_parallel(a, bins, weights):
46+
hist = np.zeros((bins,), dtype=a.dtype)
47+
bin_edges = get_bin_edges_parallel(a, bins)
48+
49+
for i in range(a.shape[0]):
50+
bin = compute_bin(a[i], bin_edges)
51+
hist[bin] += weights[i]
52+
53+
return hist, bin_edges
54+
55+
56+
@nb.jit(nopython=True, parallel=True, fastmath=True)
57+
def azimint_hist(data, radius, npt):
58+
histu = np.histogram(radius, npt)[0]
59+
# histw = np.histogram(radius, npt, weights=data)[0]
60+
histw = histogram_parallel(radius, npt, weights=data)[0]
61+
return histw / histu
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import numba as nb
14+
import numpy as np
15+
16+
17+
@nb.jit(nopython=True, parallel=True, fastmath=True)
18+
def get_bin_edges_prange(a, bins):
19+
bin_edges = np.zeros((bins + 1,), dtype=np.float64)
20+
a_min = a.min()
21+
a_max = a.max()
22+
delta = (a_max - a_min) / bins
23+
for i in nb.prange(bin_edges.shape[0]):
24+
bin_edges[i] = a_min + i * delta
25+
26+
bin_edges[-1] = a_max # Avoid roundoff error on last point
27+
return bin_edges
28+
29+
30+
@nb.jit(nopython=True, fastmath=True)
31+
def compute_bin(x, bin_edges):
32+
# assuming uniform bins for now
33+
n = bin_edges.shape[0] - 1
34+
a_min = bin_edges[0]
35+
a_max = bin_edges[-1]
36+
37+
# special case to mirror NumPy behavior for last bin
38+
if x == a_max:
39+
return n - 1 # a_max always in last bin
40+
41+
return int(n * (x - a_min) / (a_max - a_min))
42+
43+
44+
@nb.jit(nopython=True, parallel=True, fastmath=True)
45+
def histogram_prange(a, bins, weights):
46+
hist = np.zeros((bins,), dtype=a.dtype)
47+
bin_edges = get_bin_edges_prange(a, bins)
48+
49+
for i in nb.prange(a.shape[0]):
50+
bin = compute_bin(a[i], bin_edges)
51+
hist[bin] += weights[i]
52+
53+
return hist, bin_edges
54+
55+
56+
@nb.jit(nopython=True, parallel=True, fastmath=True)
57+
def azimint_hist(data, radius, npt):
58+
histu = np.histogram(radius, npt)[0]
59+
# histw = np.histogram(radius, npt, weights=data)[0]
60+
histw = histogram_prange(radius, npt, weights=data)[0]
61+
return histw / histu
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import numba as nb
14+
import numpy as np
15+
16+
17+
@nb.jit(nopython=False, forceobj=True, parallel=False, fastmath=True)
18+
def azimint_hist(data, radius, npt):
19+
histu = np.histogram(radius, npt)[0]
20+
histw = np.histogram(radius, npt, weights=data)[0]
21+
return histw / histu
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import numba as nb
14+
import numpy as np
15+
16+
17+
@nb.jit(nopython=False, forceobj=True, parallel=True, fastmath=True)
18+
def azimint_hist(data, radius, npt):
19+
histu = np.histogram(radius, npt)[0]
20+
histw = np.histogram(radius, npt, weights=data)[0]
21+
return histw / histu
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2014 Jérôme Kieffer et al.
2+
# SPDX-FileCopyrightText: 2021 ETH Zurich and the NPBench authors
3+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
"""
8+
Jérôme Kieffer and Giannis Ashiotis. Pyfai: a python library for
9+
high performance azimuthal integration on gpu, 2014. In Proceedings of the
10+
7th European Conference on Python in Science (EuroSciPy 2014).
11+
"""
12+
13+
import numpy as np
14+
15+
16+
def azimint_hist(data, radius, npt):
17+
histu = np.histogram(radius, npt)[0]
18+
histw = np.histogram(radius, npt, weights=data)[0]
19+
return histw / histu

0 commit comments

Comments
 (0)