PrefixSum inside of a nd_range kernel

Hi,
I found this example

That uses the exclusive scan to calculation block total_sum but when I try to copy and use this function in my case produces 0 output what could be the reason ?

Is there any alternative way to achieve prefix sum inside of an nd_range ?

So this is what i want to achieve inside of an nd_range kernel

values: [1,2,3,4,5,6]
initial value: 0
result: [0,0+1=1,0+1+2=3,0+1+2+3=6,0+1+2+3+4=10,0+1+2+3+4+5=15,0+1+2+3+4+5+6=21]
aggregate_sum = 0+1+3+6+10+15+21 = 56

How to achieve this behavior ?

Hi @br-ko,

the oneMKL functions are designed to be called from the host, and will perform an optimised variant of the operation on an array. For the device-side, you can use the exclusive and inclusive scan operations, detailed in the SYCL 2020 specification.

computecpp-sdk/samples/subgroup-scan.cpp at master · codeplaysoftware/computecpp-sdk · GitHub demonstrates its use but might not exactly match the 2020 spec, as it is rather old.

I hope this helps,
Duncan.

1 Like