mchen
mchen

Reputation: 10166

Does CUDA's thrust::inclusive_scan() have an 'init' parameter?

According to CUDA's Thrust library documentation, thrust::inclusive_scan() has 4 parameters:

OutputIterator thrust::inclusive_scan(InputIterator       first,
                                      InputIterator       last,
                                      OutputIterator      result,
                                      AssociativeOperator binary_op 
                                     )  

Yet in the usage demonstration (in the same documentation), they pass 5 parameters. An extra 4th parameter is passed as an intial value for the scan (exactly like in thrust::exclusive_scan()):

int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
thrust::maximum<int> binary_op;
thrust::inclusive_scan(data, data + 10, data, 1, binary_op); // in-place scan

Now, my code will only compile passing 4 parameters (passing 5 gives error no instance of overloaded function "thrust::inclusive_scan" matches the argument list), but I happen to need to initialise my rolling maximum just like in the example.

Can anyone clarify how to initialise the inclusive scan?

Many thanks.

Upvotes: 2

Views: 840

Answers (2)

Hari
Hari

Reputation: 1815

On a related note, C++'s std::inclusive_scan recognises the case which accepts an initial value. To deal with this case, the input array of values is prepended with the initial value and the scan is computed on the resulting array in an inclusive manner. Check here.

Upvotes: 0

talonmies
talonmies

Reputation: 72353

It seems you don't understand what the inclusive scan operation is. There is no such thing as initialising an inclusive scan. By definition, the first value of an inclusive scan is always the first element of the sequence.

So for the sequence

 [ 1, 2, 3, 4, 5, 6, 7 ]

the inclusive scan is

[ 1, 3, 6, 10, 15, 21, 28 ]

and the exclusive scan (initialised to zero) is

[ 0, 1, 3, 6, 10, 15, 21 ]

Upvotes: 3

Related Questions