Skip to content

Conversation

@moksiuc
Copy link
Contributor

@moksiuc moksiuc commented Nov 13, 2025

Summary:

As XPU became a PyTorch built-in device, the profiler support is indispensable part of functionality completeness. In this PR, the XPU scope profiler is introduced by extending existing XPU profiler plugin. The XPU scope profiler is built on the foundation of intel PTI toolkit (https://github.com/intel/pti-gpu), and underlying SYCL runtime. It allows to gather XPU hardware metrics. The LIBKINETO_NOXPUPTI option is used to enable or disable the whole XPU profiler plugin during kineto build stage.

Changes:

  • Added new ActivityType : XPU_SCOPE_PROFILER, enabling the new scope profiler
  • Added new class XpuptiScopeProfilerConfig derived from AbstractConfig for configuration of the new scope profiler
  • Enhanced ChromeTraceLogger::handleActivity method so it outputs XPU hardware metrics from the new scope profiler in Perfetto counters display mode ("C")
  • Added gtest

@meta-cla meta-cla bot added the cla signed label Nov 13, 2025
@moksiuc moksiuc changed the title scope profiler squashed Introduce XPU scope profiler extending existing XPU profiler plugin Nov 13, 2025
@moksiuc
Copy link
Contributor Author

moksiuc commented Nov 13, 2025

@EikanWang, @gujinghui

@gujinghui
Copy link

@moksiuc It's great that we are going to update our PTI integration code, and introduce new profiler path.
Could you help address below questions?

  1. The alternative of ScopeProfiler is the RangeProfiler for CUDA? Looks like the RangeProfler is not enabled in PyTorch by default so far. Do you know why?
  2. This PR is too huge to review. Can we split it to several PRs? For example, one PR for code refactor or cleanup per kineto or PTI changes, one or two PRs for ScopeProfiler, one PR for ChromeTraceLogger enhancement, and add test cases for each PRs.
  3. BTW, CUDA provides CUDA_DRIVER activity to trace the driver actions. We should provide L0 actions as the counterpart, right? I remember, PTI should be able to do that. Do we have plan to cover it?
    {"cuda_driver", ActivityType::CUDA_DRIVER},

@moksiuc
Copy link
Contributor Author

moksiuc commented Nov 14, 2025

  1. The alternative of ScopeProfiler is the RangeProfiler for CUDA? Looks like the RangeProfler is not enabled in PyTorch by default so far. Do you know why?
    It is enabled by providing experimental_config=_ExperimentalConfig(...). I don't know why it is this way but we are enabling our profiler the same way. One of the reasons may be that Range/Scope profiler requires parameters like HW metrics names that are passed through _ExperimentalConfig.

@moksiuc
Copy link
Contributor Author

moksiuc commented Nov 14, 2025

  1. BTW, CUDA provides CUDA_DRIVER activity to trace the driver actions. We should provide L0 actions as the counterpart, right? I remember, PTI should be able to do that. Do we have plan to cover it?
    {"cuda_driver", ActivityType::CUDA_DRIVER},

For sure not in this PR. I'll add this to our list of tasks.

@moksiuc
Copy link
Contributor Author

moksiuc commented Nov 17, 2025

  1. This PR is too huge to review. Can we split it to several PRs? For example, one PR for code refactor or cleanup per kineto or PTI changes, one or two PRs for ScopeProfiler, one PR for ChromeTraceLogger enhancement, and add test cases for each PRs.

Extracted clean up and adding config for scope profiler to separate PR's.
This one should be much smaller afterwards.
Currently I don't see further areas of extracting separate PR's as what would remain is full scope profiler implementation with tests and we'd like not to introduce half of the implementation that is not working functionally.

- removed rangeEnabled
- fix test to align to this removal
- erase used kernelActivity from map
- place of config initialization
- removal of passing unused C compiler flag into test cmake file
Copy link

@gujinghui gujinghui left a comment

Choose a reason for hiding this comment

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

This PR is split to #1177, #1180, and more.

@moksiuc moksiuc marked this pull request as ready for review November 24, 2025 10:01
@gujinghui
Copy link

@moksiuc Let's close this PR.

@moksiuc
Copy link
Contributor Author

moksiuc commented Dec 3, 2025

@gujinghui this is the core of the scope profiler. When 2 smaller parts are merged this one would have only core profiler left.

@moksiuc
Copy link
Contributor Author

moksiuc commented Dec 19, 2025

@EikanWang, @gujinghui
Please review.
2 extracted parts are already merged.
Now this change contains only code directly related to scope profiler.

@moksiuc
Copy link
Contributor Author

moksiuc commented Dec 19, 2025

Tests are run on pytorch part:
pytorch/pytorch#165766

@moksiuc moksiuc requested a review from gujinghui December 19, 2025 11:28
scopeProfilerEnabled = true;
#else
throw std::runtime_error(
"Intel® oneAPI version required to use scope profiler is at least 2025.3.1");

Choose a reason for hiding this comment

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

Can we give the PTI version here, instead of oneAPI package version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had previously PTI version but is it not clearer for the user to have one api version ?
Has the user possibility to install any PTI version he wants ?

@@ -0,0 +1,55 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

Choose a reason for hiding this comment

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

@chuanqi129 If we want to append these cases in XPU CI scope, how should we do?

Choose a reason for hiding this comment

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

Hi @gujinghui , we don't have xpu ci test for kineto repo, do you mean put those test cases into stock pytorch? If so, we may evaluate whether can put them into https://github.com/pytorch/pytorch/tree/main/test/cpp/profiler

Choose a reason for hiding this comment

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

yes. @moksiuc please sync with @chuanqi129 to make it. Thanks.

Copy link

@gujinghui gujinghui left a comment

Choose a reason for hiding this comment

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

LGTM. I assume you already verified it on local real machine, right? @moksiuc

@moksiuc
Copy link
Contributor Author

moksiuc commented Dec 22, 2025

LGTM. I assume you already verified it on local real machine, right? @moksiuc

Yes, I did.

@gujinghui
Copy link

@sraikund16 could you help review this PR? Thanks.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants