Implement element-wise subtraction of two vectors with a CUDA kernel.
C[i]=A[i]−B[i]A is the first input vector, B is the vector subtracted from it, C is the output vector, N is their common length, and i is an integer index from zero through N minus one.
Subtract the second vector from the first at each index; reversing the operands changes the result.
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: [-4,-4,-4,-4]
Explanation: At every index, subtracting the second input value from the first gives negative four.
Input: A = [1.5,2.5,3.5], B = [0.5,0.5,0.5]
Output: [1,2,3]
Use blockIdx.x, blockDim.x, and threadIdx.x to identify a thread's global element index.
Check both operand order and whether the index lies inside the vector.
Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.
Implement element-wise subtraction of two vectors with a CUDA kernel.
C[i]=A[i]−B[i]A is the first input vector, B is the vector subtracted from it, C is the output vector, N is their common length, and i is an integer index from zero through N minus one.
Subtract the second vector from the first at each index; reversing the operands changes the result.
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: [-4,-4,-4,-4]
Explanation: At every index, subtracting the second input value from the first gives negative four.
Input: A = [1.5,2.5,3.5], B = [0.5,0.5,0.5]
Output: [1,2,3]
Use blockIdx.x, blockDim.x, and threadIdx.x to identify a thread's global element index.
Check both operand order and whether the index lies inside the vector.
Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.