gpuallocator

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator struct {
	GPUs []*Device
	// contains filtered or unexported fields
}

Allocator defines the primary object for allocating and freeing the available GPUs on a node.

func NewAllocator

func NewAllocator(policy Policy) (*Allocator, error)

NewAllocator creates a new Allocator using the given allocation policy

func NewBestEffortAllocator

func NewBestEffortAllocator() (*Allocator, error)

NewBestEffortAllocator creates a new Allocator using the BestEffort allocation policy

func (*Allocator) Allocate

func (a *Allocator) Allocate(num int) []*Device

Allocate a set of 'num' GPUs from the allocator. If 'num' devices cannot be allocated, return an empty slice.

func (*Allocator) AllocateSpecific

func (a *Allocator) AllocateSpecific(devices ...*Device) error

AllocateSpecific allocates a specific set of GPUs from the allocator. Return an error if any of the specified devices cannot be allocated.

func (*Allocator) Free

func (a *Allocator) Free(devices ...*Device)

Free a set of GPUs back to the allocator.

type Device

type Device struct {
	Index int
	Links map[int][]P2PLink
	// contains filtered or unexported fields
}

Device represents a GPU device as reported by NVML, including all of its Point-to-Point link information.

func NewDevice

func NewDevice(index int, uuid, busId string) *Device
func (from *Device) AddLink(to *Device, linkType links.P2PLinkType)

func (*Device) Details

func (from *Device) Details() string

Details returns all details of a Device as a multi-line string.

func (*Device) String

func (from *Device) String() string

String returns a compact representation of a Device as string of its index.

type DeviceList

type DeviceList []*Device

DeviceList stores an ordered list of devices.

func NewDevices

func NewDevices(opts ...Option) (DeviceList, error)

NewDevices creates a list of Devices from all available nvml.Devices using the specified options.

func NewDevicesFrom

func NewDevicesFrom(uuids []string) (DeviceList, error)

NewDevicesFrom creates a list of Devices from the specific set of GPU uuids passed in.

func (d DeviceList) AddLink(from, to int, linkType links.P2PLinkType)

func (DeviceList) Devices added in v0.4.0

func (d DeviceList) Devices() []*Device

func (DeviceList) Filter

func (d DeviceList) Filter(uuids []string) (DeviceList, error)

Filter filters out the selected devices from the list. Note that the specified uuids must exist in the list of devices.

type DeviceSet

type DeviceSet map[string]*Device

DeviceSet is used to hold and manipulate a set of unique GPU devices.

func NewDeviceSet

func NewDeviceSet(devices ...*Device) DeviceSet

NewDeviceSet creates a new DeviceSet.

func (DeviceSet) Contains

func (ds DeviceSet) Contains(device *Device) bool

Contains checks if a device is present in a DeviceSet.

func (DeviceSet) ContainsAll

func (ds DeviceSet) ContainsAll(devices []*Device) bool

ContainsAll checks if a list of devices is present in a DeviceSet.

func (DeviceSet) Delete

func (ds DeviceSet) Delete(devices ...*Device)

Delete deletes a list of devices from a DeviceSet.

func (DeviceSet) Insert

func (ds DeviceSet) Insert(devices ...*Device)

Insert inserts a list of devices into a DeviceSet.

func (DeviceSet) SortedSlice

func (ds DeviceSet) SortedSlice() []*Device

SortedSlice etunrs returns a slice of devices, sorted by device index from a DeviceSet.

type Option

type Option func(*deviceListBuilder)

Option defines a type for functional options for constructing device lists.

func WithDeviceLib

func WithDeviceLib(devicelib device.Interface) Option

WithDeviceLib provides an option to set the library used for device enumeration.

func WithNvmlLib

func WithNvmlLib(nvmllib nvml.Interface) Option

WithNvmlLib provides an option to set the nvml library.

type P2PLink struct {
	GPU  *Device
	Type links.P2PLinkType
}

P2PLink represents a Point-to-Point link between two GPU devices. The link is between the Device struct this struct is embedded in and the GPU Device contained in the P2PLink struct itself.

type Policy

type Policy interface {
	// Allocate is meant to do the heavy-lifting of implementing the actual
	// allocation strategy of the policy. It takes a slice of devices to
	// allocate GPUs from, and an amount 'size' to allocate from that slice. It
	// then returns a subset of devices of length 'size'. If the policy is
	// unable to allocate 'size' GPUs from the slice of input devices, it
	// returns an empty slice.
	Allocate(available []*Device, required []*Device, size int) []*Device
}

Policy defines an interface for pluggable allocation policies to be added to an Allocator.

func NewBestEffortPolicy

func NewBestEffortPolicy() Policy

NewBestEffortPolicy creates a new BestEffortPolicy.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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