Skip to content

Commit 77fafac

Browse files
author
roxx30198
committed
rodinia/gaussian sycl and ndpx implementation
1 parent 94c2d62 commit 77fafac

20 files changed

Lines changed: 502 additions & 1 deletion

File tree

.github/workflows/build_and_run.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,8 @@ jobs:
168168
- name: Run benchmarks
169169
run: dpbench -i ${{env.WORKLOADS}} run -r2 --no-print-results || exit 1
170170

171+
- name: Run rodinia benchmarks
172+
run: dpbench -i ${{env.WORKLOADS}} run -r2 --no-print-results --rodinia --no-dpbench|| exit 1
173+
171174
- name: Generate report
172175
run: dpbench -i ${{env.WORKLOADS}} report || exit 1

.github/workflows/conda-package.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ jobs:
195195
run: |
196196
dpbench -i numpy -b azimint_hist run --npbench
197197
198+
- name: Run rodinia benchmark
199+
run: |
200+
dpbench -b gaussian run --rodinia --no-dpbench -r 1
201+
198202
upload_anaconda:
199203
name: Upload dppy/label/dev ['${{ matrix.os }}', python='${{ matrix.python }}']
200204

.pre-commit-config.yaml

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

dpbench/benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_subdirectory(kmeans)
1010
add_subdirectory(knn)
1111
add_subdirectory(gpairs)
1212
add_subdirectory(dbscan)
13+
add_subdirectory(rodinia)
1314

