Skip to content

[Common] Fix "0" literal for compilation#2934

Merged
cyanguwa merged 1 commit intoNVIDIA:mainfrom
cyanguwa:fix_2719_int
Apr 28, 2026
Merged

[Common] Fix "0" literal for compilation#2934
cyanguwa merged 1 commit intoNVIDIA:mainfrom
cyanguwa:fix_2719_int

Conversation

@cyanguwa
Copy link
Copy Markdown
Collaborator

@cyanguwa cyanguwa commented Apr 27, 2026

Description

This PR fixes a zero-init ambiguity for CUDA 12.1 (used in GitHub CI). By using a floating zero literal, static_cast<T>(0.f) goes down the float constructor unambiguously.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

See Description.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR fixes a compilation ambiguity in CUDA 12.1 by replacing static_cast<T>(0) with static_cast<T>(0.f) in the permute_vec_loop device function. The integer literal 0 is a null pointer constant in C++, which can be ambiguous when a templated type T (e.g., fp16, bf16, fp8) has constructors accepting both arithmetic and pointer types; using 0.f routes unambiguously through the float constructor path. No other occurrences of the original pattern remain in the file.

Confidence Score: 5/5

Safe to merge — single-line, correctness-only fix with no behavioural changes at runtime.

The change is minimal and provably correct: all instantiated types (float, fp16, bf16, fp8e4m3, fp8e5m2, int32_t, etc.) accept a float argument in a static_cast. No other instances of the ambiguous pattern remain in the file, and the fix directly targets the reported CUDA 12.1 compilation failure.

No files require special attention.

Important Files Changed

Filename Overview
transformer_engine/common/fused_attn/flash_attn.cu Single-character change: replaces static_cast<T>(0) with static_cast<T>(0.f) in the padding zero-fill loop of permute_vec_loop to resolve CUDA 12.1 constructor-ambiguity. Fix is correct for all instantiated types (float, fp16, bf16, fp8, int, byte).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["permute_vec_loop<T>(...)"] --> B["Copy input data\n(vectorised loop)"]
    B --> C{D_out > D?}
    C -- No --> E[Return]
    C -- Yes --> D["Padding zero-fill loop\nout[...] = static_cast<T>(0.f)"]
    D --> E

    style D fill:#d4edda,stroke:#28a745
Loading

Reviews (1): Last reviewed commit: "fix 0 literal" | Re-trigger Greptile

@cyanguwa cyanguwa requested a review from ptrendx April 27, 2026 21:56
Copy link
Copy Markdown
Collaborator

@timmoon10 timmoon10 left a comment

Choose a reason for hiding this comment

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

:shipit:

@cyanguwa cyanguwa merged commit 82ace62 into NVIDIA:main Apr 28, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants