Skip to content

Conversation

minosfuture
Copy link
Contributor

Summary:
cuda::std::isfinite is not available with earlier CUDA versions. We guard it
with macros and extract a device function for is_finite.

Test Plan: build with 12.4 and 12.8

Reviewed By: houseroad

Differential Revision: D82918389

@facebook-github-bot
Copy link

@minosfuture has exported this pull request. If you are a Meta employee, you can view the originating diff in D82918389.

@houseroad houseroad added ready ONLY add when PR is ready to merge/full CI is needed ci/build labels Sep 21, 2025
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

The pull request introduces a compatibility wrapper is_finite to handle differences in isfinite support across CUDA versions. This is a good approach to maintain backward compatibility. My feedback focuses on improving the implementation of this new function for better robustness and readability.

Comment on lines 421 to 428
template <typename T>
__device__ inline bool is_finite(const T val) {
#if (__CUDACC_VER_MAJOR__ * 10000 + __CUDACC_VER_MINOR__ * 100 >= 120800)
bool res = cuda::std::isfinite(val);
#else
bool res = isfinite(cuda_cast<float, T>(val));
#endif
return res;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The implementation of is_finite can be improved for robustness and conciseness.

  1. The preprocessor check for the CUDA version can be made more robust and standard by using the __CUDACC_VER__ macro. This macro combines major, minor, and patch versions into a single integer (e.g., 120800 for 12.8.0), which makes the check cleaner and correctly handles patch versions if needed in the future. The current check only considers major and minor versions.
  2. The function body can be simplified by directly returning the result of the isfinite calls within the #if/#else branches, removing the need for the intermediate res variable.

Here is a suggested improved version:

template <typename T>
__device__ inline bool is_finite(const T val) {
#if defined(__CUDACC_VER__) && __CUDACC_VER__ >= 120800
  return cuda::std::isfinite(val);
#else
  return isfinite(cuda_cast<float, T>(val));
#endif
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

CUDACC_VER should be deprecated, rigth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the training data of gemini needs some refreshing :D

@facebook-github-bot
Copy link

@minosfuture has exported this pull request. If you are a Meta employee, you can view the originating diff in D82918389.

minosfuture and others added 3 commits September 21, 2025 10:26
…_kernel.cu (vllm-project#25346)

Summary:

cuda::std::isfinite is not available with earlier CUDA versions. We guard it
with macros and extract a device function for is_finite.

Test Plan: build with 12.4 and 12.8

Reviewed By: houseroad

Differential Revision:
D82918389

Privacy Context Container: L1370295

Signed-off-by: Ming Yang <minos.future@gmail.com>
…ject#25250)

Signed-off-by: Rahul Tuli <rtuli@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Ming Yang <minos.future@gmail.com>
@22quinn 22quinn enabled auto-merge (squash) September 22, 2025 06:32
Copy link
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the work!

@zhuohan123 zhuohan123 disabled auto-merge September 23, 2025 16:45
@zhuohan123 zhuohan123 merged commit 527821d into vllm-project:main Sep 23, 2025
76 of 78 checks passed
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
…_kernel.cu (vllm-project#25346)

Signed-off-by: Ming Yang <minos.future@gmail.com>
Signed-off-by: Rahul Tuli <rtuli@redhat.com>
Co-authored-by: Rahul Tuli <rtuli@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Co-authored-by: Lu Fang <30275821+houseroad@users.noreply.github.com>
Co-authored-by: Ye (Charlotte) Qi <yeq@meta.com>
yewentao256 added a commit that referenced this pull request Oct 3, 2025
…_kernel.cu (#25346)

Signed-off-by: Ming Yang <minos.future@gmail.com>
Signed-off-by: Rahul Tuli <rtuli@redhat.com>
Co-authored-by: Rahul Tuli <rtuli@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Co-authored-by: Lu Fang <30275821+houseroad@users.noreply.github.com>
Co-authored-by: Ye (Charlotte) Qi <yeq@meta.com>
Signed-off-by: yewentao256 <zhyanwentao@126.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/build ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants