PIXELBANKv9.1.0
Menu

Problem Statement

Implement the ReLU activation out = max(x, 0) as a Triton kernel.

Background

Use tl.maximum to clamp negatives to zero. ReLU is the most common activation and a perfect single-op kernel.

Your Task

Implement relu_kernel and run(n=1024) comparing to torch.relu(x).

How it is tested

Your solution must define a top-level function run(...) that allocates inputs on the GPU, launches your Triton kernel, and returns a boolean from torch.allclose(triton_out, torch_reference, ...). The grader prints run(...); the expected output is True.

Example:

Input:
n = 1024
Output:
True
Reasoning:
  • The input value n = 1024 is used to allocate an input tensor x of size n on the GPU.
  • The relu_kernel function is launched, applying the ReLU activation function to each element of x using tl.maximum(x, 0), effectively setting all negative values to zero: out=max⁡(x,0)out = \max(x, 0).
  • The output of the relu_kernel function is compared to the output of torch.relu(x) using torch.allclose(triton_out, torch_reference, ...).
  • The comparison returns True if the two outputs are close enough, indicating that the relu_kernel function has been correctly implemented.

Constraints:

  • Use tl.maximum(x, 0.0)
  • Mask the tail block
solution.py

Test Results

0/0
Run code to see test results.
Triton ReLU Kernel - Easy | PixelBank