allocator

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ByAllocatableMemoryAsc Compare the assignable memory of two devices in ascending order
	ByAllocatableMemoryAsc = func(p1, p2 *device.Device) bool {
		return p1.AllocatableMemory() < p2.AllocatableMemory()
	}
	// ByAllocatableMemoryDes Compare the assignable memory of two devices in descending order
	ByAllocatableMemoryDes = func(p1, p2 *device.Device) bool {
		return p1.AllocatableMemory() > p2.AllocatableMemory()
	}
	// ByAllocatableCoresAsc Compare the assignable cores of two devices in ascending order
	ByAllocatableCoresAsc = func(p1, p2 *device.Device) bool {
		return p1.AllocatableCores() < p2.AllocatableCores()
	}
	// ByAllocatableCoresDes Compare the assignable cores of two devices in descending order
	ByAllocatableCoresDes = func(p1, p2 *device.Device) bool {
		return p1.AllocatableCores() > p2.AllocatableCores()
	}
	// ByDeviceIdAsc Compare the device id of two devices in ascending order
	ByDeviceIdAsc = func(p1, p2 *device.Device) bool {
		return p1.GetID() < p2.GetID()
	}
	ByAllocatableNumberDes = func(p1, p2 *device.Device) bool {
		return p1.AllocatableNumber() > p2.AllocatableNumber()
	}
	ByNumaAsc = func(p1, p2 *device.Device) bool {
		return p1.GetNUMA() < p2.GetNUMA()
	}
	ByNodeNameAsc = func(p1, p2 *device.NodeInfo) bool {
		return p1.GetName() < p2.GetName()
	}
	// ByNodeScoreAsc Sort in ascending order based on node scores,
	// to avoid double counting scores, a score cache was used.
	ByNodeScoreAsc = func() func(p1, p2 *device.NodeInfo) bool {
		nodeScoreMap := map[string]float64{}
		return func(p1, p2 *device.NodeInfo) bool {
			p1Score, ok := nodeScoreMap[p1.GetName()]
			if !ok {
				p1Score = GetNodeScore(p1)
				nodeScoreMap[p1.GetName()] = p1Score
			}
			p2Score, ok := nodeScoreMap[p2.GetName()]
			if !ok {
				p2Score = GetNodeScore(p2)
				nodeScoreMap[p2.GetName()] = p2Score
			}
			return p1Score < p2Score
		}
	}
	// ByNodeScoreDes Sort in descending order based on node scores,
	// to avoid double counting scores, a score cache was used.
	ByNodeScoreDes = func() func(p1, p2 *device.NodeInfo) bool {
		nodeScoreMap := map[string]float64{}
		return func(p1, p2 *device.NodeInfo) bool {
			p1Score, ok := nodeScoreMap[p1.GetName()]
			if !ok {
				p1Score = GetNodeScore(p1)
				nodeScoreMap[p1.GetName()] = p1Score
			}
			p2Score, ok := nodeScoreMap[p2.GetName()]
			if !ok {
				p2Score = GetNodeScore(p2)
				nodeScoreMap[p2.GetName()] = p2Score
			}
			return p1Score > p2Score
		}
	}
)

Functions

func GetDeviceScore

func GetDeviceScore(info *device.Device) float64

GetDeviceScore Calculate device score: assignableResource / totalResource = scorePercentage

func GetNodeScore

func GetNodeScore(info *device.NodeInfo) float64

GetNodeScore Calculate node score: freeResource / totalResource = scorePercentage

func GetNumaNodeScore

func GetNumaNodeScore(devices []*device.Device) float64

GetNumaNodeScore Calculate the average score of all devices on the numa node

func NewAllocator

func NewAllocator(nodeInfo *device.NodeInfo) *allocator

func NewDeviceBinpackPriority

func NewDeviceBinpackPriority() *sortPriority[*device.Device]

func NewDeviceSpreadPriority

func NewDeviceSpreadPriority() *sortPriority[*device.Device]

func NewNodeBinpackPriority

func NewNodeBinpackPriority() *sortPriority[*device.NodeInfo]

func NewNodeSpreadPriority

func NewNodeSpreadPriority() *sortPriority[*device.NodeInfo]

func NewSortPriority

func NewSortPriority[T any](less ...LessFunc[T]) *sortPriority[T]

Types

type Callback

type Callback func(numaNode int, devices []*device.Device) (done bool)

type LessFunc

type LessFunc[T any] func(p1, p2 T) bool

LessFunc represents function to compare two DeviceInfo or NodeInfo

type NumaNodeDevice

type NumaNodeDevice map[int][]*device.Device

func CanNotCrossNumaNode

func CanNotCrossNumaNode(gpuNumber int, devices []*device.Device) (NumaNodeDevice, bool)

func NewNumaNodeDevice

func NewNumaNodeDevice(devices []*device.Device) NumaNodeDevice

func (NumaNodeDevice) BinpackCallback

func (n NumaNodeDevice) BinpackCallback(callback Callback)

func (NumaNodeDevice) DefaultCallback

func (n NumaNodeDevice) DefaultCallback(callback Callback)

func (NumaNodeDevice) MaxDeviceNumberForNumaNode

func (n NumaNodeDevice) MaxDeviceNumberForNumaNode() int

func (NumaNodeDevice) SchedulerPolicyCallback

func (n NumaNodeDevice) SchedulerPolicyCallback(policy util.SchedulerPolicy, callback Callback)

func (NumaNodeDevice) SpreadCallback

func (n NumaNodeDevice) SpreadCallback(callback Callback)

Jump to

Keyboard shortcuts

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