cudapmreg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 10 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 cudapmreg reads the SM performance-monitor special registers SR_PM0..SR_PM7 (and their high halves) on sm_121a, with and without a profiling session, and retargets the reads to the SR_SNAP_PM snapshot bank.

The probe kernel (testdata/pmprobe.ptx, built with ptxas from CUDA 13.0) reads %pm0_64..%pm7_64 and %clock64 three times: before an FFMA loop, after it, and after a barrier. ptxas treats these reads as free to move, so data dependences pin them, and CheckOrder verifies the placement in the compiled text. %clock64 is read beside the counters in every set as a control: a read path that stores zero for everything cannot also store a clock that advances with the loop.

Retarget rewrites the special-register selector of chosen reads in the cubin, for example SR_PM0 to SR_SNAP_PM0, which no PTX name reaches.

This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/obs/cudapmreg"
)

func main() {
	cubin, err := cudapmreg.Cubin()
	if err != nil {
		fmt.Println(err)
		return
	}
	_, text, err := cudapmreg.Text(cubin)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(cudapmreg.CheckOrder(text))
}
Output:
<nil>

Index

Examples

Constants

View Source
const (
	Sets   = 3
	Values = 9
)

Sets is the number of read points in the probe; Values is the number of 64-bit values stored per set: the eight counters, then the clock.

View Source
const Kernel = "pmprobe"

Kernel is the probe kernel's entry point. Its parameters are (u64 out, u64 out2, u32 iters, f32 seed).

View Source
const (
	SelectorClockLo uint8 = 0x50 // SR_CLOCKLO; CS2R reads it with SR_CLOCKHI
)

Special-register selectors on sm_121a, as nvdisasm names them.

Variables

View Source
var ErrOrder = errors.New("probe reads are out of place")

ErrOrder means the compiled probe does not read its sets where the PTX places them.

Functions

func CheckOrder

func CheckOrder(text []sass.Encoding) error

CheckOrder verifies that text reads set 0 before every FFMA, set 1 after every FFMA and before the barrier, and set 2 after the barrier, and that each set reads the clock and eight distinct counters.

func Cubin

func Cubin() ([]byte, error)

Cubin returns the probe kernel's cubin.

func PM

func PM(i int) uint8

PM returns the selector of SR_PM<i>. SR_PM_HI<i> is the next selector, and a 64-bit CS2R or CS2UR of SR_PM<i> reads both.

func Retarget

func Retarget(cubin []byte, inSets []int, to func(old uint8) (uint8, bool)) (sass.PatchedImage, error)

Retarget returns cubin with the selector of every counter read in the given sets replaced by to(old), for each old selector where to reports true. The clock reads are never retargeted. The text section is patched in place through sass.CubinImage.Apply, which refuses if any patched byte is not the instruction this function decoded.

ptxas also writes a second copy of the kernel's text, the section .nv.capmerc.text.pmprobe, which the patch would leave stale. Retarget removes it first with elfinspect.StripCapmerc, so the result has no unpatched mirror and passes sass.PatchedImage.Loadable.

func SnapPM

func SnapPM(i int) uint8

SnapPM returns the selector of SR_SNAP_PM<i>. SR_SNAP_PM_HI<i> is the next selector.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/obs/cudapmreg"
)

func main() {
	fmt.Printf("SR_PM0=%#x SR_SNAP_PM0=%#x SR_SNAP_PM7=%#x\n", cudapmreg.PM(0), cudapmreg.SnapPM(0), cudapmreg.SnapPM(7))
}
Output:
SR_PM0=0x64 SR_SNAP_PM0=0x74 SR_SNAP_PM7=0x82

func Text

func Text(cubin []byte) (addr uint64, text []sass.Encoding, err error)

Text returns the probe kernel's instructions in cubin.

Types

type Reading

type Reading [Sets]Sample

A Reading is one thread's three samples: before the loop, after the loop, and after the barrier.

func Decode

func Decode(out []uint64) ([]Reading, error)

Decode splits the probe's out buffer into one Reading per thread.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/obs/cudapmreg"
)

func main() {
	out := make([]uint64, cudapmreg.Sets*cudapmreg.Values)
	out[cudapmreg.Values+8] = 1000 // set 1 clock
	r, err := cudapmreg.Decode(out)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(len(r), r[0][1].Clock-r[0][0].Clock)
}
Output:
1 1000

type Sample

type Sample struct {
	PM    [8]uint64
	Clock uint64
}

A Sample is one read set: the eight 64-bit counters and the clock.

Jump to

Keyboard shortcuts

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