BootGPUPeak LLM Kernels
T4
中文

Vector Addition

Easy

Given two arrays a and b of N floats, compute their element-wise sum into c:

c[i] = a[i] + b[i]

Requirements

  • Implement solve in the starter of the framework you choose; keep its signature.
    • CUDA: extern "C" void solve(const float* a, const float* b, float* c, int N)
    • Triton, PyTorch: def solve(a: torch.Tensor, b: torch.Tensor, c: torch.Tensor, N: int)
  • a, b and c are already on the GPU. Do not modify a or b.
  • Write the result into c in place; its contents on entry are undefined. In Python, c = a + b only rebinds the local name and leaves c unwritten.

Examples

Input:  a = [1.0, 2.0, 3.0, 4.0], b = [10.0, 20.0, 30.0, 40.0], N = 4
Output: c = [11.0, 22.0, 33.0, 44.0]
Input:  a = [0.5, -1.5, 2.0], b = [-0.5, 1.0, 0.25], N = 3
Output: c = [0.0, -0.5, 2.25]

Constraints

  • 1 ≤ N ≤ 25,000,000
  • -1000 ≤ a[i], b[i] ≤ 1000
  • An output is accepted if it is within 1e-5 + 1e-5 × |expected| of the expected value
  • Performance is measured with N = 25,000,000
solution.cu

Run checks the example test. Submit runs all tests and records the pass.