Prefix Sum
2026/3/9小于 1 分钟
Prefix Sum
题面
Write a GPU program that computes the prefix sum (cumulative sum) of an array of 32-bit floating point numbers. 对输入 [a, b, c, d, ...],前缀和为 [a, a+b, a+b+c, a+b+c+d, ...]。
Implementation Requirements
- Use only GPU native features (external libraries are not permitted)
- The solve function signature must remain unchanged
- The result must be stored in the output array
Examples
Input: [1.0, 2.0, 3.0, 4.0]
Output: [1.0, 3.0, 6.0, 10.0]
Input: [5.0, -2.0, 3.0, 1.0, -4.0]
Output: [5.0, 3.0, 6.0, 7.0, 3.0]Constraints
- 1 ≤ N ≤ 100,000,000
- -1000.0 ≤ input[i] ≤ 1000.0
- The largest value in the output array will fit within a 32-bit float
- Performance is measured with N = 250,000