TensorTonic
Problems
Vector Addition as a CUDA Kernel
GPU ProgrammingLinear Algebra
Easy

Implement element-wise addition of two vectors with a CUDA kernel.

C[i]=A[i]+B[i]C[i] = A[i] + B[i]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.

Loading visualization...

Examples

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]

Hint 1

Use blockIdx.x, blockDim.x, and threadIdx.x to identify a thread's global element index.

Hint 2

The final block can contain threads whose indices are outside the vector.

Requirements

  • Compute the specified operation independently at every valid index and store the result in C.
  • Leave input buffers unchanged and do not access memory outside the supplied buffers.
  • Preserve the supplied CUDA C++ function signatures and host launch wrapper.
  • Do not use external libraries.

Constraints

  • N is an integer from 1 through 10,000,000.
  • A, B, and C each contain N contiguous 32-bit floating-point elements in device memory.
  • Input values are finite and representable as 32-bit floats.
Try Similar Problems
Vector Subtraction as a CUDA KernelEasyOuter Product as a CUDA KernelEasyMatrix Addition as a CUDA KernelEasyHadamard Product as a CUDA KernelEasyMatrix Transpose as a CUDA KernelEasyImplement Swish (SiLU) as a CUDA KernelEasyReLU as a CUDA KernelEasyImplement Leaky ReLU as a CUDA KernelEasyImplement Sigmoid as a CUDA KernelEasyImplement Exact GELU as a CUDA KernelEasyTanh as a CUDA KernelEasyRMS Normalization as a CUDA KernelMedium

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Vector Addition as a CUDA Kernel

Vector Addition as a CUDA Kernel

GPU ProgrammingLinear Algebra
Easy

Implement element-wise addition of two vectors with a CUDA kernel.

C[i]=A[i]+B[i]C[i] = A[i] + B[i]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.

Loading visualization...

Examples

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]

Hint 1

Use blockIdx.x, blockDim.x, and threadIdx.x to identify a thread's global element index.

Hint 2

The final block can contain threads whose indices are outside the vector.

Requirements

  • Compute the specified operation independently at every valid index and store the result in C.
  • Leave input buffers unchanged and do not access memory outside the supplied buffers.
  • Preserve the supplied CUDA C++ function signatures and host launch wrapper.
  • Do not use external libraries.

Constraints

  • N is an integer from 1 through 10,000,000.
  • A, B, and C each contain N contiguous 32-bit floating-point elements in device memory.
  • Input values are finite and representable as 32-bit floats.
Try Similar Problems
Vector Subtraction as a CUDA KernelEasyOuter Product as a CUDA KernelEasyMatrix Addition as a CUDA KernelEasyHadamard Product as a CUDA KernelEasyMatrix Transpose as a CUDA KernelEasyImplement Swish (SiLU) as a CUDA KernelEasyReLU as a CUDA KernelEasyImplement Leaky ReLU as a CUDA KernelEasyImplement Sigmoid as a CUDA KernelEasyImplement Exact GELU as a CUDA KernelEasyTanh as a CUDA KernelEasyRMS Normalization as a CUDA KernelMedium

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1