Sum all elements of a float vector on the GPU with a shared-memory tree reduction. Assume , so one block of 256 threads holds the whole array.
Complete both functions in the starter:
__global__ void sum_kernel(const float* x, float* out, int n): each thread loads x[tid] (or 0 when tid >= n) into __shared__ memory; the block then halves the active stride each step with __syncthreads() between steps, and thread 0 writes the total to out[0].float array_sum(const std::vector<float>& x): the host wrapper the tests call. Copy x to the device, launch sum_kernel<<<1, 256>>>, copy out[0] back and return it as a float; return 0.0f for an empty input.The test harness only calls array_sum(...) and prints the result with default std::cout formatting (10, not 10.0).