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 ¶
- func Enabled() bool
- func Mark(msg string)
- func NameCUDAContext(context uintptr, name string)
- func NameCUDADevice(device int32, name string)
- func NameCUDAEvent(event uintptr, name string)
- func NameCUDAStream(stream uintptr, name string)
- func NameCategory(category uint32, name string)
- func NameOSThread(threadID uint32, name string)
- func RangeEnd(id RangeID)
- func RangePop() int
- func RangePush(msg string) int
- func ScopedRange(msg string) func()
- type Domain
- func (d *Domain) Close() error
- func (d *Domain) Mark(msg string)
- func (d *Domain) NameCategory(category uint32, name string)
- func (d *Domain) RangeEnd(id RangeID)
- func (d *Domain) RangePop() int
- func (d *Domain) RangePush(msg string) int
- func (d *Domain) RangeStart(msg string) RangeID
- func (d *Domain) Raw() uintptr
- func (d *Domain) RegisterString(s string) StringHandle
- func (d *Domain) ScopedRange(msg string) func()
- type RangeID
- type StringHandle
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 ¶
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 ¶
NameCUDADevice assigns a name to a CUDA driver device.
The call is a no-op when no NVTX injection provider is attached.
func NameCUDAEvent ¶
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 ¶
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 ¶
NameCategory assigns a name to a global integer category ID.
func NameOSThread ¶
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 ¶
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 ¶
CreateDomain creates a named custom NVTX domain.
func (*Domain) Close ¶
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) NameCategory ¶
NameCategory assigns a name to an integer category ID in d.
func (*Domain) RangePush ¶
RangePush pushes a nested timeline range on the current thread within this domain.
func (*Domain) RangeStart ¶
RangeStart starts a non-nested range within this domain.
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 ¶
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 ¶
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.