-
Notifications
You must be signed in to change notification settings - Fork 49
[CUDA] Isolate unified api to only in cubin launcher #408
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
Conversation
This PR isolates out the unified api to be only local to cubin launcher. Background: it is generally hard to mix the driver and runtime API. The particular unified api switch was mainly meant to be used in cubin launcher for a narrow set of cuda versions(around 12.8 ish to 13.0). However, we would like the most generic macros like TVM_FFI_CHECK_CUDA_ERROR to be specific to runtime API. We should revisit if we should simply deprecate driver API usages for better maintainability.
Summary of ChangesHello @tqchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the CUDA error checking macros to provide a clearer distinction between unified API error handling and standard CUDA runtime API error handling. By introducing a specialized macro for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively isolates the unified CUDA API to the cubin launcher by renaming TVM_FFI_CHECK_CUDA_ERROR to TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR and introducing a new TVM_FFI_CHECK_CUDA_ERROR for runtime-specific API calls. This is a good refactoring that improves code clarity and maintainability. My review focuses on improving consistency across the codebase. In several places, the kernel launch and error checking can be combined into a single line, a pattern that is already present in some of the updated files. Applying this consistently will make the code more concise.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = g_add_one_kernel->Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For conciseness, you could combine the kernel launch on line 87 and this error check into a single line. This would also remove the need for the result variable. Other parts of this PR follow this more concise pattern (e.g., in docs/guides/cubin_launcher.rst).
For example:
TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(g_add_one_kernel->Launch(args, grid, block, stream));This would replace lines 87 and 88.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = g_mul_two_kernel->Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = kernel.Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = kernel.Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = kernel.Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = kernel.Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = kernel.Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Launch kernel | ||
| tvm::ffi::cuda_api::ResultType result = kernel.Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUDA_ERROR(result); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| auto result = g_kernel_add_one->Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For conciseness, you can combine these two lines into one, as has been done in other example files in this PR. This also removes the need for the result variable.
| auto result = g_kernel_add_one->Launch(args, grid, block, stream); | |
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); | |
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(g_kernel_add_one->Launch(args, grid, block, stream)); |
| auto result = g_kernel_mul_two->Launch(args, grid, block, stream); | ||
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my other comment, these two lines can be combined into a single statement for better readability and conciseness.
| auto result = g_kernel_mul_two->Launch(args, grid, block, stream); | |
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(result); | |
| TVM_FFI_CHECK_CUBIN_LAUNCHER_CUDA_ERROR(g_kernel_mul_two->Launch(args, grid, block, stream)); |
This PR isolates out the unified api to be only local to cubin launcher.
Background: it is generally error-prone to mix the driver and runtime API. The particular unified api switch was mainly meant to be used in cubin launcher for a narrow set of cuda versions(around 12.8 ish to 13.0).
However, we would like the most generic macros like TVM_FFI_CHECK_CUDA_ERROR to be specific to runtime API. We should revisit if we should simply deprecate driver API usages for better maintainability.