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

support ptx code type for program #317

Merged
merged 17 commits into from
Feb 4, 2025

Conversation

ksimpson-work
Copy link
Contributor

@ksimpson-work ksimpson-work commented Dec 19, 2024

support PTX as a code type for Program. This is achieved by using the linker as a backend for Program when the input type is PTX.

This includes a translation from program options to linker options in the program class. Which inspired the removal of the Maps to section of option documentation for linker and program which now both sometimes map to other things that what was documented. (linker to either nvjitlink or culink and program to either nvrtc, nvjitlink or culink)

This also inspired the handling of deprecated options in culink to raise warnings instead of errors. This allows a user to write cuda which targets a deprecated option if they are developing on an older system and deploying on a newer one for example.

close #284

Copy link
Contributor

copy-pr-bot bot commented Dec 19, 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.

@ksimpson-work
Copy link
Contributor Author

/ok to test

@leofang leofang requested review from leofang and shwina December 20, 2024 00:19
@leofang leofang added enhancement Any code-related improvements P0 High priority - Must do! cuda.core Everything related to the cuda.core module labels Dec 20, 2024
@leofang leofang added this to the cuda.core beta 3 milestone Dec 20, 2024
@leofang leofang linked an issue Dec 27, 2024 that may be closed by this pull request
@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work
Copy link
Contributor Author

/ok to test

This comment has been minimized.

@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work ksimpson-work marked this pull request as ready for review January 22, 2025 16:50
@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work
Copy link
Contributor Author

/ok to test

Copy link
Member

@leofang leofang left a comment

Choose a reason for hiding this comment

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

Thanks, Keenan. I haven't reviewed tests yet. Will resume shortly.

cuda_core/cuda/core/experimental/_program.py Show resolved Hide resolved
cuda_core/cuda/core/experimental/_program.py Outdated Show resolved Hide resolved
cuda_core/cuda/core/experimental/_program.py Show resolved Hide resolved
cuda_core/cuda/core/experimental/_program.py Show resolved Hide resolved
cuda_core/cuda/core/experimental/_program.py Outdated Show resolved Hide resolved
link_time_optimization=options.link_time_optimization,
split_compile=options.split_compile,
)

def close(self):
"""Destroy this program."""
self._mnff.close()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self._mnff.close()
self._mnff.close()
if self._linker:
self._linker.close()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an advantage to explicitly closing the Linker instance from the Program finalizer rather than letting Program decrement the Linker instance refcount and relying on the established logic in Linker? My instincts tell me to rely on the python runtime garbage collection scheduling for PyObjects.

I've changed the mnff handle attribute name to nvrtc_handle to be more explicit, since before it felt implied that you were referencing a handle that was inherent to the Program instance, rather than a backend dependent handle. Let me know what you think. Functionally there is no difference

Copy link
Member

Choose a reason for hiding this comment

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

The semantics of close() is: Destruct every resource that this object owns immediately, and consider this object no longer usable after close() returns. It does not rely on the gc behavior, which is the last resort (gc can defer the destruction at an arbitrarily later time). We need this guarantee for certain use cases.

Copy link
Member

Choose a reason for hiding this comment

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

It is a good catch about Program.handle. I think it should return either nvrtc_handle or linker.handle (which is either nvjitlink handle or cuLink handle). For clarity on the semantics of the handle, we should make Linker.backend queryable (it is not today), so that Program.backend returns Linker.backend if it's using the linker under the hood. Then we teach users about "check which backend is in use to determine how to interpret the handle". WDYT?

We should fix this asap but perhaps in a separate PR. Would you mind creating a new issue to track this?

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 follow your point for the close() method. I will implement it as you suggest.

For the handles, I'm a bit torn. It makes sense that we would return a handle / backend of equivalent level of abstraction to that of nvrtc ( return a handle, or the binding level backend ), however it also feels like we are breaking the Linker's abstraction by doing so. An nvrtc backed Program's handle is an ~nvrtcProgramHandle, while a linker backed Program doesn't really have a handle. It has a linker backend which has a culinkHandle or nvjitLinkHandle which is a handle to the linker rather than a program. Tradeoff between handle semantic consistency and abstraction consistency.

The same tradeoff feels relevant to the return value of Program.backend (either Linker, or Linker.backend).

The only thing I feel sure of, is that we should put this in a new issue and discuss it on a call. In the meantime I will revert the handle name change I made so this review as isolated as possible from that discussion. #433 is the issue

cuda_core/tests/test_linker.py Outdated Show resolved Hide resolved
cuda_core/tests/test_program.py Outdated Show resolved Hide resolved
@leofang
Copy link
Member

leofang commented Feb 2, 2025

Let's also remove this TODO line:

# TODO: handle jit_options for ptx?

@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work
Copy link
Contributor Author

/ok to test

@leofang
Copy link
Member

leofang commented Feb 4, 2025

/ok to test

@leofang leofang enabled auto-merge February 4, 2025 05:24
@leofang leofang merged commit 8ed9c03 into NVIDIA:main Feb 4, 2025
69 checks passed
Copy link

github-actions bot commented Feb 4, 2025

Doc Preview CI
Preview removed because the pull request was closed or merged.

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 enhancement Any code-related improvements P0 High priority - Must do!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "ptx" code type in Program
2 participants