File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
numba_dpex/examples/kernel Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 8
8
9
9
10
10
@ndpx .kernel
11
- def atomic_reduction (a ):
11
+ def atomic_reduction (a , res ):
12
+ """Summarize all the items in a and writes it into res using atomic.add.
13
+
14
+ :param a: array of values to get sum
15
+ :param res: result where to add all the items from a array. It must be preset to 0.
16
+ """
12
17
idx = ndpx .get_global_id (0 )
13
- ndpx .atomic .add (a , 0 , a [idx ])
18
+ ndpx .atomic .add (res , 0 , a [idx ])
14
19
15
20
16
21
def main ():
17
22
N = 10
18
- a = np .arange (N )
23
+
24
+ # We are storing sum to the first element
25
+ a = np .arange (0 , N )
26
+ res = np .zeros (1 , dtype = a .dtype )
19
27
20
28
print ("Using device ..." )
21
29
print (a .device )
22
30
23
- atomic_reduction [ndpx .Range (N )](a )
24
- print ("Reduction sum =" , a [0 ])
31
+ atomic_reduction [ndpx .Range (N )](a , res )
32
+ print ("Reduction sum =" , res [0 ])
25
33
26
34
print ("Done..." )
27
35
You can’t perform that action at this time.
0 commit comments