@@ -55,6 +55,7 @@ const (
55
55
56
56
type cliOptions struct {
57
57
preferredAllocationPolicy string
58
+ resourcePrefix string
58
59
sharedDevNum int
59
60
enableMonitoring bool
60
61
resourceManagement bool
@@ -176,7 +177,7 @@ func newDevicePlugin(sysfsDir, devfsDir string, options cliOptions) *devicePlugi
176
177
if options .resourceManagement {
177
178
var err error
178
179
179
- dp .resMan , err = rm .NewResourceManager (monitorID , namespace + "/" + deviceType )
180
+ dp .resMan , err = rm .NewResourceManager (monitorID , namespace + "/" + options . resourcePrefix + deviceType )
180
181
if err != nil {
181
182
klog .Errorf ("Failed to create resource manager: %+v" , err )
182
183
return nil
@@ -330,7 +331,8 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
330
331
}
331
332
332
333
if dp .options .enableMonitoring {
333
- klog .V (4 ).Infof ("Adding %s to GPU %s/%s" , devPath , monitorType , monitorID )
334
+ klog .V (4 ).Infof ("Adding %s to GPU resource %s%s/%s" , devPath ,
335
+ dp .options .resourcePrefix , monitorType , monitorID )
334
336
335
337
monitor = append (monitor , devSpec )
336
338
}
@@ -343,7 +345,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
343
345
devID := fmt .Sprintf ("%s-%d" , f .Name (), i )
344
346
// Currently only one device type (i915) is supported.
345
347
// TODO: check model ID to differentiate device models.
346
- devTree .AddDevice (deviceType , devID , deviceInfo )
348
+ devTree .AddDevice (dp . options . resourcePrefix + deviceType , devID , deviceInfo )
347
349
348
350
rmDevInfos [devID ] = rm .NewDeviceInfo (nodes , nil , nil )
349
351
}
@@ -352,7 +354,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
352
354
// all Intel GPUs are under single monitoring resource
353
355
if len (monitor ) > 0 {
354
356
deviceInfo := dpapi .NewDeviceInfo (pluginapi .Healthy , monitor , nil , nil , nil )
355
- devTree .AddDevice (monitorType , monitorID , deviceInfo )
357
+ devTree .AddDevice (dp . options . resourcePrefix + monitorType , monitorID , deviceInfo )
356
358
}
357
359
358
360
if dp .resMan != nil {
@@ -371,10 +373,10 @@ func (dp *devicePlugin) Allocate(request *pluginapi.AllocateRequest) (*pluginapi
371
373
}
372
374
373
375
func main () {
374
- var prefix string
376
+ var faked string
375
377
var opts cliOptions
376
378
377
- flag .StringVar (& fprefix , "fake-mode" , "" , "Prefix for devfs & sysfs paths" )
379
+ flag .StringVar (& faked , "fake-mode" , "" , "Comma separated prefix for devfs & sysfs paths + prefix for resources names " )
378
380
flag .BoolVar (& opts .enableMonitoring , "enable-monitoring" , false , "whether to enable 'i915_monitoring' (= all GPUs) resource" )
379
381
flag .BoolVar (& opts .resourceManagement , "resource-manager" , false , "fractional GPU resource management" )
380
382
flag .IntVar (& opts .sharedDevNum , "shared-dev-num" , 1 , "number of containers sharing the same GPU device" )
@@ -400,12 +402,21 @@ func main() {
400
402
klog .V (1 ).Infof ("GPU device plugin started with %s preferred allocation policy" , opts .preferredAllocationPolicy )
401
403
402
404
var sysfs , devfs string
403
- if prefix != "" {
404
- sysfs = prefix + sysfsDrmDirectory
405
- devfs = prefix + devfsDriDirectory
405
+ if faked != "" {
406
+ prefixes := strings .Split (faked , "," )
407
+ if len (prefixes ) != 2 {
408
+ klog .Fatalf ("%d commas in fake-mode option value, not one" , len (prefixes )- 1 )
409
+ }
410
+ sysfs = prefixes [0 ] + sysfsDrmDirectory
411
+ devfs = prefixes [0 ] + devfsDriDirectory
412
+ opts .resourcePrefix = prefixes [1 ]
413
+ if opts .resourceManagement && opts .resourcePrefix != "" {
414
+ klog .Warning ("Resource name prefix breaks resource management as it hard-codes their names" )
415
+ }
406
416
} else {
407
417
sysfs = sysfsDrmDirectory
408
418
devfs = devfsDriDirectory
419
+ opts .resourcePrefix = ""
409
420
}
410
421
plugin := newDevicePlugin (sysfs , devfs , opts )
411
422
manager := dpapi .NewManager (namespace , plugin )
0 commit comments