1415
# generate dpcpp version into config
1516
set(FILE ${CMAKE_SOURCE_DIR}/dpbench/configs/framework_info/dpcpp.toml)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
add_subdirectory(gaussian)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
add_subdirectory(gaussian_sycl_native_ext)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""
6+
7+
Gaussian elimination implementation
8+
9+
This is sycl and numba-dpex implementation for gaussian elimination
10+
11+
Input
12+
---------
13+
size<int_64> : Forms an input matrix of dimensions (size x size)
14+
15+
Output
16+
17+
--------
18+
19+
result<array<float>> : Result of the given set of linear equations using
20+
gaussian elimination.
21+
22+
Method:
23+
24+
The gaussian transformations are applied to the input matrix to form the
25+
diagonal matrix in forward elimination, and then the equations are solved
26+
to find the result in back substitution.
27+
28+
"""
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
LAMBDA = -0.01
6+
7+
8+
def initialize(size, types_dict):
9+
import math
10+
11+
import numpy as np
12+
13+
dtype = types_dict["float"]
14+
15+
coe = np.empty((2 * size - 1), dtype=dtype)
16+
a = np.empty((size * size), dtype=dtype)
17+
18+
for i in range(size):
19+
coe_i = 10 * math.exp(LAMBDA * i)
20+
j = size - 1 + i
21+
coe[j] = coe_i
22+
j = size - 1 - i
23+
coe[j] = coe_i
24+
25+
for i in range(size):
26+
for j in range(size):
27+
a[i * size + j] = coe[size - 1 - i + j]
28+
29+
return (
30+
a,
31+
np.ones(size, dtype=dtype),
32+
np.zeros((size * size), dtype=dtype),
33+
np.zeros(size, dtype=dtype),
34+
)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import dpctl
6+
import numba_dpex
7+
8+
BLOCK_size_XY = 4
9+
10+
11+
@numba_dpex.kernel()
12+
def gaussian_kernel_1(m, a, size, t):
13+
if (
14+
numba_dpex.get_local_id(2)
15+
+ numba_dpex.get_group_id(2) * numba_dpex.get_local_size(2)
16+
>= size - 1 - t
17+
):
18+
return
19+
20+
m[
21+
size
22+
* (
23+
numba_dpex.get_local_size(2) * numba_dpex.get_group_id(2)
24+
+ numba_dpex.get_local_id(2)
25+
+ t
26+
+ 1
27+
)
28+
+ t
29+
] = (
30+
a[
31+
size
32+
* (
33+
numba_dpex.get_local_size(2) * numba_dpex.get_group_id(2)
34+
+ numba_dpex.get_local_id(2)
35+
+ t
36+
+ 1
37+
)
38+
+ t
39+
]
40+
/ a[size * t + t]
41+
)
42+
43+
44+
@numba_dpex.kernel()
45+
def gaussian_kernel_2(m, a, b, size, t):
46+
if (
47+
numba_dpex.get_local_id(2)
48+
+ numba_dpex.get_group_id(2) * numba_dpex.get_local_size(2)
49+
>= size - 1 - t
50+
):
51+
return
52+
53+
if (
54+
numba_dpex.get_local_id(1)
55+
+ numba_dpex.get_group_id(1) * numba_dpex.get_local_size(1)
56+
>= size - t
57+
):
58+
return
59+
60+
xidx = numba_dpex.get_group_id(2) * numba_dpex.get_local_size(
61+
2
62+
) + numba_dpex.get_local_id(2)
63+
yidx = numba_dpex.get_group_id(1) * numba_dpex.get_local_size(
64+
1
65+
) + numba_dpex.get_local_id(1)
66+
67+
a[size * (xidx + 1 + t) + (yidx + t)] -= (
68+
m[size * (xidx + 1 + t) + t] * a[size * t + (yidx + t)]
69+
)
70+
if yidx == 0:
71+
b[xidx + 1 + t] -= m[size * (xidx + 1 + t) + (yidx + t)] * b[t]
72+
73+
74+
def gaussian(a, b, m, size, result):
75+
device = dpctl.SyclDevice()
76+
block_size = device.max_work_group_size
77+
grid_size = int((size / block_size) + 0 if not (size % block_size) else 1)
78+
79+
blocksize2d = BLOCK_size_XY
80+
gridsize2d = int(
81+
(size / blocksize2d) + (0 if not (size % blocksize2d) else 1)
82+
)
83+
84+
global_range = numba_dpex.Range(1, 1, grid_size * block_size)
85+
local_range = numba_dpex.Range(1, 1, block_size)
86+
87+
dim_blockXY = numba_dpex.Range(1, blocksize2d, blocksize2d)
88+
dim_gridXY = numba_dpex.Range(
89+
1, gridsize2d * blocksize2d, gridsize2d * blocksize2d
90+
)
91+
92+
for t in range(size - 1):
93+
gaussian_kernel_1[numba_dpex.NdRange(global_range, local_range)](
94+
m, a, size, t
95+
)
96+
97+
gaussian_kernel_2[numba_dpex.NdRange(dim_gridXY, dim_blockXY)](
98+
m, a, b, size, t
99+
)
100+
101+
for i in range(size):
102+
result[size - i - 1] = b[size - i - 1]
103+
for j in range(i):
104+
result[size - i - 1] -= (
105+
a[size * (size - i - 1) + (size - j - 1)] * result[size - j - 1]
106+
)
107+
result[size - i - 1] = (
108+
result[size - i - 1] / a[size * (size - i - 1) + (size - i - 1)]
109+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
6+
def gaussian(a, b, m, size, result):
7+
# Forward Elimination
8+
for t in range(size - 1):
9+
for i in range(t + 1, size):
10+
m = a[i * size + t] / a[t * size + t]
11+
for j in range(t, size):
12+
a[i * size + j] = a[i * size + j] - m * a[t * size + j]
13+
b[i] = b[i] - m * b[t]
14+
15+
# Back Substitution
16+
for i in range(size):
17+
result[size - i - 1] = b[size - i - 1]
18+
for j in range(i):
19+
result[size - i - 1] -= (
20+
a[size * (size - i - 1) + (size - j - 1)] * result[size - j - 1]
21+
)
22+
result[size - i - 1] = (
23+
result[size - i - 1] / a[size * (size - i - 1) + (size - i - 1)]
24+
)

0 commit comments

Comments
 (0)