Skip to content

Commit 0539b82

Browse files
(numba/dppl) Fix dppl_with_context example
1 parent fb9c310 commit 0539b82

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

dppl_lowerer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def lower_parfor_rollback(lowerer, parfor):
10951095
msg = "Parfor lowered on DPPL-device"
10961096
print(msg, parfor.loc)
10971097
except Exception as e:
1098-
msg = "Failed to lower parfor on DPPL-device.\nTo see details set environment variable NUMBA_DEBUG=1"
1098+
msg = "Failed to lower parfor on DPPL-device.\nTo see details set environment variable NUMBA_DPPL_DEBUG=1"
10991099
warnings.warn(NumbaPerformanceWarning(msg, parfor.loc))
11001100
raise e
11011101
finally:

examples/dppl_with_context.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@
22
from numba import dppl, njit, prange
33
import dpctl
44

5-
65
@njit
7-
def g(a):
8-
return a + 1
9-
6+
def add_two_arrays(b, c):
7+
a = np.empty_like(b)
8+
for i in prange(len(b)):
9+
a[i] = b[i] + c[i]
1010

11-
#@njit(parallel={'offload':True})
12-
@njit
13-
def f(a, b, c, N):
14-
for i in prange(N):
15-
a[i] = b[i] + g(c[i])
11+
return a
1612

1713

1814
def main():
1915
N = 10
20-
a = np.ones(N)
2116
b = np.ones(N)
2217
c = np.ones(N)
2318

2419
if dpctl.has_gpu_queues():
2520
with dpctl.device_context("opencl:gpu"):
26-
f(a, b, c, N)
21+
gpu_result = add_two_arrays(b, c)
22+
print('GPU device found. Result on GPU:', gpu_result)
2723
elif dpctl.has_cpu_queues():
2824
with dpctl.device_context("opencl:cpu"):
29-
f(a, b, c, N)
25+
cpu_result = add_two_arrays(b, c)
26+
print('CPU device found. Result on CPU:', cpu_result)
3027
else:
3128
print("No device found")
3229

0 commit comments

Comments
 (0)