Skip to content

Always specify -DNVFUSER_BUILD_WITH_ASAN to cmake#4319

Merged
wujingyue merged 1 commit intomainfrom
wjy/asan
Apr 30, 2025
Merged

Always specify -DNVFUSER_BUILD_WITH_ASAN to cmake#4319
wujingyue merged 1 commit intomainfrom
wjy/asan

Conversation

@wujingyue
Copy link
Collaborator

This might just show my ignorance of CMake. Let me know if you have a better fix.

Symptom

When I run python setup.py --build-with-asan and then python setup.py, the second build still has asan enabled.

Investigation

The first build runs cmake -DNVFUSER_BUILD_WITH_ASAN=ON, which adds NVFUSER_BUILD_WITH_ASAN:BOOL=ON to CMakeLists.txt

The second build runs cmake without -DNVFUSER_BUILD_WITH_ASAN specified. cmake chooses to use the cached value and therefore doesn't change the existing NVFUSER_BUILD_WITH_ASAN:BOOL=ON in CMakeLists.txt to OFF.

Proposed solution

Let setup.py always specify -DNVFUSER_BUILD_WITH_ASAN.

@wujingyue wujingyue requested a review from xwang233 April 25, 2025 22:20
@wujingyue
Copy link
Collaborator Author

!test

@github-actions
Copy link

Description

  • Always specify -DNVFUSER_BUILD_WITH_ASAN in CMake configuration

  • Introduce helper function on_or_off for boolean flags

  • Remove redundant ASAN check in configuration


Changes walkthrough 📝

Relevant files
Enhancement
utils.py
Always specify ASAN flag in CMake                                               

python/utils.py

  • Added on_or_off function to convert boolean to "ON"/"OFF"
  • Modified cmake function to always include -DNVFUSER_BUILD_WITH_ASAN
  • Removed redundant ASAN check in configuration
  • +4/-2     

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🧪 No relevant tests
    ⚡ Recommended focus areas for review

    Possible Issue

    The proposed solution assumes that config.build_with_asan is always set, which might not be the case. Ensure that config.build_with_asan is defined and defaults to False if not provided.

    def on_or_off(flag: bool) -> str:
        return "ON" if flag else "OFF"
    Redundancy

    The old code conditionally appends -DNVFUSER_BUILD_WITH_ASAN=ON if config.build_with_asan is True. The new code always appends -DNVFUSER_BUILD_WITH_ASAN with either ON or OFF. Ensure that this change does not introduce unnecessary complexity or potential issues.

    f"-DNVFUSER_BUILD_WITH_ASAN={on_or_off(config.build_with_asan)}",

    @rdspring1
    Copy link
    Collaborator

    !test --dev

    @rdspring1 rdspring1 self-requested a review April 26, 2025 00:03
    @xwang233
    Copy link
    Collaborator

    The CI script of dev branch (--dev) has already been merged and had no difference from the default CI trigger.

    I'll take a look at the PR later.

    Copy link
    Collaborator

    @xwang233 xwang233 left a comment

    Choose a reason for hiding this comment

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

    This change seems a bit weird to me. I want to ask, if we add NVFUSER_BUILD_WITH_ASAN to cmake definitions, should we also add all other build configs?

    When you build nvfuser the first time with python setup.py develop, the cmake build cache is already populated. Without cleaning up the build, the second python setup.py develop is expected to be an incremental build that follows similar build configs as your first build. If you don't want ASAN in the second build, perhaps you should clean up the build and uninstall first?

    If the option for NVFUSER_BUILD_WITH_ASAN is turned off in CMake here

    Fuser/CMakeLists.txt

    Lines 374 to 379 in 07effe8

    if(NVFUSER_BUILD_WITH_ASAN)
    target_compile_options(codegen_internal PRIVATE -fsanitize=address)
    target_link_options(codegen_internal PUBLIC -fsanitize=address)
    target_link_options(nvfuser_codegen PUBLIC -fsanitize=address)
    endif()
    , basically all objects of the codegen_internal target should be recompiled.

    @wujingyue
    Copy link
    Collaborator Author

    should we also add all other build configs?

    I think so. I'm happy to do that if you think this PR is moving to the right direction.

    the second python setup.py develop is expected to be an incremental build

    That's exactly the part I wanted to check with you -- user-facing behavior.

    I wrote down my motivation in the PR description in case you missed it. To me, there's an inconsistency between switching from noasan to asan and switching from asan to noasan. The former rebuilds but the latter doesn't. This user-facing behavior sounds counter-intuitive to me; if both had rebuilt, I would have accepted the behavior.

    Does the problem now make sense to you, and do you think it needs a fix?

    @wujingyue wujingyue requested a review from xwang233 April 28, 2025 14:48
    @xwang233 xwang233 requested a review from jjsjann123 April 28, 2025 15:00
    @xwang233
    Copy link
    Collaborator

    To me, there's an inconsistency between switching from noasan to asan and switching from asan to noasan. The former rebuilds but the latter doesn't.

    I agree, that sounds counter-intuitive.

    I'd take a look and see if there are standards or conventions for pip editable install. Either way won't change our release behavior since we only build once in CI. Also, let @jjsjann123 take a look.

    Copy link
    Collaborator

    @jjsjann123 jjsjann123 left a comment

    Choose a reason for hiding this comment

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

    I'm on board with the direction. i.e. let's make options explicit.

    @wujingyue wujingyue merged commit 57d91a5 into main Apr 30, 2025
    53 checks passed
    @wujingyue wujingyue deleted the wjy/asan branch April 30, 2025 19:23
    wujingyue added a commit that referenced this pull request Apr 30, 2025
    A follow-up to #4319
    
    Before this PR, we don't pass -D for default values. This confused me
    several times, so I'm making this change to ensure consistent behavior
    across clean and dirty builds. Refer to code comments for details.
    wujingyue added a commit that referenced this pull request May 2, 2025
    This is a follow-up to #4319
    
    Before this PR, we don't pass -D for default values. This confused me
    several times, so I'm making this change to ensure consistent behavior
    across clean and dirty builds. Refer to code comments for details.
    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.

    4 participants