TensorTonic
Problems
Implement Exact GELU as a CUDA Kernel
Activation FunctionsGPU Programming
Easy

Apply the error-function form of GELU to a vector of N float32 values on the GPU.

yi=xi2(1+erf⁡(xi2))y_i = \frac{x_i}{2}\left(1 + \operatorname{erf}\left(\frac{x_i}{\sqrt{2}}\right)\right)yi​=2xi​​(1+erf(2​xi​​))

Here, x is the input vector, y is the output vector, i is an element index from 0 to N minus 1, and erf is the Gaussian error function. Use this definition rather than the tanh approximation.

Write all N results into the preallocated float32 output device buffer, preserving their order and leaving the input unchanged. The function returns no value.

Loading visualization...

Examples

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

Output: [-0.1587, 0.0, 0.8413, 1.9545]

Explanation: GELU retains a small negative output at -1 and smoothly scales the positive values.

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

Output: [-0.0155, -0.1543, 0.3457, 2.4845]

Hint 1

CUDA provides erff for a single-precision error function.

Hint 2

A precomputed reciprocal square root of two avoids repeated division.

Hint 3

Check the global element index before accessing the buffers.

Requirements

  • Compute the error-function GELU activation for every input value.
  • Write every output element without changing the input or accessing beyond the buffers.
  • Keep the supplied solve interface.

Constraints

  • N is between 1 and 10,000,000.
  • Input and output are contiguous device buffers containing N float32 values.
  • Input values are finite.
Try Similar Problems
Implement Swish (SiLU) as a CUDA KernelEasyReLU as a CUDA KernelEasyImplement Leaky ReLU as a CUDA KernelEasyImplement Sigmoid 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.

Implement Exact GELU as a CUDA Kernel

Implement Exact GELU as a CUDA Kernel

Activation FunctionsGPU Programming
Easy

Apply the error-function form of GELU to a vector of N float32 values on the GPU.

yi=xi2(1+erf⁡(xi2))y_i = \frac{x_i}{2}\left(1 + \operatorname{erf}\left(\frac{x_i}{\sqrt{2}}\right)\right)yi​=2xi​​(1+erf(2​xi​​))

Here, x is the input vector, y is the output vector, i is an element index from 0 to N minus 1, and erf is the Gaussian error function. Use this definition rather than the tanh approximation.

Write all N results into the preallocated float32 output device buffer, preserving their order and leaving the input unchanged. The function returns no value.

Loading visualization...

Examples

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

Output: [-0.1587, 0.0, 0.8413, 1.9545]

Explanation: GELU retains a small negative output at -1 and smoothly scales the positive values.

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

Output: [-0.0155, -0.1543, 0.3457, 2.4845]

Hint 1

CUDA provides erff for a single-precision error function.

Hint 2

A precomputed reciprocal square root of two avoids repeated division.

Hint 3

Check the global element index before accessing the buffers.

Requirements

  • Compute the error-function GELU activation for every input value.
  • Write every output element without changing the input or accessing beyond the buffers.
  • Keep the supplied solve interface.

Constraints

  • N is between 1 and 10,000,000.
  • Input and output are contiguous device buffers containing N float32 values.
  • Input values are finite.
Try Similar Problems
Implement Swish (SiLU) as a CUDA KernelEasyReLU as a CUDA KernelEasyImplement Leaky ReLU as a CUDA KernelEasyImplement Sigmoid 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