Dot Product
2026/3/9小于 1 分钟
Dot Product
题面
Implement a GPU program that computes the dot product of two vectors containing 32-bit floating point numbers. The dot product is the sum of the products of the corresponding elements of two vectors.
Mathematically, the dot product of two vectors and of length is defined as:
Implementation Requirements
- Use only GPU native features (external libraries are not permitted)
- The solve function signature must remain unchanged
- The final result must be stored in the output variable
Examples
Example 1:
Input: A = [1.0, 2.0, 3.0, 4.0]
B = [5.0, 6.0, 7.0, 8.0]
Output: result = 70.0 (1.0*5.0 + 2.0*6.0 + 3.0*7.0 + 4.0*8.0)Example 2:
Input: A = [0.5, 1.5, 2.5]
B = [2.0, 3.0, 4.0]
Output: result = 15.5 (0.5*2.0 + 1.5*3.0 + 2.5*4.0)Constraints
- A and B have identical lengths
- 1 ≤ N ≤ 100,000,000
- Performance is measured with N = 5