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 ¶
- Constants
- Variables
- func CheckOrder(text []sass.Encoding) error
- func Cubin() ([]byte, error)
- func PM(i int) uint8
- func Retarget(cubin []byte, inSets []int, to func(old uint8) (uint8, bool)) (sass.PatchedImage, error)
- func SnapPM(i int) uint8
- func Text(cubin []byte) (addr uint64, text []sass.Encoding, err error)
- type Reading
- type Sample
Examples ¶
Constants ¶
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.
const Kernel = "pmprobe"
Kernel is the probe kernel's entry point. Its parameters are (u64 out, u64 out2, u32 iters, f32 seed).
const (
SelectorClockLo uint8 = 0x50 // SR_CLOCKLO; CS2R reads it with SR_CLOCKHI
)
Special-register selectors on sm_121a, as nvdisasm names them.
Variables ¶
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 ¶
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 PM ¶
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 ¶
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
Types ¶
type Reading ¶
A Reading is one thread's three samples: before the loop, after the loop, and after the barrier.
func Decode ¶
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