-
Notifications
You must be signed in to change notification settings - Fork 470
feat: support green ctx creation by a list of SM counts #1190
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
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.
Summary of Changes
Hello @Conless, 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 significantly enhances the flashinfer
library's ability to manage GPU resources by introducing a flexible mechanism for creating CUDA Green Contexts with explicit control over the number of Streaming Multiprocessors (SMs allocated to each context. This feature is crucial for advanced workload partitioning and performance optimization on NVIDIA GPUs.
Highlights
- New Green Context Creation API: I've introduced a new public function,
split_device_green_ctx_by_sm_count
, which allows users to create CUDA Green Contexts by specifying a list of desired SM (Streaming Multiprocessor) counts for each partition. This provides more granular control over GPU resource allocation compared to the existingsplit_device_green_ctx
function. - SM Count Alignment Logic: The new API automatically handles the complexities of SM count alignment and granularity requirements based on the specific CUDA compute capability of the device. It includes a new helper function,
get_sm_count_constraint
, to determine these requirements (minimum SM count and alignment factor). - Resource Splitting Helper: A new internal helper function,
split_resource_by_sm_count
, was added to manage the iterative splitting of GPU resources based on the provided list of SM counts, ensuring that the remaining resources are correctly updated for subsequent allocations. - Comprehensive Testing: New tests have been added to verify the correct creation of green contexts with specified SM counts, successful kernel execution on these contexts, and proper adherence to SM alignment rules for different CUDA capabilities.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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
The code changes introduce the split_device_green_ctx_by_sm_count
function to create green contexts by specifying a list of SM counts. The review identifies a critical resource leak and suggests improvements to function purity and state management.
desc = checkCudaErrors(driver.cuDevResourceGenerateDesc([remaining], 1)) | ||
green_ctx = checkCudaErrors( | ||
driver.cuGreenCtxCreate( | ||
desc, cu_dev, driver.CUgreenCtxCreate_flags.CU_GREEN_CTX_DEFAULT_STREAM | ||
) | ||
) | ||
resource = checkCudaErrors( | ||
driver.cuGreenCtxGetDevResource( | ||
green_ctx, driver.CUdevResourceType.CU_DEV_RESOURCE_TYPE_SM | ||
) | ||
) |
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.
The green_ctx
created in the loop is not destroyed, leading to a CUDA resource leak. cuGreenCtxCreate
should be paired with cuGreenCtxDestroy
. Use a try...finally
block to ensure destruction even if cuGreenCtxGetDevResource
raises an exception.
desc = checkCudaErrors(driver.cuDevResourceGenerateDesc([remaining], 1)) | |
green_ctx = checkCudaErrors( | |
driver.cuGreenCtxCreate( | |
desc, cu_dev, driver.CUgreenCtxCreate_flags.CU_GREEN_CTX_DEFAULT_STREAM | |
) | |
) | |
resource = checkCudaErrors( | |
driver.cuGreenCtxGetDevResource( | |
green_ctx, driver.CUdevResourceType.CU_DEV_RESOURCE_TYPE_SM | |
) | |
) | |
desc = checkCudaErrors(driver.cuDevResourceGenerateDesc([remaining], 1)) | |
green_ctx = checkCudaErrors( | |
driver.cuGreenCtxCreate( | |
desc, cu_dev, driver.CUgreenCtxCreate_flags.CU_GREEN_CTX_DEFAULT_STREAM | |
) | |
) | |
try: | |
resource = checkCudaErrors( | |
driver.cuGreenCtxGetDevResource( | |
green_ctx, driver.CUdevResourceType.CU_DEV_RESOURCE_TYPE_SM | |
) | |
) | |
finally: | |
checkCudaErrors(driver.cuGreenCtxDestroy(green_ctx)) |
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.
explicit destruction may not be that important (memory overhead is 4MB per context)
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.
Overall LGTM, left some suggestions.
The official documentation link https://docs.flashinfer.ai/ returns a 404 error.
|
📌 Description
Add
split_device_green_ctx_by_sm_count
to create green context by a list of SM count.🔍 Related Issues
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commit
by runningpip install pre-commit
(or used your preferred method).pre-commit install
.pre-commit run --all-files
and fixed any reported issues.🧪 Tests
unittest
, etc.).Reviewer Notes
cc @yzh119