← All problems
#65 GEGLU Easy

Implement the Gaussian Error Gated Linear Unit (GEGLU) activation function forward pass for 1D input vectors. Given an input tensor of shape [N] where N is the number of elements, compute the output using the elementwise formula. The input and output tensor must be of type float32.

GEGLU is defined as:

  1. Split input \(x\) into two halves: \(x_1\) and \(x_2\)
  2. Compute GELU on the second half: \[ \text{GELU}(x_2) = \frac{1}{2} x_2 \left(1 + \text{erf}\left(\frac{x_2}{\sqrt{2}}\right)\right) \]
  3. Compute the GEGLU output: \[ \text{GEGLU}(x_1, x_2) = x_1 \cdot \text{GELU}(x_2) \]

Implementation Requirements

Example 1:

Input:  [1.0, 1.0]  (N=2)
Output: [0.8413447]

Example 2:

Input:  [2.0, -1.0, 1.0, 0.5]  (N=4)
Output: [1.6826895, -0.3457312]

Constraints

Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.