nvtx

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: 6 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.

README

NVTX loader policy

The handwritten loader_unix.go opens the injection provider with RTLD_NOW | RTLD_GLOBAL. Keep eager relocation: unresolved provider dependencies should produce a load error before initInjection invokes the entry point. On a load error, initialization returns with instrumentation disabled. Global symbol visibility is retained for compatibility.

The generated ../../driver/loader_unix.gen.go instead requests RTLD_LAZY | RTLD_GLOBAL. Changing that to RTLD_NOW can reject a library with unresolved function references even when those functions are never called. There is no demonstrated driver defect requiring that compatibility change. This policy concerns relocations inside the loaded library; it is separate from deferring library loading until first use and from probing exported CUDA functions with dlsym.

The driver file is marked as output of driver-survey. Its recipe is delegated to nvgen in tmc/libgen; fixes belong in that generator and must be regenerated, not patched into this checkout's generated files. NVTX's loader is owned here.

TestOpenDynamicLibrary builds synthetic libraries on Linux and Darwin with cc: a valid export must be callable and globally visible, and an unused unresolved function reference must cause an open error. It skips if cc is unavailable. This tests the host loader, not CUDA or Nsight compatibility.

Documentation

Overview

Package nvtx provides a pure-Go, zero-cgo implementation of NVIDIA Tools Extension (NVTX v3).

NVTX v3 is a header-only instrumentation protocol. When running under profilers such as NVIDIA Nsight Systems (nsys) or Nsight Compute (ncu), the profiler sets the NVTX_INJECTION64_PATH environment variable to inject the profiling library. When NVTX_INJECTION64_PATH is unset and an NVTX v3.7 runtime marker file is present (/run/nvidia/nvtx/nvtx-cuda.yaml or $XDG_RUNTIME_DIR/nvidia/nvtx/nvtx-cuda.yaml, as used by the Nsight Perf SDK), the package opens libcuda.so.1 and queries cuNvtxGetInjectionInitializer.

When no injection provider is configured, calls are safe no-ops without a native provider invocation. When attached, the injection provider is dynamically loaded via purego, enabling high-resolution timeline markers, nested ranges, domains, CUDA resource naming, and thread naming for Nsight timelines.

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/cuda/nvtx"
)

func main() {
	// Nested timeline range
	nvtx.RangePush("TransformerForward")
	// Execute forward pass...
	nvtx.RangePop()

	// Instantaneous event marker
	nvtx.Mark("CheckpointReached")

	fmt.Println("NVTX operations completed successfully")
}
Output:
NVTX operations completed successfully

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled

func Enabled() bool

Enabled reports whether an active NVTX injection provider (e.g. Nsight Systems) is attached.

func Mark

func Mark(msg string)

Mark records an instantaneous event marker on the global timeline.

func NameCUDAContext

func NameCUDAContext(context uintptr, name string)

NameCUDAContext assigns a name to a CUDA driver context.

The context is the opaque CUcontext value represented by uintptr. The call is a no-op when no NVTX injection provider is attached.

func NameCUDADevice

func NameCUDADevice(device int32, name string)

NameCUDADevice assigns a name to a CUDA driver device.

The call is a no-op when no NVTX injection provider is attached.

func NameCUDAEvent

func NameCUDAEvent(event uintptr, name string)

NameCUDAEvent assigns a name to a CUDA driver event.

The event is the opaque CUevent value represented by uintptr. The call is a no-op when no NVTX injection provider is attached.

func NameCUDAStream

func NameCUDAStream(stream uintptr, name string)

NameCUDAStream assigns a name to a CUDA driver stream.

The stream is the opaque CUstream value represented by uintptr. The call is a no-op when no NVTX injection provider is attached.

func NameCategory

func NameCategory(category uint32, name string)

NameCategory assigns a name to a global integer category ID.

func NameOSThread

func NameOSThread(threadID uint32, name string)

NameOSThread assigns a human-readable name to the specified operating system thread in Nsight timelines.

func RangeEnd

func RangeEnd(id RangeID)

RangeEnd ends a non-nested range previously started by RangeStart.

func RangePop

func RangePop() int

RangePop pops the most recent nested timeline range from the current thread. Returns the remaining stack depth.

func RangePush

func RangePush(msg string) int

RangePush pushes a nested timeline range on the current thread. Returns the 0-based depth level of the range being started.

func ScopedRange

func ScopedRange(msg string) func()

ScopedRange starts a nested range and pins the calling goroutine to its current operating-system thread until the returned function is called. Call the returned function from the same goroutine, normally with defer:

defer nvtx.ScopedRange("MatMul")()

Types

type Domain

type Domain struct {
	// contains filtered or unexported fields
}

Domain represents an isolated NVTX instrumentation namespace. Its methods may be called concurrently. Close waits for active scoped ranges and native calls, then makes subsequent calls no-ops.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/cuda/nvtx"
)

func main() {
	// Isolate instrumentation to a custom domain
	domain := nvtx.CreateDomain("DeepSeekInference")
	defer domain.Close()

	domain.RangePush("MoEExpertDispatch")
	// Execute dispatch...
	domain.RangePop()

	fmt.Println("Domain operations completed successfully")
}
Output:
Domain operations completed successfully

func CreateDomain

func CreateDomain(name string) *Domain

CreateDomain creates a named custom NVTX domain.

func (*Domain) Close

func (d *Domain) Close() error

Close destroys the custom domain and invalidates its resources. It is safe on a nil or zero Domain and idempotent on repeat calls.

func (*Domain) Mark

func (d *Domain) Mark(msg string)

Mark records an instantaneous event marker within this domain.

func (*Domain) NameCategory

func (d *Domain) NameCategory(category uint32, name string)

NameCategory assigns a name to an integer category ID in d.

func (*Domain) RangeEnd

func (d *Domain) RangeEnd(id RangeID)

RangeEnd ends a non-nested range within this domain.

func (*Domain) RangePop

func (d *Domain) RangePop() int

RangePop pops the most recent nested timeline range within this domain.

func (*Domain) RangePush

func (d *Domain) RangePush(msg string) int

RangePush pushes a nested timeline range on the current thread within this domain.

func (*Domain) RangeStart

func (d *Domain) RangeStart(msg string) RangeID

RangeStart starts a non-nested range within this domain.

func (*Domain) Raw

func (d *Domain) Raw() uintptr

Raw returns the underlying native NVTX domain handle.

func (*Domain) RegisterString

func (d *Domain) RegisterString(s string) StringHandle

RegisterString registers an immutable string in the domain for zero-overhead repeated referencing.

func (*Domain) ScopedRange

func (d *Domain) ScopedRange(msg string) func()

ScopedRange starts a nested range in d and pins the calling goroutine to its current operating-system thread until the returned function is called. It also keeps d alive for the range lifetime. Call the returned function from the same goroutine, normally with defer.

type RangeID

type RangeID uint64

RangeID represents a process-unique identifier for a non-nested NVTX range.

func RangeStart

func RangeStart(msg string) RangeID

RangeStart starts a non-nested range spanning across goroutines or asynchronous streams.

type StringHandle

type StringHandle uintptr

StringHandle represents an immutable registered string token in an NVTX domain.

Jump to

Keyboard shortcuts

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