Implement the rectified linear unit activation in Triton. For each input element:
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.
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]
Triton exposes an elementwise maximum that fuses the clamp into one instruction. A branch-free select against the scalar zero works just as well.
Same tail-mask discipline as vector add: every load and store needs the same offsets < N mask, no special-casing the last tile.
No reduction, no cross-lane communication. This is a pure map with one read, one compute, one write.
torch.float32 on cuda.atol=1e-3.Accepts: array
Submit a correct solution to see your kernel performance.
Implement the rectified linear unit activation in Triton. For each input element:
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.
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]
Triton exposes an elementwise maximum that fuses the clamp into one instruction. A branch-free select against the scalar zero works just as well.
Same tail-mask discipline as vector add: every load and store needs the same offsets < N mask, no special-casing the last tile.
No reduction, no cross-lane communication. This is a pure map with one read, one compute, one write.
torch.float32 on cuda.atol=1e-3.Accepts: array
Submit a correct solution to see your kernel performance.