Skip to content

Switch PyTorch's kineto build glue from LIBKINETO_NO* to KINETO_BACKEND - #183388

Closed
scotts wants to merge 1 commit into
pytorch:mainfrom
scotts:kineto_cmake
Closed

scotts wants to merge 1 commit into
pytorch:mainfrom
scotts:kineto_cmake

Conversation

@scotts

@scotts scotts commented May 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Building PyTorch against kineto requires three negative-form switches: LIBKINETO_NOCUPTI, LIBKINETO_NOROCTRACER, LIBKINETO_NOXPUPTI. A CPU-only build has to set all three, and the negation lives only in the build glue: kineto's C++ sources have always used the positive-form HAS_CUPTI / HAS_ROCTRACER / HAS_XPUPTI. PyTorch's CMake mirrors the awkwardness with a three-way flag derivation and a CXX_FLAGS pass-through of the negative macros into PyTorch's own translation units.

Why

In pytorch/kineto#1388, Kineto replaced the three NO-flags with a single mode-style KINETO_BACKEND flags. It can take on one of the values in {cpu, cuda, rocm, xpu} and included a compatibility shim that still honors the old flags. The shim is meant to be deleted once PyTorch migrates. This change does the PyTorch-side migration so the shim can go.

Fixes

  • Dependencies.cmake derives KINETO_BACKEND directly from USE_CUDA / USE_ROCM / USE_XPU+XPU_ENABLE_KINETO and forwards it to Kineto. The global CXX_FLAGS append is kept -- torch_cpu links kineto PRIVATE, so kineto's own PUBLIC HAS_* compile defs don't reach torch_python TUs like init.cpp -- but it now emits the positive macros -DHAS_*.
  • init.cpp's preprocessor guard switches to those positive macros.
  • The cudart-link guard in caffe2/CMakeLists.txt switches from NOT LIBKINETO_NOCUPTI to KINETO_BACKEND STREQUAL "cuda".

Authored by Claude.

**Problem**

Building PyTorch against kineto requires three negative-form switches:
LIBKINETO_NOCUPTI, LIBKINETO_NOROCTRACER, LIBKINETO_NOXPUPTI. A CPU-only
build has to set all three, and the negation lives only in the build glue:
kineto's C++ sources have always used the positive-form HAS_CUPTI /
HAS_ROCTRACER / HAS_XPUPTI. PyTorch's CMake mirrors the awkwardness with a
three-way flag derivation and a CXX_FLAGS pass-through of the negative
macros into PyTorch's own translation units.

**Why**

Kineto's main branch (third_party/kineto pin 7739225) replaces the three
NO-flags with a single mode-style KINETO_BACKEND, one of {cpu, cuda, rocm,
xpu}, and ships a compatibility shim that still honors the old flags. The
shim is meant to be deleted once PyTorch migrates. This change does the
PyTorch-side migration so the shim can go.

**Fix**

Dependencies.cmake derives KINETO_BACKEND directly from
USE_CUDA / USE_ROCM / USE_XPU+XPU_ENABLE_KINETO and forwards it to kineto.
The global CXX_FLAGS append is kept -- torch_cpu links kineto PRIVATE, so
kineto's own PUBLIC HAS_* compile defs don't reach torch_python TUs like
init.cpp -- but it now emits the positive macros -DHAS_*. init.cpp's
preprocessor guard switches to those positive macros. The cudart-link
guard in caffe2/CMakeLists.txt switches from NOT LIBKINETO_NOCUPTI to
KINETO_BACKEND STREQUAL "cuda".

Authored by Claude.
@pytorch-bot

pytorch-bot Bot commented May 12, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183388

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ You can merge normally! (4 Unrelated Failures), 2 Unclassified Failures

As of commit 03da2a7 with merge base 3d5307b (image):

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@scotts scotts added ciflow/xpu Run XPU CI tasks ciflow/rocm-mi355 Trigger "default" config CI on ROCm MI355 runners labels May 12, 2026
@scotts scotts added the topic: not user facing topic category label May 12, 2026
@scotts
scotts marked this pull request as ready for review May 12, 2026 03:48
@scotts
scotts requested review from albanD and soulitzer as code owners May 12, 2026 03:48
@NicolasHug

