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
13 changes: 13 additions & 0 deletions python/test/unit/language/test_compile_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,16 @@ def good_cube_kernel():
obtained_err_msg = str(e.value).split('\n')[-1]

assert expected_err_msg == obtained_err_msg


def test_err_constexpr_and_do_not_specialize():

@triton.jit(do_not_specialize=["N"])
def kernel(N: tl.constexpr):
pass

with pytest.raises(CompilationError, match="N marked as constexpr and listed in do_not_specialize"):
triton.compile(triton.compiler.ASTSource(fn=kernel, signature={}, constexprs={"N": 5}))

with pytest.raises(CompilationError, match="N marked as constexpr and listed in do_not_specialize"):
kernel[(1, )](5)
6 changes: 6 additions & 0 deletions python/triton/compiler/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ def visit_arguments(self, node):

def visit_arg(self, node):
ast.NodeVisitor.generic_visit(self, node)
param = next(p for p in self.jit_fn.params if p.name == node.arg)
if param.is_constexpr and (param.do_not_specialize or param.do_not_specialize_on_alignment):
raise CompilationError(
self.jit_fn.src, node,
f"{node.arg} marked as constexpr and listed in do_not_specialize/do_not_specialize_on_alignment. "
"Remove constexpr designation to skip specialization.")
return node.arg

def visit_AnnAssign(self, node):
Expand Down