func GetDevices() ([]*pluginapi.Device, map[uint]string) {
	n, err := nvml.GetDeviceCount()
	check(err)
	var virtualDevs []*pluginapi.Device
	deviceByIndex := map[uint]string{}
	for i := uint(0); i < n; i++ {
		d, err := nvml.NewDevice(i)
		check(err)
		var id uint
		_, err = fmt.Sscanf(d.Path, "/dev/nvidia%d", &id)
		check(err)
		deviceByIndex[id] = d.UUID
		if GetGPUMemory() == uint(0) {
			SetGPUMemory(uint(*d.Memory))
		}
		for j := uint(0); j < GetGPUMemory(); j++ {
			fakeID := GenerateVirtualDeviceID(id, j)
			virtualDevs = append(virtualDevs, &pluginapi.Device{
				ID:     fakeID,
				Health: pluginapi.Healthy,
			})
		}
	}
	return virtualDevs, deviceByIndex
}
GetDevices returns virtual devices and all physical devices by index.
package nvidia
import (
	"context"
	"fmt"
	"math"
	"strconv"
	"strings"
	"github.com/NVIDIA/gpu-monitoring-tools/bindings/go/nvml"
	"github.com/prometheus/common/log"
	v1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/klog"
	pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)
func IsGPURequiredContainer(c *v1.Container) bool {
	vmemory := GetGPUResourceOfContainer(c)
	if vmemory == 0 {
		return false
	}
	return true
}
func GetGPUResourceOfContainer(container *v1.Container) uint {
	var count uint
	if val, ok := container.Resources.Limits[VolcanoGPUResource]; ok {
		count = uint(val.Value())
	}
	return count
}
var (
	gpuMemory uint
)
func GenerateVirtualDeviceID(id uint, fakeCounter uint) string {
	return fmt.Sprintf("%d-%d", id, fakeCounter)
}
func SetGPUMemory(raw uint) {
	v := raw
	gpuMemory = v
	log.Infof("set gpu memory: %d", gpuMemory)
}
func GetGPUMemory() uint {
	return gpuMemory
}