Conversation
Summary of ChangesHello @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, 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. Changelog
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.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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,
No description provided.