TensorTonic
Problems
Implement Swish (SiLU) as a CUDA Kernel
Activation FunctionsGPU Programming
Easy

Apply Swish, also called SiLU, to a vector of N float32 values on the GPU.

yi=xi1+e−xiy_i = \frac{x_i}{1 + e^{-x_i}}yi​=1+e−xi​xi​​

Here, x is the input vector, y is the output vector, and i is an element index from 0 to N minus 1. This is the standard Swish activation with a fixed sigmoid scale of one.

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 = [-2, -1, 0, 1, 2]

Output: [-0.2384, -0.2689, 0.0, 0.7311, 1.7616]

Explanation: Negative inputs retain a negative output, while positive inputs are scaled toward their original values.

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

Output: [-0.1423, -0.2736, 0.3112, 2.3104]

Hint 1

CUDA provides expf for a single-precision exponential.

Hint 2

Keep a loaded input value in a local variable when reusing it.

Hint 3

Check the global element index before accessing the buffers.

Requirements

  • Compute the stated Swish 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
ReLU 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.

Implement Swish (SiLU) as a CUDA Kernel

Implement Swish (SiLU) as a CUDA Kernel

Activation FunctionsGPU Programming
Easy

Apply Swish, also called SiLU, to a vector of N float32 values on the GPU.

yi=xi1+e−xiy_i = \frac{x_i}{1 + e^{-x_i}}yi​=1+e−xi​xi​​

Here, x is the input vector, y is the output vector, and i is an element index from 0 to N minus 1. This is the standard Swish activation with a fixed sigmoid scale of one.

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 = [-2, -1, 0, 1, 2]

Output: [-0.2384, -0.2689, 0.0, 0.7311, 1.7616]

Explanation: Negative inputs retain a negative output, while positive inputs are scaled toward their original values.

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

Output: [-0.1423, -0.2736, 0.3112, 2.3104]

Hint 1

CUDA provides expf for a single-precision exponential.

Hint 2

Keep a loaded input value in a local variable when reusing it.

Hint 3

Check the global element index before accessing the buffers.

Requirements

  • Compute the stated Swish 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
ReLU 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