Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linking of external code from callees #137

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gmarkall
Copy link
Collaborator

The original linking implementation for linkable code in device declarations did not consider calls inside callees; this change recurses through the typing to find all calls requiring linkable code.

The original linking implementation for linkable code in device
declarations did not consider calls inside callees; this change recurses
through the typing to find all calls requiring linkable code.
@gmarkall gmarkall added the 2 - In Progress Currently a work in progress label Feb 26, 2025
Comment on lines +51 to +68
# The typemap of the function includes calls, so we can traverse it to find
# the references we need.
for name, v in cres.fndesc.typemap.items():

# CUDADispatchers represent a call to a device function, so we need to
# look up the linkable code for those recursively.
if isinstance(v, cuda_types.CUDADispatcher):
# We need to locate the signature of the call so we can find the
# correct overload.
for call, sig in cres.fndesc.calltypes.items():
if isinstance(call, ir.Expr) and call.op == 'call':
# There will likely be multiple calls in the typemap; we
# can uniquely identify the relevant one using its SSA
# name.
if call.func.name == name:
called_cres = v.dispatcher.overloads[sig.args]
called_link_objects = get_cres_link_objects(called_cres)
link_objects.update(called_link_objects)
Copy link
Collaborator

@isVoid isVoid Mar 2, 2025

Choose a reason for hiding this comment

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

This is cool. I learnt a few things by reading through this section. Do you think the below simplifies the code and reduces the code complexity for a little bit?

I made a PR here:
gmarkall#4

I think this reduces the size of the list for both of the nested for-loop. This is proportional to O(num_calls^2), not O(num_typings^2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - In Progress Currently a work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants