Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
Signed-off-by: peiniliu <[email protected]>
  • Loading branch information
peiniliu committed Aug 31, 2021
1 parent fd7d0f3 commit 6db3361
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 54 deletions.
8 changes: 3 additions & 5 deletions pkg/scheduler/api/device_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ func (g *GPUDevice) getUsedGPUMemory() uint {
// isIdleGPU check if the device is idled.
func (g *GPUDevice) isIdleGPU() bool {
if g.PodMap == nil {
return true
return true
}
return false
}


// GetGPUResourceOfPod returns the GPU resource required by the pod.
func GetGPUResourceOfPod(pod *v1.Pod) uint {
var mem uint
Expand All @@ -80,12 +79,11 @@ func getGPUResourceOfContainer(container *v1.Container) uint {
return mem
}


// GetGPUNumberOfPod returns the number of GPUs required by the pod.
func GetGPUNumberOfPod(pod *v1.Pod) int {
var gpus int
for _, container := range pod.Spec.Containers {
gpus += getGPUNumberOfContainer(&container)
gpus += getGPUNumberOfContainer(&container)
}
return gpus
}
Expand All @@ -97,4 +95,4 @@ func getGPUNumberOfContainer(container *v1.Container) int {
gpus = int(val.Value())
}
return gpus
}
}
17 changes: 8 additions & 9 deletions pkg/scheduler/api/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,23 +500,22 @@ func (ni *NodeInfo) getDevicesAllGPUMemory() map[int]uint {
func (ni *NodeInfo) GetDevicesIdleGPUs() []int {
res := []int{}
for _, device := range ni.GPUDevices {
if device.isIdleGPU(){
res = append(res, device.ID)
if device.isIdleGPU() {
res = append(res, device.ID)
}
}
return res
}


// AddGPUResource adds the pod to GPU pool if it is assigned
func (ni *NodeInfo) AddGPUResource(pod *v1.Pod) {
gpuRes := GetGPUResourceOfPod(pod)
if gpuRes > 0 {
ids := GetGPUIndex(pod)
for _, id := range ids {
if dev := ni.GPUDevices[id]; dev != nil {
dev.PodMap[string(pod.UID)] = pod
}
if dev := ni.GPUDevices[id]; dev != nil {
dev.PodMap[string(pod.UID)] = pod
}
}
}
}
Expand All @@ -527,9 +526,9 @@ func (ni *NodeInfo) SubGPUResource(pod *v1.Pod) {
if gpuRes > 0 {
ids := GetGPUIndex(pod)
for _, id := range ids {
if dev := ni.GPUDevices[id]; dev != nil {
delete(dev.PodMap, string(pod.UID))
}
if dev := ni.GPUDevices[id]; dev != nil {
delete(dev.PodMap, string(pod.UID))
}
}
}
}
16 changes: 8 additions & 8 deletions pkg/scheduler/api/pod_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ func GetGPUIndex(pod *v1.Pod) []int {
ids := strings.Split(value, ",")
idSlice := make([]int, len(ids))
for idx, id := range ids {
j, err := strconv.Atoi(id)
if err != nil {
klog.Errorf("invalid %s=%s", GPUIndex, value)
return nil
}
idSlice[idx] = j
}
j, err := strconv.Atoi(id)
if err != nil {
klog.Errorf("invalid %s=%s", GPUIndex, value)
return nil
}
idSlice[idx] = j
}
return idSlice
}
}
Expand All @@ -170,7 +170,7 @@ func escapeJSONPointer(p string) string {

// AddGPUIndexPatch returns the patch adding GPU index
func AddGPUIndexPatch(ids []int) string {
idsstring := strings.Trim(strings.Replace(fmt.Sprint(ids), " ", ",", -1), "[]")
idsstring := strings.Trim(strings.Replace(fmt.Sprint(ids), " ", ",", -1), "[]")
return fmt.Sprintf(`[{"op": "add", "path": "/metadata/annotations/%s", "value":"%d"},`+
`{"op": "add", "path": "/metadata/annotations/%s", "value": "%s"}]`,
escapeJSONPointer(PredicateTime), time.Now().UnixNano(),
Expand Down
21 changes: 10 additions & 11 deletions pkg/scheduler/plugins/predicates/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"volcano.sh/volcano/pkg/scheduler/api"
)


// checkNodeGPUSharingPredicate checks if a pod with gpu requirement can be scheduled on a node.
func checkNodeGPUSharingPredicate(pod *v1.Pod, nodeInfo *api.NodeInfo) (bool, error) {
// no gpu sharing request
Expand All @@ -42,13 +41,13 @@ func checkNodeGPUSharingPredicate(pod *v1.Pod, nodeInfo *api.NodeInfo) (bool, er
func checkNodeGPUNumberPredicate(pod *v1.Pod, nodeInfo *api.NodeInfo) (bool, error) {
//no gpu number request
if api.GetGPUNumberOfPod(pod) <= 0 {
return true, nil
return true, nil
}
ids := predicateGPUbyNumber(pod, nodeInfo)
if ids == nil{
if ids == nil {
return false, fmt.Errorf("no enough gpu number on node %s", nodeInfo.Name)
}
return true, nil
return true, nil
}

// predicateGPU returns the available GPU ID
Expand Down Expand Up @@ -79,16 +78,16 @@ func predicateGPUbyNumber(pod *v1.Pod, node *api.NodeInfo) []int {
var devIDs []int

if len(allocatableGPUs) < gpuRequest {
klog.Errorf("Not enough gpu cards")
return nil
}
klog.Errorf("Not enough gpu cards")
return nil
}

for devID := 0; devID < len(allocatableGPUs); devID++ {
devIDs = append(devIDs, allocatableGPUs[devID])
if len(devIDs) == gpuRequest{
return devIDs;
}
if len(devIDs) == gpuRequest {
return devIDs
}
}

return nil
}
}
42 changes: 21 additions & 21 deletions pkg/scheduler/plugins/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (

// GPUSharingPredicate is the key for enabling GPU Sharing Predicate in YAML
GPUSharingPredicate = "predicate.GPUSharingEnable"
GPUNumberPredicate = "predicate.GPUNumberEnable"
GPUNumberPredicate = "predicate.GPUNumberEnable"

// CachePredicate control cache predicate feature
CachePredicate = "predicate.CacheEnable"
Expand Down Expand Up @@ -123,8 +123,8 @@ func enablePredicate(args framework.Arguments) predicateEnable {
args.GetBool(&predicate.gpuSharingEnable, GPUSharingPredicate)
args.GetBool(&predicate.gpuNumberEnable, GPUNumberPredicate)

if predicate.gpuSharingEnable && predicate.gpuNumberEnable{
klog.Errorf("can not define true in both gpu sharing and gpu number")
if predicate.gpuSharingEnable && predicate.gpuNumberEnable {
klog.Errorf("can not define true in both gpu sharing and gpu number")
}

args.GetBool(&predicate.cacheEnable, CachePredicate)
Expand Down Expand Up @@ -183,7 +183,7 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) {
}

//predicate gpu sharing
if predicate.gpuSharingEnable && api.GetGPUResourceOfPod(pod) > 0 {
if predicate.gpuSharingEnable && api.GetGPUResourceOfPod(pod) > 0 {
nodeInfo, ok := ssn.Nodes[nodeName]
if !ok {
klog.Errorf("Failed to get node %s info from cache", nodeName)
Expand All @@ -201,18 +201,18 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) {
return
}
for _, id := range ids {
dev, ok := nodeInfo.GPUDevices[id]
if !ok {
klog.Errorf("Failed to get GPU %d from node %s", id, nodeName)
return
}
dev.PodMap[string(pod.UID)] = pod
dev, ok := nodeInfo.GPUDevices[id]
if !ok {
klog.Errorf("Failed to get GPU %d from node %s", id, nodeName)
return
}
dev.PodMap[string(pod.UID)] = pod
}
klog.V(4).Infof("predicates with gpu sharing, update pod %s/%s allocate to node [%s]", pod.Namespace, pod.Name, nodeName)
}

//predicate gpu number
if predicate.gpuNumberEnable && api.GetGPUNumberOfPod(pod) > 0 {
if predicate.gpuNumberEnable && api.GetGPUNumberOfPod(pod) > 0 {
nodeInfo, ok := ssn.Nodes[nodeName]
if !ok {
klog.Errorf("Failed to get node %s info from cache", nodeName)
Expand All @@ -230,12 +230,12 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) {
return
}
for _, id := range ids {
dev, ok := nodeInfo.GPUDevices[id]
if !ok {
klog.Errorf("Failed to get GPU %d from node %s", id, nodeName)
return
}
dev.PodMap[string(pod.UID)] = pod
dev, ok := nodeInfo.GPUDevices[id]
if !ok {
klog.Errorf("Failed to get GPU %d from node %s", id, nodeName)
return
}
dev.PodMap[string(pod.UID)] = pod
}
klog.V(4).Infof("predicates with gpu number, update pod %s/%s allocate to node [%s]", pod.Namespace, pod.Name, nodeName)
}
Expand Down Expand Up @@ -268,9 +268,9 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) {
return
}
for _, id := range ids {
if dev, ok := nodeInfo.GPUDevices[id]; ok {
delete(dev.PodMap, string(pod.UID))
}
if dev, ok := nodeInfo.GPUDevices[id]; ok {
delete(dev.PodMap, string(pod.UID))
}
}

klog.V(4).Infof("predicates with gpu sharing, update pod %s/%s deallocate from node [%s]", pod.Namespace, pod.Name, nodeName)
Expand Down Expand Up @@ -403,7 +403,7 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) {
if predicate.gpuNumberEnable {
//CheckGPUNumberPredicate
fit, err := checkNodeGPUNumberPredicate(task.Pod, node)
if err != nil{
if err != nil {
return err
}

Expand Down

0 comments on commit 6db3361

Please sign in to comment.