Copy link
Copy Markdown
Member

LGTM, looking at the hud, the last time the XPU tests were run was on https://hud2.pytorch.org/pytorch/pytorch/commit/dc8be5dc1f4b31076cbb0739e57553d383ba4b1b, and they look pretty broken there already.

@scotts

scotts commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Agreed on XPU; the fact that everything compiles indicates to me that this PR is not the cause of the failures.

@scotts

scotts commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 12, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • Metamates (8Keep, aditvenk, AmesingFlank, andrewor14, andyanwang, ...)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@scotts

scotts commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 2 jobs have failed, first few of them are: xpu / linux-noble-xpu-n-py3.10 / test (default, 3, 12, linux.idc.xpu), xpu / linux-noble-xpu-n-py3.10 / test (default, 7, 12, linux.idc.xpu)

Details for Dev Infra team Raised by workflow job

@scotts

scotts commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

meta-codesync Bot pushed a commit to pytorch/kineto that referenced this pull request May 13, 2026
Summary:
The CMake refactor (#1388) replaced `LIBKINETO_NOCUPTI`, `LIBKINETO_NOROCTRACER`, and `LIBKINETO_NOXPUPTI` with a single `KINETO_BACKEND` variable, but kept a shim that translated the legacy flags during the cross-repo migration window. pytorch/pytorch#183388 migrated PyTorch's `cmake/Dependencies.cmake` and `torch/csrc/autograd/init.cpp` have now both been migrated to use `KINETO_BACKEND` / `HAS_*` directly. The shim has no remaining caller.

**Approach**

Delete the shim block and the cached-vs-new-legacy-flags conflict warning that existed only to ease the migration. Replace with a simpler guard that warns when `KINETO_BACKEND` wasn't set at all and the build defaulted to `cpu`. This catches stragglers passing legacy `LIBKINETO_NO*` flags as a side effect — they'll be silently ignored, `KINETO_BACKEND` will default to `cpu`, and the new warning will tell them how to pick a backend explicitly. The new code carries no knowledge of the legacy flag names, so the kineto repo is now free of all `LIBKINETO_NO*` references.

The warning fires only on initial configure (subsequent re-runs find `KINETO_BACKEND` populated in the cache) and on a freshly-wiped build directory.

Pull Request resolved: #1399

Reviewed By: NicolasHug

Differential Revision: D104927633

Pulled By: scotts

fbshipit-source-id: 71e5f4103d77e4550bf74c5bed22c9808c8a6f5b
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…ND (pytorch#183388)

**Problem**

Building PyTorch against kineto requires three negative-form switches: LIBKINETO_NOCUPTI, LIBKINETO_NOROCTRACER, LIBKINETO_NOXPUPTI. A CPU-only build has to set all three, and the negation lives only in the build glue: kineto's C++ sources have always used the positive-form HAS_CUPTI / HAS_ROCTRACER / HAS_XPUPTI. PyTorch's CMake mirrors the awkwardness with a three-way flag derivation and a CXX_FLAGS pass-through of the negative macros into PyTorch's own translation units.

**Why**

In pytorch/kineto#1388, Kineto replaced the three NO-flags with a single mode-style KINETO_BACKEND flags. It can take on one of the values in {cpu, cuda, rocm, xpu} and included a compatibility shim that still honors the old flags. The shim is meant to be deleted once PyTorch migrates. This change does the PyTorch-side migration so the shim can go.

**Fixes**

- Dependencies.cmake derives KINETO_BACKEND directly from USE_CUDA / USE_ROCM / USE_XPU+XPU_ENABLE_KINETO and forwards it to Kineto. The global CXX_FLAGS append is kept -- torch_cpu links kineto PRIVATE, so kineto's own PUBLIC HAS_* compile defs don't reach torch_python TUs like init.cpp -- but it now emits the positive macros -DHAS_*.
- init.cpp's preprocessor guard switches to those positive macros.
- The cudart-link guard in caffe2/CMakeLists.txt switches from NOT LIBKINETO_NOCUPTI to KINETO_BACKEND STREQUAL "cuda".

Authored by Claude.
Pull Request resolved: pytorch#183388
Approved by: https://github.com/NicolasHug, https://github.com/jathu
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ND (pytorch#183388)

**Problem**

Building PyTorch against kineto requires three negative-form switches: LIBKINETO_NOCUPTI, LIBKINETO_NOROCTRACER, LIBKINETO_NOXPUPTI. A CPU-only build has to set all three, and the negation lives only in the build glue: kineto's C++ sources have always used the positive-form HAS_CUPTI / HAS_ROCTRACER / HAS_XPUPTI. PyTorch's CMake mirrors the awkwardness with a three-way flag derivation and a CXX_FLAGS pass-through of the negative macros into PyTorch's own translation units.

**Why**

In pytorch/kineto#1388, Kineto replaced the three NO-flags with a single mode-style KINETO_BACKEND flags. It can take on one of the values in {cpu, cuda, rocm, xpu} and included a compatibility shim that still honors the old flags. The shim is meant to be deleted once PyTorch migrates. This change does the PyTorch-side migration so the shim can go.

**Fixes**

- Dependencies.cmake derives KINETO_BACKEND directly from USE_CUDA / USE_ROCM / USE_XPU+XPU_ENABLE_KINETO and forwards it to Kineto. The global CXX_FLAGS append is kept -- torch_cpu links kineto PRIVATE, so kineto's own PUBLIC HAS_* compile defs don't reach torch_python TUs like init.cpp -- but it now emits the positive macros -DHAS_*.
- init.cpp's preprocessor guard switches to those positive macros.
- The cudart-link guard in caffe2/CMakeLists.txt switches from NOT LIBKINETO_NOCUPTI to KINETO_BACKEND STREQUAL "cuda".

Authored by Claude.
Pull Request resolved: pytorch#183388
Approved by: https://github.com/NicolasHug, https://github.com/jathu
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ND (pytorch#183388)

**Problem**

Building PyTorch against kineto requires three negative-form switches: LIBKINETO_NOCUPTI, LIBKINETO_NOROCTRACER, LIBKINETO_NOXPUPTI. A CPU-only build has to set all three, and the negation lives only in the build glue: kineto's C++ sources have always used the positive-form HAS_CUPTI / HAS_ROCTRACER / HAS_XPUPTI. PyTorch's CMake mirrors the awkwardness with a three-way flag derivation and a CXX_FLAGS pass-through of the negative macros into PyTorch's own translation units.

**Why**

In pytorch/kineto#1388, Kineto replaced the three NO-flags with a single mode-style KINETO_BACKEND flags. It can take on one of the values in {cpu, cuda, rocm, xpu} and included a compatibility shim that still honors the old flags. The shim is meant to be deleted once PyTorch migrates. This change does the PyTorch-side migration so the shim can go.

**Fixes**

- Dependencies.cmake derives KINETO_BACKEND directly from USE_CUDA / USE_ROCM / USE_XPU+XPU_ENABLE_KINETO and forwards it to Kineto. The global CXX_FLAGS append is kept -- torch_cpu links kineto PRIVATE, so kineto's own PUBLIC HAS_* compile defs don't reach torch_python TUs like init.cpp -- but it now emits the positive macros -DHAS_*.
- init.cpp's preprocessor guard switches to those positive macros.
- The cudart-link guard in caffe2/CMakeLists.txt switches from NOT LIBKINETO_NOCUPTI to KINETO_BACKEND STREQUAL "cuda".

Authored by Claude.
Pull Request resolved: pytorch#183388
Approved by: https://github.com/NicolasHug, https://github.com/jathu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rocm-mi355 Trigger "default" config CI on ROCm MI355 runners ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged topic: not user facing topic category

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants