device

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 9 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 *DeviceInfo) bool {
		return p1.AllocatableMemory() < p2.AllocatableMemory()
	}
	// ByAllocatableMemoryDes Compare the assignable memory of two devices in descending order
	ByAllocatableMemoryDes = func(p1, p2 *DeviceInfo) bool {
		return p1.AllocatableMemory() > p2.AllocatableMemory()
	}
	// ByAllocatableCoresAsc Compare the assignable cores of two devices in ascending order
	ByAllocatableCoresAsc = func(p1, p2 *DeviceInfo) bool {
		return p1.AllocatableCores() < p2.AllocatableCores()
	}
	// ByAllocatableCoresDes Compare the assignable cores of two devices in descending order
	ByAllocatableCoresDes = func(p1, p2 *DeviceInfo) bool {
		return p1.AllocatableCores() > p2.AllocatableCores()
	}
	// ByDeviceIdAsc Compare the device id of two devices in ascending order
	ByDeviceIdAsc = func(p1, p2 *DeviceInfo) bool {
		return p1.GetID() < p2.GetID()
	}
	ByAllocatableNumberDes = func(p1, p2 *DeviceInfo) bool {
		return p1.AllocatableNumber() > p2.AllocatableNumber()
	}
	ByNumaAsc = func(p1, p2 *DeviceInfo) bool {
		return p1.GetNUMA() < p2.GetNUMA()
	}
	//ByAllocatableNumberAsc = func(p1, p2 *DeviceInfo) bool {
	//	return p1.AllocatableNumber() < p2.AllocatableNumber()
	//}
	ByNodeScoreDes = func(p1, p2 *NodeInfo) bool {
		return GetNodeScore(p1) > GetNodeScore(p2)
	}
	ByNodeScoreAsc = func(p1, p2 *NodeInfo) bool {
		return GetNodeScore(p1) < GetNodeScore(p2)
	}
	ByNodeNameAsc = func(p1, p2 *NodeInfo) bool {
		return p1.GetName() < p2.GetName()
	}
)

Functions

func GetNodeScore

func GetNodeScore(info *NodeInfo) float64

GetNodeScore 计算节点空闲资源得分:空闲资源 / 资源总量 = 可用资源百分比

func NewAllocator

func NewAllocator(n *NodeInfo) *allocator

func NewDeviceBinpackPriority

func NewDeviceBinpackPriority(number int) *sortPriority[*DeviceInfo]

func NewDeviceInfoMapByNode

func NewDeviceInfoMapByNode(node *corev1.Node) (map[int]*DeviceInfo, error)

func NewDeviceSpreadPriority

func NewDeviceSpreadPriority(number int) *sortPriority[*DeviceInfo]

func NewNodeBinpackPriority

func NewNodeBinpackPriority() *sortPriority[*NodeInfo]

func NewNodeSpreadPriority

func NewNodeSpreadPriority() *sortPriority[*NodeInfo]

func NewSortPriority

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

Types

type ClaimDevice

type ClaimDevice struct {
	Id     int    `json:"id"`
	Uuid   string `json:"uuid"`
	Core   int    `json:"core"`
	Memory int    `json:"memory"`
}

func (*ClaimDevice) MarshalText

func (c *ClaimDevice) MarshalText() (string, error)

func (*ClaimDevice) UnmarshalText

func (c *ClaimDevice) UnmarshalText(text string) error

type ContainerDevices

type ContainerDevices struct {
	Name    string        `json:"name"`
	Devices []ClaimDevice `json:"devices"`
}

func GetCurrentPreAllocateContainerDevice

func GetCurrentPreAllocateContainerDevice(pod *corev1.Pod) (*ContainerDevices, error)

GetCurrentPreAllocateContainerDevice find the device information pre allocated to the current container.

func (*ContainerDevices) MarshalText

func (c *ContainerDevices) MarshalText() (string, error)

func (*ContainerDevices) UnmarshalText

func (c *ContainerDevices) UnmarshalText(text string) error

type DeviceInfo

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

func NewDeviceInfo

func NewDeviceInfo(gpuInfo GPUInfo) *DeviceInfo

func (*DeviceInfo) AllocatableCores

func (dev *DeviceInfo) AllocatableCores() int

AllocatableCores returns the remaining cores of this GPU device

func (*DeviceInfo) AllocatableMemory

func (dev *DeviceInfo) AllocatableMemory() int

AllocatableMemory returns the remaining memory of this GPU device

func (*DeviceInfo) AllocatableNumber

func (dev *DeviceInfo) AllocatableNumber() int

AllocatableNumber returns the remaining number of this GPU device

func (*DeviceInfo) GetComputeCapability

func (dev *DeviceInfo) GetComputeCapability() int

GetComputeCapability returns the capability of this device

func (*DeviceInfo) GetID

func (dev *DeviceInfo) GetID() int

GetID returns the idx of this device

func (*DeviceInfo) GetNUMA

func (dev *DeviceInfo) GetNUMA() int

GetNUMA returns the numa of this device

func (*DeviceInfo) GetTotalCore

func (dev *DeviceInfo) GetTotalCore() int

GetTotalCore returns the totalCore of this device

func (*DeviceInfo) GetTotalMemory

func (dev *DeviceInfo) GetTotalMemory() int

GetTotalMemory returns the totalMemory of this device

func (*DeviceInfo) GetTotalNumber

func (dev *DeviceInfo) GetTotalNumber() int

GetTotalNumber returns the totalNum of this device

func (*DeviceInfo) GetType

func (dev *DeviceInfo) GetType() string

GetType returns the type of this device

func (*DeviceInfo) GetUUID

func (dev *DeviceInfo) GetUUID() string

GetUUID returns the uuid of this device

func (*DeviceInfo) Healthy

func (dev *DeviceInfo) Healthy() bool

Healthy return whether the device is healthy

func (*DeviceInfo) Mig

func (dev *DeviceInfo) Mig() bool

type GPUInfo

type GPUInfo struct {
	Id         int    `json:"id"`
	Uuid       string `json:"uuid"`
	Core       int    `json:"core"`
	Memory     int    `json:"memory"`
	Type       string `json:"type"`
	Mig        bool   `json:"mig"`
	Number     int    `json:"number"`
	Numa       int    `json:"numa"`
	Capability int    `json:"capability"`
	Healthy    bool   `json:"healthy"`
}

type LessFunc

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

LessFunc represents function to compare two DeviceInfo or NodeInfo

type NodeDeviceInfos

type NodeDeviceInfos []GPUInfo

func ParseNodeDeviceInfos

func ParseNodeDeviceInfos(val string) (NodeDeviceInfos, error)

func (NodeDeviceInfos) Encode

func (n NodeDeviceInfos) Encode() (string, error)

type NodeInfo

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

func NewNodeInfo

func NewNodeInfo(node *corev1.Node, pods []*corev1.Pod) (*NodeInfo, error)

func (*NodeInfo) GetAvailableCore

func (n *NodeInfo) GetAvailableCore() int

GetAvailableCore returns the remaining cores of this node

func (*NodeInfo) GetAvailableMemory

func (n *NodeInfo) GetAvailableMemory() int

GetAvailableMemory returns the remaining memory of this node

func (*NodeInfo) GetAvailableNumber

func (n *NodeInfo) GetAvailableNumber() int

GetAvailableNumber returns the remaining number of this node

func (*NodeInfo) GetDeviceCount

func (n *NodeInfo) GetDeviceCount() int

GetDeviceCount returns the number of GPU devices

func (*NodeInfo) GetDeviceMap

func (n *NodeInfo) GetDeviceMap() map[int]*DeviceInfo

GetDeviceMap returns each GPU device information structure

func (*NodeInfo) GetMaxCapability

func (n *NodeInfo) GetMaxCapability() int

GetMaxCapability returns the maxCapability of GPU devices

func (*NodeInfo) GetName

func (n *NodeInfo) GetName() string

GetName returns node name

func (*NodeInfo) GetNode

func (n *NodeInfo) GetNode() *corev1.Node

GetNode returns the original node structure of kubernetes

func (*NodeInfo) GetTotalCore

func (n *NodeInfo) GetTotalCore() int

GetTotalCore returns the total cores of this node

func (*NodeInfo) GetTotalMemory

func (n *NodeInfo) GetTotalMemory() int

GetTotalMemory returns the total memory of this node

func (*NodeInfo) GetTotalNumber

func (n *NodeInfo) GetTotalNumber() int

GetTotalNumber returns the total number of this node

type PodDevices

type PodDevices []ContainerDevices

func GetPodAssignDevices

func GetPodAssignDevices(pod *corev1.Pod) PodDevices

func (*PodDevices) MarshalText

func (p *PodDevices) MarshalText() (string, error)

func (*PodDevices) UnmarshalText

func (p *PodDevices) UnmarshalText(text string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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