TensorTonic
Problems
ReLU in Triton
Activation FunctionsGPU Programming
Easy

Implement the rectified linear unit activation in Triton. For each input element:

out[i]=max⁡(x[i],0)\texttt{out}[i] = \max(x[i], 0)out[i]=max(x[i],0)

ReLU is a pure pointwise nonlinearity, the simplest activation in deep learning. In Triton it is one extra step on top of vector addition: load the tile, clamp negatives to zero, store the result. The pattern generalizes to every activation kernel in the library.

Loading visualization...

Examples

Input: x = [-1.0, 0.0, 1.0, -2.5, 3.0]

Output: [0.0, 0.0, 1.0, 0.0, 3.0]

Input: x = [2.0, -3.0, 4.0]

Output: [2.0, 0.0, 4.0]

Hint 1

Triton exposes an elementwise maximum that fuses the clamp into one instruction. A branch-free select against the scalar zero works just as well.

Hint 2

Same tail-mask discipline as vector add: every load and store needs the same offsets < N\texttt{offsets < N}offsets < N mask, no special-casing the last tile.

Hint 3

No reduction, no cross-lane communication. This is a pure map with one read, one compute, one write.

Requirements

  • Use one Triton program per contiguous tile of the input
  • Apply the rectification without a divergent branch
  • Guard against indices beyond NNN on every load and store
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1061 \le N \le 10^61≤N≤106.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-3.
Try Similar Problems
GELU in TritonEasySiLU in TritonEasyVector Addition in TritonEasyFused Multiply-Add in TritonEasyOnline Softmax Kernel in TritonMediumFused Row-Wise Softmax in TritonMediumFused Matmul + Bias + ReLU in TritonMediumImplement 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 KernelEasy

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

ReLU in Triton

ReLU in Triton

Activation FunctionsGPU Programming
Easy

Implement the rectified linear unit activation in Triton. For each input element:

out[i]=max⁡(x[i],0)\texttt{out}[i] = \max(x[i], 0)out[i]=max(x[i],0)

ReLU is a pure pointwise nonlinearity, the simplest activation in deep learning. In Triton it is one extra step on top of vector addition: load the tile, clamp negatives to zero, store the result. The pattern generalizes to every activation kernel in the library.

Loading visualization...

Examples

Input: x = [-1.0, 0.0, 1.0, -2.5, 3.0]

Output: [0.0, 0.0, 1.0, 0.0, 3.0]

Input: x = [2.0, -3.0, 4.0]

Output: [2.0, 0.0, 4.0]

Hint 1

Triton exposes an elementwise maximum that fuses the clamp into one instruction. A branch-free select against the scalar zero works just as well.

Hint 2

Same tail-mask discipline as vector add: every load and store needs the same offsets < N\texttt{offsets < N}offsets < N mask, no special-casing the last tile.

Hint 3

No reduction, no cross-lane communication. This is a pure map with one read, one compute, one write.

Requirements

  • Use one Triton program per contiguous tile of the input
  • Apply the rectification without a divergent branch
  • Guard against indices beyond NNN on every load and store
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1061 \le N \le 10^61≤N≤106.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-3.
Try Similar Problems
GELU in TritonEasySiLU in TritonEasyVector Addition in TritonEasyFused Multiply-Add in TritonEasyOnline Softmax Kernel in TritonMediumFused Row-Wise Softmax in TritonMediumFused Matmul + Bias + ReLU in TritonMediumImplement 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 KernelEasy

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1