Skip to content

feat: add cuLaunchKernelEx support#476

Merged
cyx-6 merged 4 commits intoapache:mainfrom
lucifer1004:launch-ex
Feb 27, 2026
Merged

feat: add cuLaunchKernelEx support#476
cyx-6 merged 4 commits intoapache:mainfrom
lucifer1004:launch-ex

Conversation

@lucifer1004
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lucifer1004, 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 integrates support for CUDA's extended kernel launch API, cuLaunchKernelEx, into the CubinLauncher. This enhancement allows users to leverage advanced GPU features, such as cluster dimensions on SM90+ architectures, by providing new functions to construct launch configurations and execute kernels with these extended capabilities.

Highlights

  • Extended Kernel Launch API: Introduced a new LaunchEx method in the CubinKernel class, enabling the use of CUDA's extended kernel launch API (cuLaunchKernelEx / cudaLaunchKernelExC) with pre-built launch configurations.
  • Cluster Dimensions Support: Added LaunchKernelEx and ConstructLaunchConfig functions within the CUDA unified API, providing the necessary infrastructure to configure and launch kernels with advanced features like cluster dimensions for SM90+ architectures.

🧠 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.

Changelog
  • include/tvm/ffi/extra/cuda/cubin_launcher.h
    • Added LaunchEx method to CubinKernel for extended kernel launches.
  • include/tvm/ffi/extra/cuda/internal/unified_api.h
    • Implemented LaunchKernelEx function to support extended CUDA kernel launching.
    • Added ConstructLaunchConfig function to build launch configurations, including cluster dimensions.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 introduces support for the extended CUDA kernel launch APIs (cuLaunchKernelEx and cudaLaunchKernelExC), which is a valuable addition for leveraging modern CUDA features like cluster launch. The implementation is well-organized, adding new wrappers in unified_api.h and exposing them through the CubinKernel class. My review includes a few suggestions to enhance correctness and code quality, focusing on an unnecessary const_cast, a redundant and potentially problematic function call for setting shared memory, and a type suggestion for a function parameter to improve correctness.

Comment on lines +229 to +238
if (smem_size > 0) {
#if TVM_FFI_CUBIN_LAUNCHER_USE_DRIVER_API
err = cuFuncSetAttribute(reinterpret_cast<CUfunction>(kernel),
CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, smem_size);
#else
err = cudaFuncSetAttribute(reinterpret_cast<const void*>(kernel),
cudaFuncAttributeMaxDynamicSharedMemorySize, smem_size);
#endif
if (err != kSuccess) return err;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This block of code incorrectly sets a persistent kernel attribute (MAX_DYNAMIC_SHARED_SIZE_BYTES) on every launch. The dynamic shared memory for a specific launch should be configured via the LaunchConfig struct, which is already being done correctly later in this function.

Setting this attribute here is not only redundant but can also lead to incorrect behavior. For instance, launching a kernel with a smaller shared memory size after one with a larger size would incorrectly cap the maximum shared memory for all subsequent launches of this kernel. This functionality is properly handled by CubinKernel::SetMaxDynamicSharedMemory.

Please remove this block.

Comment on lines +202 to +210
inline ResultType LaunchKernelEx(KernelHandle kernel, void** args, const LaunchConfig& config) {
// The underlying CUDA APIs take a pointer to config but do not modify it
auto* mutable_config = const_cast<LaunchConfig*>(&config);
#if TVM_FFI_CUBIN_LAUNCHER_USE_DRIVER_API
return cuLaunchKernelEx(mutable_config, reinterpret_cast<CUfunction>(kernel), args, nullptr);
#else
return cudaLaunchKernelExC(mutable_config, reinterpret_cast<const void*>(kernel), args);
#endif
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The const_cast to get a mutable pointer to config is unnecessary. Both the cuLaunchKernelEx (Driver API) and cudaLaunchKernelExC (Runtime API) functions expect a const pointer to their respective configuration structs. You can simplify the code and improve safety by passing &config directly.

inline ResultType LaunchKernelEx(KernelHandle kernel, void** args, const LaunchConfig& config) {
#if TVM_FFI_CUBIN_LAUNCHER_USE_DRIVER_API
  return cuLaunchKernelEx(&config, reinterpret_cast<CUfunction>(kernel), args, nullptr);
#else
  return cudaLaunchKernelExC(&config, reinterpret_cast<const void*>(kernel), args);
#endif
}

* \param[out] attr Storage for a launch attribute (must outlive the launch call).
* \return Result code from setting shared memory attribute, or kSuccess.
*/
inline ResultType ConstructLaunchConfig(KernelHandle kernel, StreamHandle stream, int smem_size,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The smem_size parameter represents the dynamic shared memory size, which cannot be negative. Using int is not ideal for this purpose. For better type safety and consistency with other parts of the API, such as CubinKernel::Launch which uses uint32_t, please consider changing the type to uint32_t.

inline ResultType ConstructLaunchConfig(KernelHandle kernel, StreamHandle stream, uint32_t smem_size,

Copy link
Contributor

@cyx-6 cyx-6 left a comment

Choose a reason for hiding this comment

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

thanks for improving!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants