Skip to content

[CI] Minor CMake refactoring#3227

Open
fheinecke wants to merge 3 commits into
NVIDIA:mainfrom
fheinecke:fred/build-refactor-1
Open

[CI] Minor CMake refactoring#3227
fheinecke wants to merge 3 commits into
NVIDIA:mainfrom
fheinecke:fred/build-refactor-1

Conversation

@fheinecke

Copy link
Copy Markdown
Collaborator

Description

This fixes a couple of minor CMake bugs, and slightly simplifies NCCL dependency resolution.

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

Please list the changes introduced in this PR:

  • 28fe8ee: NCCL header location is now resolved once instead of two separate places with different resolution hints.
  • b6303b8: Python site-packages/nvidia/nccl is now searched for NCCL headers, making it easier to resolve them when installing NCCL via nvidia-nccl-cu{12,13} wheels.
  • 30d92a7: The TE version linker script is now only provided when TE is linked, rather than every time the C++ or CUDA compiler is executed (compiler detection, compilation, etc).

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

@fheinecke

Copy link
Copy Markdown
Collaborator Author

/te-ci

1 similar comment
@fheinecke

Copy link
Copy Markdown
Collaborator Author

/te-ci

NCCL is now always required for all native build paths (due to a change
sometime between v2.16 and main). This updates CMake to only search for
the headers in a single place.

This does not impact the NCCL EP dependency resolution.

Signed-off-by: Fred Heinecke <fheinecke@nvidia.com>
This will now also search Python's site-packages, making it much easier
to pull in headers from `nvidia-nccl-cu{12,13}`.

Signed-off-by: Fred Heinecke <fheinecke@nvidia.com>
Previously this was provided every time the C++ or CUDA compiler was
invoked for everything built by CMake, including compiler detection and
compilation, instead of just when linking the TE library.

Signed-off-by: Fred Heinecke <fheinecke@nvidia.com>
@fheinecke
fheinecke force-pushed the fred/build-refactor-1 branch from 30d92a7 to eef16c6 Compare July 24, 2026 14:51
@fheinecke
fheinecke marked this pull request as ready for review July 24, 2026 14:51
@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR performs three targeted CMake improvements in transformer_engine/common/CMakeLists.txt: it consolidates duplicate NCCL header discovery into a single find_path call at the top level (adding Python site-packages as a search hint), renames the helper function to get_nccl_version to reflect its new narrower role, and moves the linker version-script from global CMAKE_CXX_FLAGS/CMAKE_CUDA_FLAGS to a target_link_options(PRIVATE ...) on the transformer_engine target.

  • The version-script change is a genuine bug fix: the old global flag was injected into every compiler invocation (compiler detection, try_compile, and subproject targets like nvshmemapi), which could cause spurious link failures. Scoping it with target_link_options is the correct CMake idiom.
  • The NCCL consolidation drops the internal find_path from inside the old find_nccl_version function and the one inside the NVTE_WITH_NCCL_EP conditional, replacing both with a single top-level find_path ... REQUIRED call. A side-effect is that nccl.h is now unconditionally required at configure time, even when NVTE_WITH_NCCL_EP=OFF and NVTE_WITH_CUBLASMP=OFF; in practice this is fine since the always-compiled comm_gemm_overlap sources reference NCCL symbols.

Confidence Score: 5/5

Safe to merge. All three changes are scoped, correct, and reduce unintended side-effects of the previous implementation.

The linker-script fix removes a real CMake anti-pattern where a link-only flag was injected into every compiler invocation project-wide. The NCCL consolidation is functionally equivalent for the existing call sites and adds a useful new search path. No existing override mechanisms (e.g. -DNCCL_INCLUDE_DIR) are broken.

No files require special attention.

Important Files Changed

Filename Overview
transformer_engine/common/CMakeLists.txt Three clean improvements: linker version-script scoped to the transformer_engine target via target_link_options; NCCL header discovery consolidated into one top-level find_path with an added Python site-packages hint; get_nccl_version helper simplified to not do its own path search. No logic regressions observed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CMake configure start] --> B[find_path NCCL_INCLUDE_DIR\nHINTS: Python site-packages,\n/opt/nvidia/nccl, /usr/local/nccl\nREQUIRED]
    B -->|found| C[get_nccl_version\nNCCL_VERSION]
    B -->|not found| FAIL1[FATAL_ERROR]

    C --> D[add_library transformer_engine SHARED]
    D --> E[target_link_options PRIVATE\nLINKER:--version-script=\nlibtransformer_engine.version]
    D --> F[target_include_directories PRIVATE\nNCCL_INCLUDE_DIR]

    G{NVTE_WITH_CUBLASMP?} -->|ON| H[Check NCCL_VERSION >= 2.30.0\nusing already-resolved NCCL_INCLUDE_DIR]
    G -->|OFF| I[skip]

    J{NVTE_WITH_NCCL_EP?} -->|ON| K[find NCCL_EP headers & lib\ntarget_include_directories NCCL_EP_INCLUDE_DIR]
    J -->|OFF| L[compile stub ep_api.cpp]
Loading

Reviews (1): Last reviewed commit: "Make TE linker script be provided when l..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant