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.
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 ]