Skip to content

Commit

Permalink
Signed-off-by: limengxuan <[email protected]>
Browse files Browse the repository at this point in the history
Add NodeOrder to devices API

Conflicts:
	pkg/scheduler/api/shared_device_pool.go
  • Loading branch information
archlitchi committed Jul 18, 2023
1 parent f9d22d6 commit 6ca89e0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/scheduler/api/devices/nvidia/gpushare/device_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func (gs *GPUDevices) FilterNode(pod *v1.Pod) (int, string, error) {
return devices.Success, "", nil
}

func (gs *GPUDevices) ScoreNode(pod *v1.Pod) (float64, error) {
return 0, nil
}

func (gs *GPUDevices) GetStatus() string {
return ""
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/scheduler/api/devices/nvidia/vgpu/device_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (gs *GPUDevices) FilterNode(pod *v1.Pod) (int, string, error) {
return devices.Success, "", nil
}

func (gs *GPUDevices) ScoreNode(pod *v1.Pod) (float64, error) {
return 0, nil
}

func (gs *GPUDevices) GetStatus() string {
return ""
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/scheduler/api/shared_device_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Devices interface {
// that the pod can get scheduled with preemption.
// The accompanying status message should explain why the pod is unschedulable.
FilterNode(pod *v1.Pod) (int, string, error)
//ScoreNode returns the score of the current node based on this device
ScoreNode(pod *v1.Pod) (float64, error)
//Allocate action in predicate
Allocate(kubeClient kubernetes.Interface, pod *v1.Pod) error
//Release action in predicate
Expand Down
65 changes: 65 additions & 0 deletions pkg/scheduler/plugins/devicescore/devicescore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package devicescore

import (
"k8s.io/klog/v2"

"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/framework"
)

// PluginName indicates name of volcano scheduler plugin.
const PluginName = "devicescore"

type priorityPlugin struct {
// Arguments given for the plugin
pluginArguments framework.Arguments
}

// New return priority plugin
func New(arguments framework.Arguments) framework.Plugin {
return &priorityPlugin{pluginArguments: arguments}
}

func (pp *priorityPlugin) Name() string {
return PluginName
}

func (pp *priorityPlugin) OnSessionOpen(ssn *framework.Session) {
ssn.AddNodeOrderFn(pp.Name(), func(task *api.TaskInfo, node *api.NodeInfo) (float64, error) {
score := float64(0)
for _, val := range api.RegisteredDevices {
if devices, ok := node.Others[val].(api.Devices); ok {
if !devices.HasDeviceRequest(task.Pod) {
continue
}
tmp, err := devices.ScoreNode(task.Pod)
if err != nil {
klog.Warningln("scoreNode failed in predicate nodeorderFn", err.Error())
return 0, err
}
score += tmp
} else {
klog.Warningf("Devices %s assertion conversion failed, skip", val)
}
}
return score, nil
})
}

func (pp *priorityPlugin) OnSessionClose(ssn *framework.Session) {}

0 comments on commit 6ca89e0

Please sign in to comment.