MCPcopy Create free account
hub / github.com/apache/tvm / add_kernel

Function add_kernel

tests/python/contrib/test_tir_triton_integration.py:47–62  ·  view source on GitHub ↗

Triton vector add kernel from its tutorial.

(
        x_ptr,  # *Pointer* to first input vector.
        y_ptr,  # *Pointer* to second input vector.
        output_ptr,  # *Pointer* to output vector.
        n_elements,  # Size of the vector.
        BLOCK_SIZE: tl.constexpr,  # Number of elements each program should process.
    )

Source from the content-addressed store, hash-verified

45def test_tir_triton_integration():
46 @triton.jit
47 def add_kernel(
48 x_ptr, # *Pointer* to first input vector.
49 y_ptr, # *Pointer* to second input vector.
50 output_ptr, # *Pointer* to output vector.
51 n_elements, # Size of the vector.
52 BLOCK_SIZE: tl.constexpr, # Number of elements each program should process.
53 ):
54 """Triton vector add kernel from its tutorial."""
55 pid = tl.program_id(axis=0) # We use a 1D launch grid so axis is 0.
56 block_start = pid * BLOCK_SIZE
57 offsets = block_start + tl.arange(0, BLOCK_SIZE)
58 mask = offsets < n_elements
59 x = tl.load(x_ptr + offsets, mask=mask)
60 y = tl.load(y_ptr + offsets, mask=mask)
61 output = x + y
62 tl.store(output_ptr + offsets, output, mask=mask)
63
64 @I.ir_module(s_tir=True)
65 class Module:

Callers

nothing calls this directly

Calls 2

arangeMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…