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 options data class to program #237

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

Conversation

ksimpson-work
Copy link
Contributor

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

closes #221

Add the options class to Program.

TODO modify the test so that it compiles the program with options once the CI is in place. I was running into compile issues that seemed related to my environment.

Copy link

copy-pr-bot bot commented Nov 13, 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 ksimpson-work marked this pull request as ready for review November 13, 2024 00:39
Copy link

@warsawnv warsawnv left a comment

Choose a reason for hiding this comment

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

Just some drive-by observations. Feel free to ignore!

device_stack_protector: Optional[bool] = None # /**< --device-stack-protector (-device-stack-protector) Enable stack canaries in device code. */

def __post_init__(self):
# Format options into a list of strings

Choose a reason for hiding this comment

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

I don't think this comment is correct. Because of all the .encode() calls, won't self.formatted_options be a list of bytes objects? Is that really intended?

Copy link
Member

Choose a reason for hiding this comment

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

We could consider keeping strings and deferring the .encode() conversion to bytes in Program ctor. This way ProgramOptions can be easily inspected/debugged by human. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right about that being a bad comment. I will fix it. WRT your suggestion Leo, I used bytes so that we didn't need to duplicate the list of options, but perhaps that efficiency vs usability tradeoff is not worth it

cuda_core/cuda/core/experimental/_program.py Show resolved Hide resolved
if self.diag_warn is not None:
self.formatted_options.append(f"--diag-warn={self.diag_warn}".encode())
if self.brief_diagnostics is not None:
self.formatted_options.append(f"--brief-diagnostics={'true' if self.brief_diagnostics else 'false'}".encode())

Choose a reason for hiding this comment

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

The ternary statement seems like a pattern that might benefit from a helper function.

cuda_core/cuda/core/experimental/_program.py Show resolved Hide resolved
@leofang leofang added P1 Medium priority - Should do cuda.core Everything related to the cuda.core module enhancement Any code-related improvements labels Nov 14, 2024
@leofang leofang added this to the cuda.core beta 2 milestone Nov 14, 2024
from dataclasses import dataclass

@dataclass
class ProgramOptions:
Copy link
Member

Choose a reason for hiding this comment

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

TODO:

  1. As we discussed briefly offline, let's find out if we can autogen the docstrings. It should contain the description for the option, the default value if unset, acceptable value type, and then explain what the underlying C option it maps to, something like (no need to take this literally)
gpu_architecture : Specify the name of the class of GPU architectures for which the input must be compiled.

.. seealso:: ` --gpu-architecture`, `-arch`
  1. There are some options we might have to tweak/combine, e.g. device_c vs relocatable_device_code. Let's chat offline about this.
  2. For gpu_architecture I think we should detect the current device's CC if it's unset, instead of falling back to NVRTC default

@leofang
Copy link
Member

leofang commented Nov 14, 2024

Just some drive-by observations. Feel free to ignore!

Thanks, Berry 🙏 We welcome feedbacks and won't ignore anyone!

@leofang
Copy link
Member

leofang commented Nov 14, 2024

Another TODO: Let's also update the code samples and show the best practice!

@warsawnv
Copy link

Another TODO: Let's also update the code samples and show the best practice!

Is there a way to add these as doctests so that the code samples must always be kept in working order?

@ksimpson-work
Copy link
Contributor Author

@warsawnv Totally. I'm actively working on getting github actions working, and the examples are invoked as part of the testsuite.

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 P1 Medium priority - Should do
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Program.compile() options parameter is not handled properly
3 participants