Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

move device-sharing logics from predicates to standalone devices plugin #3313

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/user-guide/how_to_use_gpu_number.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ After installed, update the scheduler configuration:
kubectl edit cm -n volcano-system volcano-scheduler-configmap
```

For volcano v1.8.2+(v1.8.2 excluded), use the following configMap

```yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: volcano-scheduler-configmap
namespace: volcano-system
data:
volcano-scheduler.conf: |
actions: "enqueue, allocate, backfill"
tiers:
- plugins:
- name: priority
- name: gang
- name: conformance
- plugins:
- name: drf
- name: deviceshare
arguments:
deviceshare.GPUNumberEnable: true # enable gpu number
- name: predicates
- name: proportion
- name: nodeorder
- name: binpack
```

For volcano v1.8.2-(v1.8.2 included), use the following configMap

```yaml
kind: ConfigMap
apiVersion: v1
Expand Down
29 changes: 29 additions & 0 deletions docs/user-guide/how_to_use_gpu_sharing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ After installed, update the scheduler configuration:
kubectl edit cm -n volcano-system volcano-scheduler-configmap
```

For volcano v1.8.2+(v1.8.2 excluded), use the following configMap

```yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: volcano-scheduler-configmap
namespace: volcano-system
data:
volcano-scheduler.conf: |
actions: "enqueue, allocate, backfill"
tiers:
- plugins:
- name: priority
- name: gang
- name: conformance
- plugins:
- name: drf
- name: deviceshare
arguments:
deviceshare.GPUSharingEnable: true # enable gpu sharing
- name: predicates
- name: proportion
- name: nodeorder
- name: binpack
```

For volcano v1.8.2-(v1.8.2 included), use the following configMap

```yaml
kind: ConfigMap
apiVersion: v1
Expand Down
27 changes: 27 additions & 0 deletions docs/user-guide/how_to_use_vgpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ After installed, update the scheduler configuration:
kubectl edit cm -n volcano-system volcano-scheduler-configmap
```

For volcano v1.8.2+(v1.8.2 excluded), use the following configMap
```yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: volcano-scheduler-configmap
namespace: volcano-system
data:
volcano-scheduler.conf: |
actions: "enqueue, allocate, backfill"
tiers:
- plugins:
- name: priority
- name: gang
- name: conformance
- plugins:
- name: drf
- name: deviceshare
arguments:
deviceshare.VGPUEnable: true # enable vgpu
- name: predicates
- name: proportion
- name: nodeorder
- name: binpack
```

For volcano v1.8.2-(v1.8.2 included), use the following configMap
```yaml
kind: ConfigMap
apiVersion: v1
Expand Down
110 changes: 110 additions & 0 deletions pkg/scheduler/plugins/deviceshare/deviceshare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2024 The Volcano 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 deviceshare

import (
"fmt"

"k8s.io/klog/v2"

"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/api/devices"
"volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/gpushare"
"volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/vgpu"
"volcano.sh/volcano/pkg/scheduler/framework"
)

// PluginName indicates name of volcano scheduler plugin.
const (
PluginName = "deviceshare"
// GPUSharingPredicate is the key for enabling GPU Sharing Predicate in YAML
GPUSharingPredicate = "deviceshare.GPUSharingEnable"
NodeLockEnable = "deviceshare.NodeLockEnable"
GPUNumberPredicate = "deviceshare.GPUNumberEnable"

VGPUEnable = "deviceshare.VGPUEnable"
)

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

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

func (dp *deviceSharePlugin) Name() string {
return PluginName
}

func enablePredicate(args framework.Arguments) {
// Checks whether predicate.GPUSharingEnable is provided or not, if given, modifies the value in predicateEnable struct.
args.GetBool(&gpushare.GpuSharingEnable, GPUSharingPredicate)
args.GetBool(&gpushare.GpuNumberEnable, GPUNumberPredicate)
args.GetBool(&gpushare.NodeLockEnable, NodeLockEnable)
args.GetBool(&vgpu.VGPUEnable, VGPUEnable)

if gpushare.GpuSharingEnable && gpushare.GpuNumberEnable {
klog.Fatal("can not define true in both gpu sharing and gpu number")
}
if (gpushare.GpuSharingEnable || gpushare.GpuNumberEnable) && vgpu.VGPUEnable {
klog.Fatal("gpu-share and vgpu can't be used together")
}
}

func (dp *deviceSharePlugin) OnSessionOpen(ssn *framework.Session) {
enablePredicate(dp.pluginArguments)
// Register event handlers to update task info in PodLister & nodeMap
ssn.AddPredicateFn(dp.Name(), func(task *api.TaskInfo, node *api.NodeInfo) ([]*api.Status, error) {
predicateStatus := make([]*api.Status, 0)
// Check PredicateWithCache
for _, val := range api.RegisteredDevices {
if dev, ok := node.Others[val].(api.Devices); ok {
if dev == nil {
predicateStatus = append(predicateStatus, &api.Status{
Code: devices.Unschedulable,
Reason: "node not initialized with device" + val,
})
return predicateStatus, fmt.Errorf("node not initialized with device %s", val)
}
code, msg, err := dev.FilterNode(task.Pod)
filterNodeStatus := &api.Status{
Code: code,
Reason: msg,
}
if err != nil {
return predicateStatus, err
}
if filterNodeStatus.Code != api.Success {
predicateStatus = append(predicateStatus, filterNodeStatus)
return predicateStatus, fmt.Errorf("plugin device filternode predicates failed %s", msg)
}
} else {
klog.Warningf("Devices %s assertion conversion failed, skip", val)
}
}

klog.V(4).Infof("checkDevices predicates Task <%s/%s> on Node <%s>: fit ",
task.Namespace, task.Name, node.Name)

return predicateStatus, nil
})
}

