gpureplay

package
v0.6.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gpureplay coordinates headless GPU capture replay and performance profiling via Apple's system MTLReplayer and GPU trace analysis tools.

Index

Examples

Constants

View Source
const SystemReplayerAppPath = "/System/Library/CoreServices/MTLReplayer.app/Contents/MacOS/MTLReplayer"

SystemReplayerAppPath is the standard macOS system path for the headless Metal replayer.

Variables

View Source
var (
	// ErrReplayerUnavailable indicates MTLReplayer is not present on this system.
	ErrReplayerUnavailable = errors.New("gpureplay: MTLReplayer executable not found")
	// ErrInvalidCapturePath indicates the provided capture bundle does not exist or is invalid.
	ErrInvalidCapturePath = errors.New("gpureplay: invalid .gputrace capture bundle")
)

Functions

func Available

func Available() error

Available checks if the system MTLReplayer binary exists and is executable.

Types

type KernelTiming

type KernelTiming struct {
	Name            string        `json:"name"`
	Duration        time.Duration `json:"duration"`
	DispatchCount   int           `json:"dispatch_count"`
	AverageDuration time.Duration `json:"average_duration"`
}

KernelTiming describes the measured GPU hardware execution duration of a kernel dispatch.

type Options

type Options struct {
	// OutputDirectory sets the destination directory for profiler output.
	OutputDirectory string
	// Timeout specifies the maximum duration to wait for replay completion.
	Timeout time.Duration
	// KeepRawPayload preserves intermediate .gpuprofiler_raw files.
	KeepRawPayload bool
}

Options configures replay execution.

type ReplayReport

type ReplayReport struct {
	TotalGPUActiveTime time.Duration  `json:"total_gpu_active_time"`
	KernelTimings      []KernelTiming `json:"kernel_timings"`
	ShaderMetrics      []ShaderMetric `json:"shader_metrics"`
	PeakRegisterUsage  int            `json:"peak_register_usage"`
	RawOutputPath      string         `json:"raw_output_path,omitempty"`
}

ReplayReport summarizes GPU profiling results produced by replaying a Metal capture.

Example
package main

import (
	"fmt"
	"time"

	"github.com/tmc/apple/x/gpureplay"
)

func main() {
	report := &gpureplay.ReplayReport{
		TotalGPUActiveTime: 12500 * time.Microsecond,
		PeakRegisterUsage:  32,
		KernelTimings: []gpureplay.KernelTiming{
			{
				Name:          "FastGEMV",
				Duration:      4500 * time.Microsecond,
				DispatchCount: 16,
			},
			{
				Name:          "ComputeRMSNorm",
				Duration:      800 * time.Microsecond,
				DispatchCount: 32,
			},
		},
		ShaderMetrics: []gpureplay.ShaderMetric{
			{
				Name:             "FastGEMV",
				RegisterCount:    32,
				ThreadgroupBytes: 1024,
				ALUInstructions:  256,
				MemInstructions:  64,
				ExecutionCostPct: 65.5,
			},
		},
	}

	fmt.Printf("Active Time: %v\n", report.TotalGPUActiveTime)
	fmt.Printf("Peak GPRs: %d\n", report.PeakRegisterUsage)
	fmt.Printf("Timings: %d\n", len(report.KernelTimings))

}
Output:
Active Time: 12.5ms
Peak GPRs: 32
Timings: 2

func Replay

func Replay(ctx context.Context, capturePath string, opts Options) (*ReplayReport, error)

Replay executes headless GPU replay on the given capturePath bundle and returns a parsed ReplayReport.

func (*ReplayReport) String

func (r *ReplayReport) String() string

String returns a human-readable summary of the replay report.

type ShaderMetric

type ShaderMetric struct {
	Name             string  `json:"name"`
	RegisterCount    int     `json:"register_count"`     // GPRs per thread
	ThreadgroupBytes int     `json:"threadgroup_bytes"`  // Shared memory bytes
	ALUInstructions  int     `json:"alu_instructions"`   // Arithmetic ops
	MemInstructions  int     `json:"mem_instructions"`   // Load/store ops
	ExecutionCostPct float64 `json:"execution_cost_pct"` // % of total GPU active time
}

ShaderMetric holds static and dynamic performance counters for a compiled Metal compute shader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL