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 88
99
1010@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+ """
1217 idx = ndpx .get_global_id (0 )
13- ndpx .atomic .add (a , 0 , a [idx ])
18+ ndpx .atomic .add (res , 0 , a [idx ])
1419
1520
1621def main ():
1722 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 )
1927
2028 print ("Using device ..." )
2129 print (a .device )
2230
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 ])
2533
2634 print ("Done..." )
2735
You can’t perform that action at this time.
0 commit comments