Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,36 @@ def my_kernel(x_ptr, y_ptr, out_ptr, BLOCK_SIZE: tl.constexpr):
assert sum(c == "tracer" for c in clients) == 1


# ======== Nested JIT Call Tests =========
@triton_viz.trace(clients=Sanitizer(abort_on_error=True))
@triton.jit
def trace_nested_inner_kernel(x):
return x * 2


def test_trace_nested_jit_calls():
"""
Test that Trace class properly handles nested JIT function calls via __call__ method.

When a traced JIT function is called from within another JIT function,
the Trace wrapper needs to properly delegate to the underlying function.
This test ensures compatibility with nested Triton JIT function calls.
"""

@triton_viz.trace(clients=Sanitizer(abort_on_error=True))
@triton.jit
def trace_nested_call_kernel(ptr, n: tl.constexpr):
x = tl.load(ptr + tl.arange(0, n))
y = trace_nested_inner_kernel(
x
) # This nested call requires __call__ method when wrapped by trace
tl.store(ptr + tl.arange(0, n), y)

# Test execution
data = torch.ones(8)
trace_nested_call_kernel[(1,)](data, 8)


# ======== Wrapper Tests =========
# Test that triton_viz.wrapper works correctly:
# 1. It should patch triton.jit / triton.language.jit /
Expand Down
5 changes: 5 additions & 0 deletions triton_viz/core/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def run(self, *args, **kwargs):
self.finalize()
return ret

def __call__(self, *args, **kwargs):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should interpret this function as well using its interpreter_fn

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise you cannot intercept any loads and stores in this function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a test

# When a traced JIT function is called from within another JIT function,
# we need to execute the underlying function directly
return self.base_fn(*args, **kwargs)

def warmup(self, *args, **kwargs):
raise NotImplementedError

Expand Down