Skip to content

Commit

Permalink
[FRONTEND] Fix arg name conflict bug (triton-lang#3383)
Browse files Browse the repository at this point in the history
There is a bug introduced in latest triton code where AttributeError is
getting thrown if kernel function args has same name as global variable.

Co-authored-by: Keren Zhou <kerenzhou@openai.com>
  • Loading branch information
Sarbojit2019 and Jokeren authored Mar 22, 2024
1 parent 982fbc4 commit dca2d07
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/triton/runtime/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def ret(self):
return self.hasher.hexdigest()

def visit_Name(self, node):
if node.id in self.local_names:
# The global name is hidden by the local name.
return None
return self.globals.get(node.id, None)

def visit_Attribute(self, node):
Expand Down Expand Up @@ -77,6 +80,21 @@ def is_triton_builtin(func):
key = func_cache_key + noinline
self.hasher.update(key.encode("utf-8"))

def visit_FunctionDef(self, node):
# Save the local name which may hide the global name.
self.local_names = [arg.arg for arg in node.args.args]
self.generic_visit(node)

def visit_Assign(self, node):
_names = []
for target in node.targets:
_names += [self.visit(target)]
if len(_names) == 1:
self.local_names += _names
else:
raise TypeError("Simultaneous multiple assignment is not supported.")
self.generic_visit(node)


# -----------------------------------------------------------------------------
# JITFunction
Expand Down

0 comments on commit dca2d07

Please sign in to comment.