Write a Triton kernel relu_kernel and a Python wrapper relu(x) that applies ReLU element-wise on the GPU.
Kernel signature:
@triton.jit
def relu_kernel(x_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
Wrapper:
def relu(x: torch.Tensor) -> torch.Tensor
Use BLOCK_SIZE = 1024 and the standard 1-D grid.
tl.maximum(x, 0.0) is the element-wise max - the cleanest way to express ReLU in Triton.tl.where(x > 0, x, 0.0) works too. Both compile to the same instructions on most GPUs.