Skip to content

Support multi-config generators in the SYCL CMake build#4370

Open
cyyever wants to merge 4 commits into
intel:mainfrom
cyyever:agent/buildflags-multiconfig-guard
Open

Support multi-config generators in the SYCL CMake build#4370
cyyever wants to merge 4 commits into
intel:mainfrom
cyyever:agent/buildflags-multiconfig-guard

Conversation

@cyyever

@cyyever cyyever commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Multi-config generators (Ninja Multi-Config, Visual Studio) did not build correctly: per-config flags keyed off CMAKE_BUILD_TYPE, which is empty under multi-config, and FindSYCL object paths used the deprecated CMAKE_CFG_INTDIR, which stays . under Ninja Multi-Config so every configuration collided on the same outputs.

Three commits, in review order:

  1. flags - per-config host/kernel flags become $<CONFIG:> genexes. TORCH_XPU_OPS_FLAGS stays config-agnostic and defers to PyTorch's per-config flags (CMAKE_CXX_FLAGS_DEBUG, MSVC_Z7_OVERRIDE) instead of duplicating/fighting them.
  2. paths - per-config object and dependency subpaths under multi-config generators only (single-config layout unchanged); same-named sources from different directories are disambiguated by a source-dir hash rather than the old FindCUDA mirrored-subdirectory scheme.
  3. guard - settle USE_SYCLTLA before its include() so debug builds skip it.

Authored with Claude Code assistance.

@cyyever
cyyever marked this pull request as draft July 17, 2026 04:23
@cyyever
cyyever force-pushed the agent/buildflags-multiconfig-guard branch 6 times, most recently from 4829dc6 to 9a04e49 Compare July 22, 2026 05:21
@cyyever
cyyever marked this pull request as ready for review July 22, 2026 05:28
@cyyever cyyever changed the title Support multi-config generators in SYCL build flags and object paths Support multi-config generators in the SYCL CMake build Jul 22, 2026
cyyever added 3 commits July 22, 2026 15:50
The per-config host and kernel flags were chosen with
`if(CMAKE_BUILD_TYPE MATCHES ...)`, which is empty under multi-config
generators, so Debug/RelWithDebInfo builds silently got the release
flags. Spell them as $<CONFIG:> genexes instead: host flags go in
SYCL_HOST_PER_CONFIG_FLAGS and the DEBUG_XPU kernel option becomes a
genex too.

These genexes are needed only on the -fsycl-host-compiler-options path,
which is assembled from the base CMAKE_CXX_FLAGS and never sees
CMAKE_CXX_FLAGS_<CONFIG>. Because PyTorch unconditionally forces -O2 into
that base CMAKE_CXX_FLAGS, the GNU Debug flags override it back to -O0
while RelWithDebInfo only needs to add -g (dropping the -O2 that would
just duplicate the inherited one); MSVC keeps /O2 since PyTorch adds -O2
only for non-MSVC.

The regular host TUs, compiled through
target_compile_options(${lib} ${TORCH_XPU_OPS_FLAGS}), already receive
PyTorch's per-config flags from CMake: CMAKE_CXX_FLAGS_DEBUG carries
-fno-omit-frame-pointer/-O0, and MSVC_Z7_OVERRIDE swaps /Zi for /Z7. So
TORCH_XPU_OPS_FLAGS stays config-agnostic and does not re-add any of
them, which also stops it from fighting a user who turns MSVC_Z7_OVERRIDE
off. In the same vein, drop -Wunused-variable from SYCL_HOST_FLAGS: both
compile paths inherit PyTorch's base -Wall, which already implies it.
-fPIC stays (the device link extracts it from SYCL_HOST_FLAGS) and
-std=c++20 stays (the host-compiler path does not get CMAKE_CXX_STANDARD).

Test Plan:

```
lintrunner cmake/BuildFlags.cmake
```

Verified together with the FindSYCL change by building a driver project
under both Ninja (single-config) and Ninja Multi-Config.

Authored with Claude Code assistance.
FindSYCL object paths used the deprecated CMAKE_CFG_INTDIR, which stays
"." under Ninja Multi-Config, so every configuration wrote to the same
intermediate object and dependency files and collided. Add a per-config
subdir and suffix, applied only under multi-config generators so the
single-config layout (including the device link object) is unchanged.

Same-named sources from different directories are now disambiguated by a
short hash of their source directory embedded in the object name,
replacing the removed SYCL_COMPUTE_BUILD_PATH mirrored-subdirectory
scheme inherited from FindCUDA. Dependency bookkeeping expands to the
per-config .depend files and the compile command depends on their union,
and the per-config output directory is created before device linking.

Test Plan:

```
lintrunner cmake/Modules/FindSYCL.cmake
```

Verified by building a driver project (fsycl-specific flags stubbed out)
that links two same-named SYCL sources plus a host source, under both
Ninja and Ninja Multi-Config (--config Debug and Release).

Authored with Claude Code assistance.
The debug guard set USE_SYCLTLA OFF after SYCLTLA.cmake had already been
included, so a debug build still pulled the include in. Fold the debug
disable into the existing platform guard so USE_SYCLTLA is decided before
the include; the later block then only forces BUILD_SEPARATE_OPS. Both
key off CMAKE_BUILD_TYPE, which is a configure-time switch with no single
answer across a multi-config config list; pytorch's Visual Studio flow
exports CMAKE_BUILD_TYPE and builds --config to match, so that path is
covered.

Test Plan:

```
lintrunner CMakeLists.txt
```

Authored with Claude Code assistance.
@cyyever
cyyever force-pushed the agent/buildflags-multiconfig-guard branch from 9a04e49 to a41b658 Compare July 22, 2026 07:50
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.

2 participants