func (dp *deviceSharePlugin) OnSessionClose(ssn *framework.Session) {}
2 changes: 2 additions & 0 deletions pkg/scheduler/plugins/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"volcano.sh/volcano/pkg/scheduler/plugins/binpack"
"volcano.sh/volcano/pkg/scheduler/plugins/cdp"
"volcano.sh/volcano/pkg/scheduler/plugins/conformance"
"volcano.sh/volcano/pkg/scheduler/plugins/deviceshare"
"volcano.sh/volcano/pkg/scheduler/plugins/drf"
"volcano.sh/volcano/pkg/scheduler/plugins/extender"
"volcano.sh/volcano/pkg/scheduler/plugins/gang"
Expand All @@ -43,6 +44,7 @@ func init() {
// Plugins for Jobs
framework.RegisterPluginBuilder(drf.PluginName, drf.New)
framework.RegisterPluginBuilder(gang.PluginName, gang.New)
framework.RegisterPluginBuilder(deviceshare.PluginName, deviceshare.New)
framework.RegisterPluginBuilder(predicates.PluginName, predicates.New)
framework.RegisterPluginBuilder(priority.PluginName, priority.New)
framework.RegisterPluginBuilder(nodeorder.PluginName, nodeorder.New)
Expand Down
51 changes: 0 additions & 51 deletions pkg/scheduler/plugins/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone"

"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/api/devices"
"volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/gpushare"
"volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/vgpu"
"volcano.sh/volcano/pkg/scheduler/framework"
"volcano.sh/volcano/pkg/scheduler/plugins/util/k8s"
)
Expand Down Expand Up @@ -71,13 +68,6 @@ const (
// PodTopologySpreadEnable is the key for enabling Pod Topology Spread Predicates in scheduler configmap
PodTopologySpreadEnable = "predicate.PodTopologySpreadEnable"

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

VGPUEnable = "predicate.VGPUEnable"

// CachePredicate control cache predicate feature
CachePredicate = "predicate.CacheEnable"

Expand Down Expand Up @@ -176,18 +166,6 @@ func enablePredicate(args framework.Arguments) predicateEnable {
args.GetBool(&predicate.volumeZoneEnable, VolumeZoneEnable)
args.GetBool(&predicate.podTopologySpreadEnable, PodTopologySpreadEnable)

// Checks whether predicate.GPUSharingEnable is provided or not, if given, modifies the value in predicateEnable struct.
args.GetBool(&gpushare.GpuSharingEnable, GPUSharingPredicate)
args.GetBool(&gpushare.GpuNumberEnable, GPUNumberPredicate)
args.GetBool(&gpushare.NodeLockEnable, NodeLockEnable)
args.GetBool(&vgpu.VGPUEnable, VGPUEnable)

if gpushare.GpuSharingEnable && gpushare.GpuNumberEnable {
klog.Fatal("can not define true in both gpu sharing and gpu number")
}
if (gpushare.GpuSharingEnable || gpushare.GpuNumberEnable) && vgpu.VGPUEnable {
klog.Fatal("gpu-share and vgpu can't be used together")
}
args.GetBool(&predicate.cacheEnable, CachePredicate)
// Checks whether predicate.ProportionalEnable is provided or not, if given, modifies the value in predicateEnable struct.
args.GetBool(&predicate.proportionalEnable, ProportionalPredicate)
Expand Down Expand Up @@ -527,35 +505,6 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) {
}
}

for _, val := range api.RegisteredDevices {
if dev, ok := node.Others[val].(api.Devices); ok {
if dev == nil {
predicateStatus = append(predicateStatus, &api.Status{
Code: devices.Unschedulable,
Reason: "node not initialized with device" + val,
})
return predicateStatus, fmt.Errorf("node not initialized with device %s", val)
}
code, msg, err := dev.FilterNode(task.Pod)
filterNodeStatus := &api.Status{
Code: code,
Reason: msg,
}
if err != nil {
return predicateStatus, err
}
if filterNodeStatus.Code != api.Success {
predicateStatus = append(predicateStatus, filterNodeStatus)
return predicateStatus, fmt.Errorf("plugin device filternode predicates failed %s", msg)
}
} else {
klog.Warningf("Devices %s assertion conversion failed, skip", val)
}
}

klog.V(4).Infof("checkNodeGPUPredicate predicates Task <%s/%s> on Node <%s>: fit %v",
task.Namespace, task.Name, node.Name, fit)

if predicate.proportionalEnable {
// Check ProportionalPredicate
proportionalStatus, err := checkNodeResourceIsProportional(task, node, predicate.proportional)
Expand Down
Loading