Skip to content

Commit 799d7ca

Browse files
authored
Merge pull request #1495 from elezar/expose-nvcdi-features
Allow CDI feature flags to be set
2 parents 503742d + c829806 commit 799d7ca

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

cmd/nvidia-device-plugin/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ func main() {
169169
Usage: "The specified IMEX channels are required",
170170
EnvVars: []string{"IMEX_REQUIRED"},
171171
},
172+
&cli.StringSliceFlag{
173+
Name: "cdi-feature-flags",
174+
Usage: "A set of feature flags to be passed to the CDI spec generation logic",
175+
EnvVars: []string{"CDI_FEATURE_FLAGS"},
176+
},
172177
}
173178
o.flags = c.Flags
174179

deployments/helm/nvidia-device-plugin/templates/daemonset-device-plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ spec:
169169
- name: NVIDIA_CDI_HOOK_PATH
170170
value: {{ .Values.cdi.nvidiaHookPath }}
171171
{{- end }}
172+
{{- if typeIs "string" .Values.cdi.featureFlags }}
173+
- name: CDI_FEATURE_FLAGS
174+
value: {{ .Values.cdi.featureFlags }}
175+
{{- end }}
172176
{{- if typeIs "bool" .Values.gdrcopyEnabled }}
173177
- name: GDRCOPY_ENABLED
174178
value: {{ .Values.gdrcopyEnabled | quote }}

deployments/helm/nvidia-device-plugin/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,6 @@ cdi:
163163
# nvidiaHookPath specifies the path to the nvidia-cdi-hook or nvidia-ctk executables on the host.
164164
# This is required to ensure that the generated CDI specification refers to the correct CDI hooks.
165165
nvidiaHookPath: null
166+
# featureFlags allows CDI feature flags to be specified for CDI specification generation.
167+
# This is specified as a comma-separated list of strings.
168+
featureFlags: null

internal/cdi/cdi.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type cdiHandler struct {
5757

5858
deviceListStrategies spec.DeviceListStrategies
5959

60+
// nvcdiFeatureFlags allows finer control over CDI spec generation.
61+
nvcdiFeatureFlags []string
62+
6063
gdsEnabled bool
6164
mofedEnabled bool
6265
gdrcopyEnabled bool
@@ -113,19 +116,26 @@ func New(infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interf
113116
return nil, err
114117
}
115118

116-
c.cdilibs = make(map[string]nvcdi.SpecGenerator)
117-
118-
c.cdilibs["gpu"], err = nvcdi.New(
119-
nvcdi.WithInfoLib(c.infolib),
120-
nvcdi.WithNvmlLib(c.nvmllib),
119+
commonOptions := []nvcdi.Option{
121120
nvcdi.WithDeviceLib(c.devicelib),
121+
nvcdi.WithDevRoot(c.devRoot),
122+
nvcdi.WithDriverRoot(c.driverRoot),
123+
nvcdi.WithFeatureFlags(c.nvcdiFeatureFlags...),
124+
nvcdi.WithInfoLib(c.infolib),
122125
nvcdi.WithLogger(c.logger),
123126
nvcdi.WithNVIDIACDIHookPath(c.nvidiaCTKPath),
124-
nvcdi.WithDriverRoot(c.driverRoot),
125-
nvcdi.WithDevRoot(c.devRoot),
126-
nvcdi.WithDeviceNamers(deviceNamer),
127+
nvcdi.WithNvmlLib(c.nvmllib),
127128
nvcdi.WithVendor(c.vendor),
128-
nvcdi.WithClass("gpu"),
129+
}
130+
131+
c.cdilibs = make(map[string]nvcdi.SpecGenerator)
132+
133+
c.cdilibs["gpu"], err = nvcdi.New(
134+
append(
135+
commonOptions,
136+
nvcdi.WithDeviceNamers(deviceNamer),
137+
nvcdi.WithClass("gpu"),
138+
)...,
129139
)
130140
if err != nil {
131141
return nil, fmt.Errorf("failed to create nvcdi library: %v", err)
@@ -147,13 +157,10 @@ func New(infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interf
147157

148158
for _, mode := range c.additionalModes {
149159
lib, err := nvcdi.New(
150-
nvcdi.WithInfoLib(c.infolib),
151-
nvcdi.WithLogger(c.logger),
152-
nvcdi.WithNVIDIACDIHookPath(c.nvidiaCTKPath),
153-
nvcdi.WithDriverRoot(c.driverRoot),
154-
nvcdi.WithDevRoot(c.devRoot),
155-
nvcdi.WithVendor(c.vendor),
156-
nvcdi.WithMode(mode),
160+
append(
161+
commonOptions,
162+
nvcdi.WithMode(mode),
163+
)...,
157164
)
158165
if err != nil {
159166
return nil, fmt.Errorf("failed to create nvcdi library: %v", err)

internal/cdi/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ import (
2424
// Option defines a function for passing options to the New() call
2525
type Option func(*cdiHandler)
2626

27+
// WithFeatureFlags provides and option to set the feature flags for the nvcdi
28+
// spec generation instance.
29+
func WithFeatureFlags(featureFlags ...string) Option {
30+
return func(c *cdiHandler) {
31+
c.nvcdiFeatureFlags = featureFlags
32+
}
33+
}
34+
2735
// WithDeviceListStrategies provides an Option to set the enabled flag used by the 'cdi' interface
2836
func WithDeviceListStrategies(deviceListStrategies spec.DeviceListStrategies) Option {
2937
return func(c *cdiHandler) {

0 commit comments

Comments
 (0)