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 ¶
const SystemReplayerAppPath = "/System/Library/CoreServices/MTLReplayer.app/Contents/MacOS/MTLReplayer"
SystemReplayerAppPath is the standard macOS system path for the headless Metal replayer.
Variables ¶
var ( 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 ¶
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 ¶
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.