代码拉取完成,页面将自动刷新
// Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
package main
import (
"fmt"
"log"
"strings"
"github.com/NVIDIA/nvidia-docker/src/nvidia"
"github.com/NVIDIA/nvidia-docker/src/nvml"
"golang.org/x/net/context"
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1alpha"
)
func check(err error) {
if err != nil {
log.Panicln("Fatal:", err)
}
}
func getDevices() []*pluginapi.Device {
devices, err := nvidia.LookupDevices()
check(err)
var devs []*pluginapi.Device
for _, d := range devices {
devs = append(devs, &pluginapi.Device{
ID: d.UUID,
Health: pluginapi.Healthy,
Attributes: map[string]string{
resourceName + "-memory": fmt.Sprintf("%d", *d.Memory.Global),
resourceName + "-ECC": fmt.Sprintf("%t", *d.Memory.ECC),
resourceName + "-arch": fmt.Sprintf("%s", *d.Arch),
},
})
}
return devs
}
func deviceExists(devs []*pluginapi.Device, id string) bool {
for _, d := range devs {
if d.ID == id {
return true
}
}
return false
}
func watchXIDs(ctx context.Context, devs []*pluginapi.Device, xids chan<- *pluginapi.Device) {
eventSet := nvml.NewEventSet()
defer nvml.DeleteEventSet(eventSet)
for _, d := range devs {
err := nvml.RegisterEventForDevice(eventSet, nvml.XidCriticalError, d.ID)
if err != nil && strings.HasSuffix(err.Error(), "Not Supported") {
log.Printf("Warning: GPU with UUID %s is too old to support healtchecking with error: %s. Marking it unhealthy.", d.ID)
xids <- d
continue
}
if err != nil {
log.Panicln("Fatal:", err)
}
}
for {
select {
case <-ctx.Done():
return
default:
}
e, err := nvml.WaitForEvent(eventSet, 5000)
if err != nil && e.Etype != nvml.XidCriticalError {
continue
}
// FIXME: formalize the full list and document it.
// http://docs.nvidia.com/deploy/xid-errors/index.html#topic_4
// Application errors: the GPU should still be healthy
if e.Edata == 31 || e.Edata == 43 || e.Edata == 45 {
continue
}
if e.UUID == nil || len(*e.UUID) == 0 {
// All devices are unhealthy
for _, d := range devs {
xids <- d
}
continue
}
for _, d := range devs {
if d.ID == *e.UUID {
xids <- d
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。