Developer Tools

PyTorch adds torch.xpu.clock_rate for Intel GPU frequency monitoring

New function lets developers query real-time GPU clock speed on XPU devices.

Deep Dive

PyTorch has introduced a new function, torch.xpu.clock_rate, that exposes the GPU clock frequency on Intel XPU (Intel GPU) devices. This is part of a larger initiative to bring XPU device telemetry—such as temperature, clock rate, power draw, utilization, and memory usage—closer to parity with what CUDA offers. Previously, only temperature was available via torch.xpu.temperature. The new feature leverages Intel's Level Zero Sysman API, specifically the zesFrequencyGetState function, through the existing pyzes Python bindings. This allows developers and tooling to monitor GPU performance metrics in real time, which is crucial for profiling large-scale model training and inference.

The implementation includes several technical refinements. A new helper function, _zes_ensure_device_infos(), was added to deduplicate device cache initialization and bounds-checking, which was previously inlined in the temperature handle getter. A separate _get_zes_frequency_handle() function now caches the frequency handle, mirroring the pattern used for temperature. A known limitation exists: pyzes currently lacks bindings for zesFrequencyGetProperties, so the code assumes index 0 corresponds to ZES_FREQ_DOMAIN_GPU. This assumption holds for most single-GPU setups but may need updating once proper domain filtering is added. The pull request was approved by gujinghui and merged into the PyTorch trunk.

Key Points
  • New torch.xpu.clock_rate function queries GPU clock frequency via Intel Level Zero Sysman API.
  • Part of PyTorch's effort to add XPU telemetry APIs (temperature, clock_rate, power, utilization) to match CUDA's monitoring capabilities.
  • Known limitation: lacks zesFrequencyGetProperties binding, so assumes index 0 is GPU frequency domain.

Why It Matters

Gives PyTorch developers on Intel GPUs essential telemetry for performance profiling and model optimization.