Skip to content

Add Intel GPU profiling mode via iaprof - #1059

Merged
bkammerd merged 10 commits into
intel:masterfrom
bkammerd:master
Oct 20, 2026
Merged

bkammerd merged 10 commits into
intel:masterfrom
bkammerd:master

Conversation

@bkammerd

@bkammerd bkammerd commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

This adds --mode=gpu, which profiles EU stalls on Intel GPUs (Xe-based arch) using an external iaprof executable. The collected profile conforms to gProfiler's existing stack-sampling format so that GPU flame graphs can be viewed in an unmodified Performance Studio.

Description

Additions

  • IaprofProfiler (gprofiler/profilers/iaprof.py)
  • A system profiler registered only for gpu mode.
  • Starts a single long-lived iaprof process.
  • Requires iaprof 2026.3 or newer, checked with iaprof --version.
  • New arguments: --iaprof-path and --iaprof-eu-stall-subsample (default 100).
  • IaprofProcess (gprofiler/utils/iaprof_process.py)
  • Reads stdout on a background thread and stores the counts per PID.
  • gprofiler/utils/iaprof.py parses iaprof's output into per-PID counters.
  • CLI (gprofiler/main.py)
  • -f/--profiling-frequency sets iaprof's output interval in GPU mode. The default is 100 Hz, which is matches iaprof's default 10 ms interval.
  • GPU mode rejects --rootless and --alloc-interval.
  • Profile metadata: adds iaprof_version, iaprof_output_interval_ms and iaprof_eu_stall_subsample.
  • Tests:
    • tests/test_iaprof.py: parser
    • tests/test_iaprof_process.py: the process management
    • tests/test_iaprof_profiler.py: the profiler subsystem and CLI args

Changes to shared code

  • SystemProfilerBase: a new base class for the exclusive system-profiler slot. Perf (SystemProfiler) and IaprofProfiler both inherit from it. It also lets a system profiler add its own profile metadata.
  • get_profilers(): selects the system profiler by SystemProfilerBase instead of SystemProfiler. A profiler that doesn't support the current mode is now skipped with a debug log instead of a warning.
  • --max-system-processes-for-system-profilers now applies only to perf.
  • _snapshot(): local_end_time is now computed after the system-profiler result is collected to fix a bug where in GPU mode, no process profilers ran to take up the snapshot duration, so profiles got identical start and end times.
  • Snapshot failure log now prints the name of the system profiler that failed, instead of always mentioning perf.

CPU and allocation modes behave the same as before.

Current Limitations

  • iaprof is not bundled. It must be installed separately and selected with --iaprof-path.
  • GPU mode runs only one profiler. perf and the language profilers are disabled.
  • Starting GPU mode from the Performance Studio doesn't work because Studio's profile_request validation only accepts cpu, allocation and none.
  • After an iaprof restart, kernels loaded before the restart may not be attributed.
  • Root is required.

Manual Testing

Tested end-to-end on a local machine with an Intel B580 running a simple SYCL matrix multiply benchmark. Test produced flame graphs in a locally-deployed version of the Performance Studio.

@bkammerd
bkammerd requested a review from mlim19 October 2, 2026 15:19
gmunoz
gmunoz previously approved these changes Oct 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Snapshot timeout cleanup can leave stale process and reader state, causing an additional profiling cycle to fail.

1 open finding
What changed in this PR

Adds Intel Xe GPU EU-stall profiling through an external iaprof process.

Changes:

  • Adds GPU profiling mode, CLI options, and metadata.
  • Implements iaprof parsing, process lifecycle, and profile generation.
  • Generalizes system profilers and adds comprehensive tests.
File Description
gprofiler/​consts.py Defines GPU mode and frequency limits.
gprofiler/​main.py Integrates GPU CLI behavior and metadata.
gprofiler/​profilers/​__init__.py Exports the Intel GPU profiler.
gprofiler/​profilers/​factory.py Selects generic system profilers by mode.
gprofiler/​profilers/​iaprof.py Implements the GPU profiler.
gprofiler/​profilers/​perf.py Migrates perf to the shared system-profiler base.
gprofiler/​profilers/​profiler_base.py Introduces SystemProfilerBase.
gprofiler/​utils/​iaprof.py Parses streamed iaprof records.
gprofiler/​utils/​iaprof_process.py Manages the long-lived iaprof process.
tests/​test_iaprof.py Tests output parsing and snapshots.
tests/​test_iaprof_process.py Tests process lifecycle and recovery.
tests/​test_iaprof_profiler.py Tests profiler behavior and CLI validation.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread gprofiler/utils/iaprof_process.py
Comment thread gprofiler/main.py
if args.frequency is None:
args.frequency = DEFAULT_GPU_PROFILING_FREQUENCY
elif args.frequency > MAX_GPU_PROFILING_FREQUENCY:
parser.error(f"-f|--frequency cannot exceed {MAX_GPU_PROFILING_FREQUENCY} in gpu profiling")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we error out if the result is requested to upload to the backend at this time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The result can be uploaded to the backend without issues. It just appears as a CPU flame graph, so we may need to visually differentiate on the performance studio side.

Comment thread gprofiler/main.py
"sampling_frequency": self.system_profiler._frequency,
}
)
elif isinstance(self.system_profiler, SystemProfilerBase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is specific to iaprof profiler?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this covers both perf and iaprof since they are now both considered "system" profilers.

@mlim19

mlim19 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

In general, looks good to me with 2 minor questions

@bkammerd
bkammerd merged commit 8329c5c into intel:master Oct 20, 2026
78 of 80 checks passed
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.

4 participants