Documentation
¶
Overview ¶
Package fabricmanager provides low-level Go bindings for NVIDIA Fabric Manager.
Fabric Manager configures the NVLink fabric on NVSwitch-based systems. It partitions the fabric into isolated sets of GPUs, activates and deactivates those partitions, and reports GPUs and switches whose NVLink connections failed to train.
Fabric Manager complements NVML: NVML reports NVLink state for a single device, while Fabric Manager operates on the fabric spanning devices.
Call LibInit, then Connect to obtain a Handle bound to a running Fabric Manager instance. Release it with Handle.Disconnect and LibShutdown.
Structs passed to the query functions are versioned: set the version field to the matching FM_*_VERSION value before the call, or Fabric Manager returns ErrVersionMismatch.
Example ¶
Example connects to a running Fabric Manager instance on the local host and lists the fabric partitions it supports. It returns early when the library is absent or no instance is listening, which is every machine without an NVSwitch fabric.
Every versioned struct carries its own size in the low 24 bits of Version and the struct revision in the high 8, which is what FM_*_VERSION expands to in the C header; the constants themselves are not exported, so the value is computed from the Go struct.
package main
import (
"fmt"
"unsafe"
"github.com/tmc/lib/nvidia/fabricmanager"
)
func main() {
if err := fabricmanager.LibInit(); err != nil {
fmt.Println("Fabric Manager unavailable:", err)
return
}
defer fabricmanager.LibShutdown()
params := fabricmanager.ConnectParams{TimeoutMs: 1000}
copy(params.AddressInfo[:], "127.0.0.1:6666")
params.Version = uint32(unsafe.Sizeof(params)) | 1<<24
h, err := fabricmanager.Connect(¶ms)
if err != nil {
fmt.Println("connect:", err)
return
}
defer h.Disconnect()
var list fabricmanager.FabricPartitionList
list.Version = uint32(unsafe.Sizeof(list)) | 1<<24
if err := h.SupportedFabricPartitions(&list); err != nil {
fmt.Println("partitions:", err)
return
}
for _, p := range list.PartitionInfo[:list.NumPartitions] {
fmt.Printf("partition %d: %d GPUs\n", p.PartitionId, p.NumGpus)
}
}
Output:
Index ¶
- func Close() error
- func Has(symbol string) bool
- func HasActivateFabricPartition() bool
- func HasActivateFabricPartitionWithVFs() bool
- func HasConnect() bool
- func HasDeactivateFabricPartition() bool
- func HasDisconnect() bool
- func HasGetNvlinkFailedDevices() bool
- func HasGetSupportedFabricPartitions() bool
- func HasGetUnsupportedFabricPartitions() bool
- func HasLibInit() bool
- func HasLibShutdown() bool
- func HasSetActivatedFabricPartitions() bool
- func LibInit() error
- func LibShutdown() error
- func Load(path string) error
- func Loaded() bool
- func Path() string
- type ActivatedFabricPartitionList
- type ActivatedFabricPartitionListV1
- type BindFailure
- type CallError
- type ConnectParams
- type ConnectParamsV1
- type ConnectParamsV2
- type FabricPartitionGpuInfo
- type FabricPartitionInfo
- type FabricPartitionList
- type FabricPartitionListV2
- type Handle
- func (h Handle) ActivateFabricPartition(partitionId uint32) error
- func (h Handle) ActivateFabricPartitionWithVFs(partitionId uint32, vfList *PciDevice, numVfs uint32) error
- func (h Handle) DeactivateFabricPartition(partitionId uint32) error
- func (h Handle) Disconnect() error
- func (h Handle) NvlinkFailedDevices(pFmNvlinkFailedDevices *NvlinkFailedDevices) error
- func (h Handle) SetActivatedFabricPartitions(pFmActivatedPartitionList *ActivatedFabricPartitionList) error
- func (h Handle) SupportedFabricPartitions(pFmFabricPartition *FabricPartitionList) error
- func (h Handle) UnsupportedFabricPartitions(pFmUnupportedFabricPartition *UnsupportedFabricPartitionList) error
- type LibraryAttempt
- type LibraryConflictError
- type LibraryError
- type NvFmApiAddrTypes
- type NvlinkFailedDeviceInfo
- type NvlinkFailedDevices
- type NvlinkFailedDevicesV1
- type PciDevice
- type Result
- type SymbolError
- type UnsupportedFabricPartitionInfo
- type UnsupportedFabricPartitionList
- type UnsupportedFabricPartitionListV1
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶
func Close() error
Close unloads the library and clears all bound function pointers.
The function pointers are package-level state, so Close must not be called concurrently with any other call into this package: doing so is a use-after-free. It is intended for test teardown, not for reclaiming a live library.
func Has ¶
Has reports whether the named C symbol resolved in the loaded library, loading it first if necessary. It returns false if the library failed to load. Use it to gate on capabilities before calling into them.
func HasActivateFabricPartition ¶
func HasActivateFabricPartition() bool
HasActivateFabricPartition reports whether fmActivateFabricPartition resolved in the loaded library.
func HasActivateFabricPartitionWithVFs ¶
func HasActivateFabricPartitionWithVFs() bool
HasActivateFabricPartitionWithVFs reports whether fmActivateFabricPartitionWithVFs resolved in the loaded library.
func HasConnect ¶
func HasConnect() bool
HasConnect reports whether fmConnect resolved in the loaded library.
func HasDeactivateFabricPartition ¶
func HasDeactivateFabricPartition() bool
HasDeactivateFabricPartition reports whether fmDeactivateFabricPartition resolved in the loaded library.
func HasDisconnect ¶
func HasDisconnect() bool
HasDisconnect reports whether fmDisconnect resolved in the loaded library.
func HasGetNvlinkFailedDevices ¶
func HasGetNvlinkFailedDevices() bool
HasGetNvlinkFailedDevices reports whether fmGetNvlinkFailedDevices resolved in the loaded library.
func HasGetSupportedFabricPartitions ¶
func HasGetSupportedFabricPartitions() bool
HasGetSupportedFabricPartitions reports whether fmGetSupportedFabricPartitions resolved in the loaded library.
func HasGetUnsupportedFabricPartitions ¶
func HasGetUnsupportedFabricPartitions() bool
HasGetUnsupportedFabricPartitions reports whether fmGetUnsupportedFabricPartitions resolved in the loaded library.
func HasLibInit ¶
func HasLibInit() bool
HasLibInit reports whether fmLibInit resolved in the loaded library.
func HasLibShutdown ¶
func HasLibShutdown() bool
HasLibShutdown reports whether fmLibShutdown resolved in the loaded library.
func HasSetActivatedFabricPartitions ¶
func HasSetActivatedFabricPartitions() bool
HasSetActivatedFabricPartitions reports whether fmSetActivatedFabricPartitions resolved in the loaded library.
func Load ¶
Load opens the shared library from path, or from the default search list when path is empty, and binds all symbols. Callers that need to direct loading should call Load before any other function; otherwise the first call loads from the default search list.
Load is idempotent: calling it again with the same path, or with an empty path, returns nil. Calling it with a different path after a successful load returns *LibraryConflictError rather than replacing the library. After a failed load, Load retries.
Types ¶
type ActivatedFabricPartitionList ¶
type ActivatedFabricPartitionList struct {
Version uint32
NumPartitions uint32
PartitionIds [64]uint32
}
ActivatedFabricPartitionList stores information about all the activated fabric partitionIds.
type ActivatedFabricPartitionListV1 ¶
type ActivatedFabricPartitionListV1 = ActivatedFabricPartitionList
ActivatedFabricPartitionListV1 is an alias for ActivatedFabricPartitionList.
type BindFailure ¶
BindFailure names a symbol the loaded library exports but that could not be bound, and why.
func BindFailures ¶
func BindFailures() []BindFailure
BindFailures returns the symbols the loaded library exports that could not be bound, sorted by symbol name, or nil if every exported symbol bound. Calling one of these reports *SymbolError with the same Err.
A load that reports no error can still leave symbols unbound: the library is fine and the signatures are not representable here. Call this after Load to find that out at once rather than one call site at a time. It does not trigger a load, and returns nil if none has happened.
type CallError ¶
CallError reports that a library call returned a failure result.
Unwrap returns Result, so errors.Is(err, c) reports whether the call returned the Result constant c, and errors.As(err, &r) with r of type Result recovers the code.
type ConnectParams ¶
type ConnectParams struct {
Version uint32
AddressInfo [256]byte
TimeoutMs uint32
AddressIsUnixSocket uint32
AddressType NvFmApiAddrTypes
}
ConnectParams represents fmConnectParams_v2.
type ConnectParamsV1 ¶
type ConnectParamsV1 struct {
Version uint32
AddressInfo [256]byte
TimeoutMs uint32
AddressIsUnixSocket uint32
}
ConnectParamsV1 represents connection options for Connect.
type ConnectParamsV2 ¶
type ConnectParamsV2 = ConnectParams
ConnectParamsV2 is an alias for ConnectParams.
type FabricPartitionGpuInfo ¶
type FabricPartitionGpuInfo struct {
PhysicalId uint32
Uuid [80]byte
PciBusId [32]byte
NumNvLinksAvailable uint32
MaxNumNvLinks uint32
NvlinkLineRateMBps uint32
}
FabricPartitionGpuInfo stores information about a GPU belonging to fabric partition.
type FabricPartitionInfo ¶
type FabricPartitionInfo struct {
PartitionId uint32
IsActive uint32
NumGpus uint32
GpuInfo [16]FabricPartitionGpuInfo
}
FabricPartitionInfo stores information about a fabric partition.
type FabricPartitionList ¶
type FabricPartitionList struct {
Version uint32
NumPartitions uint32
MaxNumPartitions uint32
PartitionInfo [64]FabricPartitionInfo
}
FabricPartitionList stores information about all the supported fabric partitions.
type FabricPartitionListV2 ¶
type FabricPartitionListV2 = FabricPartitionList
FabricPartitionListV2 is an alias for FabricPartitionList.
type Handle ¶
type Handle uintptr
Handle is an opaque handle for fmHandle_t.
func Connect ¶
func Connect(connectParams *ConnectParams) (Handle, error)
Connect wraps fmConnect.
- connectParams: IN : Valid IP address for the remote host engine to connect to. If addressInfo is specified as x.x.x.x it will attempt to connect to the default port specified by FM_CMD_PORT_NUMBER If addressInfo is specified as x.x.x.x:yyyy it will attempt to connect to the port specified by yyyy To connect to an FM instance that was started with unix domain socket, fill the socket path in addressInfo member and set addressType to NV_FM_API_ADDR_TYPE_UNIX. To connect to an FM instance on a vsock connection fill addressInfo with `<cid>:<port_number>`. Supported address types are listed in NvFmApiAddrTypes enumeration. For additional connection parameters. See ConnectParams for details
func (Handle) ActivateFabricPartition ¶
ActivateFabricPartition wraps fmActivateFabricPartition.
- partitionId: IN: The partition id to be activated
func (Handle) ActivateFabricPartitionWithVFs ¶
func (h Handle) ActivateFabricPartitionWithVFs(partitionId uint32, vfList *PciDevice, numVfs uint32) error
ActivateFabricPartitionWithVFs wraps fmActivateFabricPartitionWithVFs.
- partitionId: IN: The partition id to be activated
- vfList: IN: List of VFs associated with physical GPUs in the partition. Please note that the order of VFs should be associated with actual physical GPUs in the partition
- numVfs: IN: Number of VFs
func (Handle) DeactivateFabricPartition ¶
DeactivateFabricPartition wraps fmDeactivateFabricPartition.
- partitionId: IN: The partition id to be deactivated
func (Handle) NvlinkFailedDevices ¶
func (h Handle) NvlinkFailedDevices(pFmNvlinkFailedDevices *NvlinkFailedDevices) error
NvlinkFailedDevices wraps fmGetNvlinkFailedDevices.
- pFmNvlinkFailedDevices: OUT: List of GPU or NVSwitch devices that have failed NVLinks
func (Handle) SetActivatedFabricPartitions ¶
func (h Handle) SetActivatedFabricPartitions(pFmActivatedPartitionList *ActivatedFabricPartitionList) error
SetActivatedFabricPartitions wraps fmSetActivatedFabricPartitions.
- pFmActivatedPartitionList: IN: List of currently activated fabric partition
func (Handle) SupportedFabricPartitions ¶
func (h Handle) SupportedFabricPartitions(pFmFabricPartition *FabricPartitionList) error
SupportedFabricPartitions wraps fmGetSupportedFabricPartitions.
- pFmFabricPartition: OUT: List of currently supported fabric partition information
func (Handle) UnsupportedFabricPartitions ¶
func (h Handle) UnsupportedFabricPartitions(pFmUnupportedFabricPartition *UnsupportedFabricPartitionList) error
UnsupportedFabricPartitions wraps fmGetUnsupportedFabricPartitions.
- pFmUnupportedFabricPartition: OUT: List of unsupported fabric partitions on the system
type LibraryAttempt ¶
LibraryAttempt records one failed attempt to open the shared library.
type LibraryConflictError ¶
type LibraryConflictError struct {
Loaded string
Requested string
// Implicit reports that the loaded library was opened lazily and no
// successful Load has since acknowledged it. A
// caller that sees this called some
// other function first, and that call took the default search list.
Implicit bool
}
LibraryConflictError reports a Load call naming a different library than the one already loaded. Only one library is loaded per process.
func (*LibraryConflictError) Error ¶
func (e *LibraryConflictError) Error() string
Error reports the conflicting library paths, and whether the library that is already loaded got there without a Load call.
type LibraryError ¶
type LibraryError struct {
Library string
Env string
Path string
Attempts []LibraryAttempt
Hint string
}
LibraryError reports that libnvfm could not be opened. Attempts lists every name tried in order. Path is set when an explicit path, from Load or FM_LIB_PATH, was requested and failed. Hint reports pkg-config discovery results and query failures, when discovery ran.
func (*LibraryError) Error ¶
func (e *LibraryError) Error() string
Error describes the library load attempts and their errors.
func (*LibraryError) Unwrap ¶
func (e *LibraryError) Unwrap() []error
Unwrap returns the error from each attempt.
type NvFmApiAddrTypes ¶
type NvFmApiAddrTypes int32
NvFmApiAddrTypes represents an enumeration of supported address types.
const ( NvFmApiAddrTypeUnknown NvFmApiAddrTypes = 0 NvFmApiAddrTypeInet NvFmApiAddrTypes = 1 NvFmApiAddrTypeUnix NvFmApiAddrTypes = 2 NvFmApiAddrTypeVsock NvFmApiAddrTypes = 3 )
func (NvFmApiAddrTypes) String ¶
func (e NvFmApiAddrTypes) String() string
String returns the constant name, or a numeric representation for unknown values.
type NvlinkFailedDeviceInfo ¶
type NvlinkFailedDeviceInfo struct {
Uuid [80]byte
PciBusId [32]byte
NumPorts uint32
PortNum [64]uint32
}
NvlinkFailedDeviceInfo stores information about a NVSwitch or GPU with failed NVLinks.
type NvlinkFailedDevices ¶
type NvlinkFailedDevices struct {
Version uint32
NumGpus uint32
NumSwitches uint32
GpuInfo [16]NvlinkFailedDeviceInfo
SwitchInfo [12]NvlinkFailedDeviceInfo
}
NvlinkFailedDevices stores a list of NVSwitches and GPUs with failed NVLinks.
type NvlinkFailedDevicesV1 ¶
type NvlinkFailedDevicesV1 = NvlinkFailedDevices
NvlinkFailedDevicesV1 is an alias for NvlinkFailedDevices.
type Result ¶
type Result int32
Result represents a nvfm API error code (fmReturn_t).
const ( Success Result = 0 // The operation was successful ErrBadparam Result = -1 // A supplied argument is invalid ErrGenericError Result = -2 // A generic, unspecified error ErrNotSupported Result = -3 // The requested operation/feature not supported ErrUninitialized Result = -4 // Object is in undefined state/uninitialized ErrTimeout Result = -5 // Requested operation timed out or user provided timeout passed ErrVersionMismatch Result = -6 // Version mismatch between received and understood API ErrInUse Result = -7 // The requested operation cannot be performed because the resource is in use ErrNotConfigured Result = -8 // Setting not configured ErrConnectionNotValid Result = -9 // The connection to the FM instance is not valid any longer ErrNvlinkError Result = -10 // Requested operation failed due to NVLink error ErrResourceBad Result = -11 // Requested operation referenced a resource that does not exist ErrResourceInUse Result = -12 // Requested operation failed because one of the referenced resources is already in use ErrResourceNotInUse Result = -13 // Requested operation failed because one of the referenced resources is not in use ErrResourceExhausted Result = -14 // Requested operation failed because not enough of one of the resources could be allocated ErrResourceNotReady Result = -15 // Requested operation failed because one of the resources is not ready to be used ErrPartitionExists Result = -16 // Partition has already been created, nothing to do ErrPartitionIdInUse Result = -17 // Partition id already used by another partition, could not complete operation ErrPartitionIdNotInUse Result = -18 // Partition id could not be found ErrPartitionNameInUse Result = -19 // Partition name is already used by another partition and name is supposed to be unique ErrPartitionNameNotInUse Result = -20 // Partition name is specified but the referenced partition could not be found ErrPartitionIdNameMismatch Result = -21 // Valid partition id and name specified but they refer to different partitions ErrNotReady Result = -22 // Fabric Manager is not ready to serve GFM API requests. ErrResourceUsedInThisPartition Result = -23 // Resource is already in use in this partition ErrResourceUsedInAnotherPartition Result = -24 // Resource is already in use in another partition ErrPartitionMiswiredTrunks Result = -25 // Partition has miswired trunks ErrPartitionInsufficientTrunks Result = -26 // Partition has insufficient trunks ErrPartitionMissingSwitches Result = -27 // Partition has missing switches ErrPartitionNetworkConfigError Result = -28 // Partition has network configuration error ErrPartitionRouteProgrammingError Result = -29 // Partition has route programming error )
nvfm error codes from nv_fm_agent.h.
type SymbolError ¶
SymbolError reports that a symbol is not callable.
Err distinguishes the two ways that happens. A nil Err means the loaded library does not export the symbol, which is what an installation older than the symbol looks like. A non-nil Err means the library does export it and the binding itself failed; the library is not at fault.
func (*SymbolError) Error ¶
func (e *SymbolError) Error() string
Error reports the uncallable library symbol and, when the symbol was present but could not be bound, why.
func (*SymbolError) Unwrap ¶
func (e *SymbolError) Unwrap() error
Unwrap returns the reason the symbol could not be bound, or nil when the loaded library does not export it.
type UnsupportedFabricPartitionInfo ¶
type UnsupportedFabricPartitionInfo struct {
PartitionId uint32
NumGpus uint32
GpuPhysicalIds [16]uint32
}
UnsupportedFabricPartitionInfo stores information about a unsupported fabric partition.
type UnsupportedFabricPartitionList ¶
type UnsupportedFabricPartitionList struct {
Version uint32
NumPartitions uint32
PartitionInfo [64]UnsupportedFabricPartitionInfo
}
UnsupportedFabricPartitionList stores information about all the unsupported fabric partitions.
type UnsupportedFabricPartitionListV1 ¶
type UnsupportedFabricPartitionListV1 = UnsupportedFabricPartitionList
UnsupportedFabricPartitionListV1 is an alias for UnsupportedFabricPartitionList.