A kernel should pass a correctness check before its timing is trusted. `triton.testing.assert_close` compares a result tensor with a reference and raises an error when their values exceed the allowed absolute and relative tolerances. Tolerance matters because floating-point results can differ slightly when calculations accumulate in a different order. section 2.2.10
import torch
import triton
x = torch.rand(98432, device="cuda", dtype=torch.float32)
y = torch.rand_like(x)
reference = x + y # trusted PyTorch result
result = add(x, y) # our Triton kernel from listing 2.1
triton.testing.assert_close(result, reference)
print("Triton output matches the reference within tolerance.")
Example: compare a Triton vector-add result with a PyTorch reference before benchmarking. section 2.2.10
