Skip to content

[Code Standard] Establish a Coding Standard for Return Values vs. Output Parameters in CUDA Kernels #19430

Open
@yewentao256

Description

@yewentao256

I prefer the return, it's more functional, looks more clear, and I think it's a better general c++/CUDA practice, and the compiler is nominally better at optimizing it (in general - here I think everything will be inlined anyway). So I always default to returning.

Originally posted by @ProExpertProg in #19233 (comment)

The vLLM codebase currently employs two different patterns for handling function outputs within our CUDA C++ code:

  1. Return Values: Functions return the result directly (e.g., OutType func(InType)).
  2. Output Parameters: Functions take a non-const pointer or reference to fill with the result (e.g., void func(InType, OutType*)).

While both are valid, the lack of a formal standard can lead to inconsistencies. Adopting a clear coding standard would improve readability, maintainability, and make it easier for new contributors to understand and write idiomatic code.

I would like to open this topic for discussion with the community. What are your thoughts on this? If we can reach a consensus, we can create a small guide in our contribution documentation and identify existing code that could be refactored in follow-up issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions