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

Add the cuda.core.experiemental.Linker class #229

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

Conversation

ksimpson-work
Copy link
Contributor

@ksimpson-work ksimpson-work commented Nov 8, 2024

wrap nvjitlink into the object model.
Depends on #224

Copy link

copy-pr-bot bot commented Nov 8, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@leofang leofang added this to the cuda.core beta 2 milestone Nov 11, 2024
@ksimpson-work ksimpson-work marked this pull request as ready for review November 13, 2024 17:34

__slots__ = ("_handle")

def __init__(self, options: LinkerOptions, object_codes = None):
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to revert the order:

Suggested change
def __init__(self, options: LinkerOptions, object_codes = None):
def __init__(self, *object_codes, options: LinkerOptions = None):

Taking *object_codes also allows us to loop over it later.

cuda_core/cuda/core/experimental/_linker.py Outdated Show resolved Hide resolved
Comment on lines 74 to 76
linker.add_code_object(functions[0])
linker.add_code_object(functions[1])
linker.add_code_object(functions[2])
Copy link
Collaborator

Choose a reason for hiding this comment

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

for func in compile_ptx_functions:
    linker.add_code_object(func)

But I think I'd go beyond this:

  • Add Linker.add_code_objects(self, iterable): in _linker.py and then use that here:
    linker.add_code_objects(compile_ptx_functions)
  • I'd try hard to find something here to assert, or (probably best) just drop this particular test_linker_add_code_object() function, because it's the exact same code as in the next two functions.

linker.add_code_object(functions[1])
linker.add_code_object(functions[2])

def test_linker_link_ptx(compile_ltoir_functions):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm unclear about what combinations of functions {ptx, ltoir} and target_types {ptx, cubin} are valid.

To reduce the code duplication, could this work as a general idea?

@pytest.mark.parametrize("functions", [compile_ptx_functions, compile_ltoir_functions])
@pytest.mark.parametrize("target_type", ["ptx", "cubin"])

I'm not sure if/how that works with fixtures though.

I'd also add these right here:

    log = linker.get_error_log()
    assert isinstance(log, str)
    log = linker.get_info_log()
    assert isinstance(log, str)

I think that could consolidate four test functions into one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea of using parameterize, so I added it to the linker init test. In general I write tests to be as minimal as possible, and then to build on each other. ie I like to test add_code_object() in isolation before calling it in another test such as test_linker_link_ptx. This is just something I picked up when working on my last project, as there were a lot of fragile components, and it made it a faster process to determine where the issue was. That said, you have a lot more experience than me, so I am tempted to go with your suggestion of consolidating tests. I've left it as is for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, considering the removal of add_codeObject as a public entrypoint that test can go.

@leofang leofang added P0 High priority - Must do! feature New feature or request cuda.core Everything related to the cuda.core module labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda.core Everything related to the cuda.core module feature New feature or request P0 High priority - Must do!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants