mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
gpu_plugin: add -shared-dev-num option
The DRM driver of Intel i915 GPUs allows sharing one device between many containers. Make it possible to use the same device from different containers. The exact number of containers sharing the same device can be limited with the new option -shared-dev-num set to 1 by default. closes #53
This commit is contained in:
parent
850ca06121
commit
40246f64ad
@ -47,14 +47,17 @@ type devicePlugin struct {
|
||||
sysfsDir string
|
||||
devfsDir string
|
||||
|
||||
sharedDevNum int
|
||||
|
||||
gpuDeviceReg *regexp.Regexp
|
||||
controlDeviceReg *regexp.Regexp
|
||||
}
|
||||
|
||||
func newDevicePlugin(sysfsDir string, devfsDir string) *devicePlugin {
|
||||
func newDevicePlugin(sysfsDir, devfsDir string, sharedDevNum int) *devicePlugin {
|
||||
return &devicePlugin{
|
||||
sysfsDir: sysfsDir,
|
||||
devfsDir: devfsDir,
|
||||
sharedDevNum: sharedDevNum,
|
||||
gpuDeviceReg: regexp.MustCompile(gpuDeviceRE),
|
||||
controlDeviceReg: regexp.MustCompile(controlDeviceRE),
|
||||
}
|
||||
@ -112,12 +115,15 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
}
|
||||
|
||||
if len(nodes) > 0 {
|
||||
// Currently only one device type (i915) is supported.
|
||||
// TODO: check model ID to differentiate device models.
|
||||
devTree.AddDevice(deviceType, f.Name(), dpapi.DeviceInfo{
|
||||
State: pluginapi.Healthy,
|
||||
Nodes: nodes,
|
||||
})
|
||||
for i := 0; i < dp.sharedDevNum; i++ {
|
||||
devID := fmt.Sprintf("%s-%d", f.Name(), i)
|
||||
// Currently only one device type (i915) is supported.
|
||||
// TODO: check model ID to differentiate device models.
|
||||
devTree.AddDevice(deviceType, devID, dpapi.DeviceInfo{
|
||||
State: pluginapi.Healthy,
|
||||
Nodes: nodes,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -127,10 +133,19 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var sharedDevNum int
|
||||
|
||||
flag.IntVar(&sharedDevNum, "shared-dev-num", 1, "number of containers sharing the same GPU device")
|
||||
flag.Parse()
|
||||
|
||||
if sharedDevNum < 1 {
|
||||
glog.Error("The number of containers sharing the same GPU must greater than zero")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
glog.Info("GPU device plugin started")
|
||||
|
||||
plugin := newDevicePlugin(sysfsDrmDirectory, devfsDriDirectory)
|
||||
plugin := newDevicePlugin(sysfsDrmDirectory, devfsDriDirectory, sharedDevNum)
|
||||
manager := dpapi.NewManager(namespace, plugin)
|
||||
manager.Run()
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func TestScan(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testPlugin := newDevicePlugin(sysfs, devfs)
|
||||
testPlugin := newDevicePlugin(sysfs, devfs, 1)
|
||||
|
||||
if testPlugin == nil {
|
||||
t.Fatal("Failed to create a deviceManager")
|
||||
|
Loading…
Reference in New Issue
Block a user