cudapmpred

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: 9 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 cudapmpred provides SASS pm_pred per-instruction event counting and PTX %pm0..%pm7 baseline counter auditing for NVIDIA sm_121a (GB10).

On sm_121a, bits [103:102] of the 128-bit instruction encoding select hardware performance monitor event triggers (PMN, PM1, PM2, PM3). This enables zero-trampoline per-instruction event counting directly inside executing kernels without code caves or branch trampolines.

Baseline counters are read using PTX %pm0..%pm7 and pmevent instructions, which lower to CS2R.32 and PMTRIG in SASS.

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/isa/sass"
	"github.com/tmc/lib/nvidia/x/obs/cudapmpred"
)

func main() {
	// Start with a basic NOP instruction on sm_121a.
	nop := sass.Encoding{
		Lo: 0x0000000000007918,
		Hi: 0x000e220000000000,
	}

	// Tag the instruction with PM1 for per-instruction hardware event counting.
	tagged, err := cudapmpred.EncodePMPred(nop, cudapmpred.PM1, sass.SM121a)
	if err != nil {
		panic(err)
	}

	pred, err := cudapmpred.DecodePMPred(tagged, sass.SM121a)
	if err != nil {
		panic(err)
	}

	fmt.Println("pm_pred:", pred)
}
Output:
pm_pred: PM1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodePMPred

func EncodePMPred(enc sass.Encoding, pred PMPred, arch sass.Arch) (sass.Encoding, error)

EncodePMPred encodes the pm_pred field into enc on the specified architecture. Only sass.SM121a is calibrated for pm_pred bit positioning.

func FindNvdisasm

func FindNvdisasm() (string, error)

FindNvdisasm locates the nvdisasm toolchain executable.

func PatchInstructionBytes

func PatchInstructionBytes(raw []byte, offset int, pred PMPred) error

PatchInstructionBytes patches the 16-byte SASS instruction at offset in raw.

func VerifyEncodingNvdisasm

func VerifyEncodingNvdisasm(enc sass.Encoding) (string, error)

VerifyEncodingNvdisasm verifies that enc disassembles into a valid sm_120 instruction using host nvdisasm -b SM120 -hex prior to GPU launch.

Types

type PMPred

type PMPred uint8

PMPred represents the 2-bit performance monitor trigger field in sm_121a SASS. It is encoded in bits [103:102] of the 128-bit instruction word (bits [39:38] of Hi).

const (
	// PMN indicates no performance monitor event trigger (default).
	PMN PMPred = 0

	// PM1 triggers performance monitor event 1 upon instruction execution.
	PM1 PMPred = 1

	// PM2 triggers performance monitor event 2 upon instruction execution.
	PM2 PMPred = 2

	// PM3 triggers performance monitor event 3 upon instruction execution.
	PM3 PMPred = 3
)

func DecodePMPred

func DecodePMPred(enc sass.Encoding, arch sass.Arch) (PMPred, error)

DecodePMPred extracts the pm_pred field from enc on the specified architecture.

func ParsePMPred

func ParsePMPred(s string) (PMPred, error)

ParsePMPred parses a performance monitor trigger name.

Example
package main

import (
	"fmt"

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

func main() {
	p1, _ := cudapmpred.ParsePMPred("PM1")
	p2, _ := cudapmpred.ParsePMPred("2")
	pNone, _ := cudapmpred.ParsePMPred("NONE")

	fmt.Println(p1, p2, pNone)
}
Output:
PM1 PM2 PMN

func (PMPred) String

func (p PMPred) String() string

type PTXBaseline

type PTXBaseline struct {
	Name         string // PTX identifier (%pm0, pmevent, etc.)
	SASSMnemonic string // Lowered SASS mnemonic (CS2R.32, PMTRIG, etc.)
	SRIndex      uint8  // Special register index in SASS (100 for PM0, etc.)
	BitWidth     int    // Counter bit width (32 or 64)
}

PTXBaseline describes an audited PTX performance counter or trigger instruction.

func AuditPTXBaselines

func AuditPTXBaselines() []PTXBaseline

AuditPTXBaselines returns the audited lowering of PTX performance monitor registers and pmevent instructions on sm_121a.

Jump to

Keyboard shortcuts

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