Compute an inclusive prefix sum (scan) on the GPU. Given a float vector x of length n, produce y of the same length where
That is, each output is the sum of the input up to and including that index. is a power of two and the whole array fits in one thread block (n <= 1024), so a single-block parallel scan is enough.
A sequential running total on one thread is not the point of this exercise. Implement a parallel scan in shared memory (Hillis–Steele or Blelloch). Because threads both read and write the working array, you must avoid in-place races — double-buffer the shared array or write into a temporary.
Complete:
__global__ kernel that computes the inclusive scan.void solve(const float* input, float* output, int n) where both pointers are host pointers of length n. Allocate, copy in, launch, copy out, and free.Constraints: n is a power of two, 1 <= n <= 1024. Do not write a main() in your solution.