What pid Indexes in a Triton Kernel
@triton.jit
def add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
x = tl.load(x_ptr + offsets, mask=mask)
y = tl.load(y_ptr + offsets, mask=mask)
tl.store(output_ptr + offsets, x + y, mask=mask)
grid = lambda meta: (triton.cdiv(n_elements, meta['BLOCK_SIZE']), )
A CUDA developer reads this and asks where the per-thread code went. Which reading is correct?
Sign in to answer questions and track your progress
Sign In