TensorTonic
Problems
ReLU as a CUDA Kernel
Activation FunctionsGPU Programming
Easy

Implement the rectified linear unit (ReLU) activation element-wise with a CUDA kernel.

y=max⁡(x,0)y = \max(x, 0)y=max(x,0)

Here x is an input element, y is its output value, and max selects the larger of its arguments. N is the number of elements in each buffer.

Negative inputs become zero, while non-negative inputs remain unchanged.

The buffers are contiguous arrays of 32-bit floats in device memory. Write all N results into the preallocated output buffer; the solve function returns no value.

Loading visualization...

Examples

Input: input = [-2,-1,0,3]

Output: [0,0,0,3]

Explanation: The two negative values become zero, while zero and three remain unchanged.

Input: input = [1,-1,2.5,-0.5]

Output: [1,0,2.5,0]

Hint 1

CUDA provides fmaxf for a single-precision maximum.

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 output.
  • Leave input buffers unchanged and do not access memory outside the supplied buffers.
  • Preserve the supplied CUDA C++ function signatures and host launch wrapper.

Constraints

  • N is an integer from 1 through 10,000,000.
  • The input and output buffers 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
Implement Swish (SiLU) as a CUDA KernelEasyImplement Leaky ReLU as a CUDA KernelEasyImplement Sigmoid as a CUDA KernelEasyImplement Exact GELU as a CUDA KernelEasyTanh as a CUDA KernelEasySoftmax as a CUDA KernelMediumVector Addition as a CUDA KernelEasyVector Subtraction as a CUDA KernelEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasyMasked Triton GELU KernelEasy

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

ReLU as a CUDA Kernel

ReLU as a CUDA Kernel

Activation FunctionsGPU Programming
Easy

Implement the rectified linear unit (ReLU) activation element-wise with a CUDA kernel.

y=max⁡(x,0)y = \max(x, 0)y=max(x,0)

Here x is an input element, y is its output value, and max selects the larger of its arguments. N is the number of elements in each buffer.

Negative inputs become zero, while non-negative inputs remain unchanged.

The buffers are contiguous arrays of 32-bit floats in device memory. Write all N results into the preallocated output buffer; the solve function returns no value.

Loading visualization...

Examples

Input: input = [-2,-1,0,3]

Output: [0,0,0,3]

Explanation: The two negative values become zero, while zero and three remain unchanged.

Input: input = [1,-1,2.5,-0.5]

Output: [1,0,2.5,0]

Hint 1

CUDA provides fmaxf for a single-precision maximum.

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 output.
  • Leave input buffers unchanged and do not access memory outside the supplied buffers.
  • Preserve the supplied CUDA C++ function signatures and host launch wrapper.

Constraints

  • N is an integer from 1 through 10,000,000.
  • The input and output buffers 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
Implement Swish (SiLU) as a CUDA KernelEasyImplement Leaky ReLU as a CUDA KernelEasyImplement Sigmoid as a CUDA KernelEasyImplement Exact GELU as a CUDA KernelEasyTanh as a CUDA KernelEasySoftmax as a CUDA KernelMediumVector Addition as a CUDA KernelEasyVector Subtraction as a CUDA KernelEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasyMasked Triton GELU KernelEasy

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1