Implement element-wise addition of two vectors with a CUDA kernel.
C[i]=A[i]+B[i]A and B are the input vectors, C is the output vector, N is their common length, and i is an integer index from zero through N minus one.
Add corresponding elements without changing their order.
The buffers are contiguous arrays of 32-bit floats in device memory. Write all N results into the preallocated C buffer; the solve function returns no value.
Input: A = [1,2,3,4], B = [5,6,7,8]
Output: [6,8,10,12]
Explanation: Each output element is the sum of the two input elements at the same index.
Input: A = [1.5,2.5,3.5], B = [0.5,0.5,0.5]
Output: [2,3,4]
Use blockIdx.x, blockDim.x, and threadIdx.x to identify a thread's global element index.
The final block can contain threads whose indices are outside the vector.
Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.
Implement element-wise addition of two vectors with a CUDA kernel.
C[i]=A[i]+B[i]A and B are the input vectors, C is the output vector, N is their common length, and i is an integer index from zero through N minus one.
Add corresponding elements without changing their order.
The buffers are contiguous arrays of 32-bit floats in device memory. Write all N results into the preallocated C buffer; the solve function returns no value.
Input: A = [1,2,3,4], B = [5,6,7,8]
Output: [6,8,10,12]
Explanation: Each output element is the sum of the two input elements at the same index.
Input: A = [1.5,2.5,3.5], B = [0.5,0.5,0.5]
Output: [2,3,4]
Use blockIdx.x, blockDim.x, and threadIdx.x to identify a thread's global element index.
The final block can contain threads whose indices are outside the vector.
Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.