Skip to content

Commit

Permalink
[no-relnote] Remove feature flag for per-container features
Browse files Browse the repository at this point in the history
This change REMOVES the ability to set opt-in features
(e.g. GDS, MOFED, GDRCOPY) in the config file. The existing
per-container envvars are unaffected.

Signed-off-by: Evan Lezar <[email protected]>
  • Loading branch information
elezar committed Oct 16, 2024
1 parent 17f1427 commit ac6f785
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 60 deletions.
58 changes: 2 additions & 56 deletions internal/config/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,16 @@

package config

type featureName string

const (
FeatureGDS = featureName("gds")
FeatureMOFED = featureName("mofed")
FeatureNVSWITCH = featureName("nvswitch")
FeatureGDRCopy = featureName("gdrcopy")
)

// features specifies a set of named features.
type features struct {
GDS *feature `toml:"gds,omitempty"`
MOFED *feature `toml:"mofed,omitempty"`
NVSWITCH *feature `toml:"nvswitch,omitempty"`
GDRCopy *feature `toml:"gdrcopy,omitempty"`
}

type feature bool

Check failure on line 23 in internal/config/features.go

View workflow job for this annotation

GitHub Actions / check

type `feature` is unused (unused)

// IsEnabled checks whether a specified named feature is enabled.
// An optional list of environments to check for feature-specific environment
// variables can also be supplied.
func (fs features) IsEnabled(n featureName, in ...getenver) bool {
featureEnvvars := map[featureName]string{
FeatureGDS: "NVIDIA_GDS",
FeatureMOFED: "NVIDIA_MOFED",
FeatureNVSWITCH: "NVIDIA_NVSWITCH",
FeatureGDRCopy: "NVIDIA_GDRCOPY",
}

envvar := featureEnvvars[n]
switch n {
case FeatureGDS:
return fs.GDS.isEnabled(envvar, in...)
case FeatureMOFED:
return fs.MOFED.isEnabled(envvar, in...)
case FeatureNVSWITCH:
return fs.NVSWITCH.isEnabled(envvar, in...)
case FeatureGDRCopy:
return fs.GDRCopy.isEnabled(envvar, in...)
default:
return false
}
}

// isEnabled checks whether a feature is enabled.
// If the enabled value is explicitly set, this is returned, otherwise the
// associated envvar is checked in the specified getenver for the string "enabled"
// A CUDA container / image can be passed here.
func (f *feature) isEnabled(envvar string, ins ...getenver) bool {
// IsEnabled checks whether a feature is explicitly enabled.
func (f *feature) IsEnabled() bool {

Check failure on line 26 in internal/config/features.go

View workflow job for this annotation

GitHub Actions / check

func `(*feature).IsEnabled` is unused (unused)
if f != nil {
return bool(*f)
}
if envvar == "" {
return false
}
for _, in := range ins {
if in.Getenv(envvar) == "enabled" {
return true
}
}
return false
}

type getenver interface {
Getenv(string) string
}
4 changes: 4 additions & 0 deletions internal/config/image/cuda_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,7 @@ func (i CUDA) CDIDevicesFromMounts() []string {
}
return devices
}

func (i CUDA) IsEnabled(envvar string) bool {
return i.Getenv(envvar) == "enabled"
}
8 changes: 4 additions & 4 deletions internal/modifier/gated.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,31 @@ func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image
driverRoot := cfg.NVIDIAContainerCLIConfig.Root
devRoot := cfg.NVIDIAContainerCLIConfig.Root

if cfg.Features.IsEnabled(config.FeatureGDS, image) {
if image.Getenv("NVIDIA_GDS") == "enabled" {
d, err := discover.NewGDSDiscoverer(logger, driverRoot, devRoot)
if err != nil {
return nil, fmt.Errorf("failed to construct discoverer for GDS devices: %w", err)
}
discoverers = append(discoverers, d)
}

if cfg.Features.IsEnabled(config.FeatureMOFED, image) {
if image.Getenv("NVIDIA_MOFED") == "enabled" {
d, err := discover.NewMOFEDDiscoverer(logger, devRoot)
if err != nil {
return nil, fmt.Errorf("failed to construct discoverer for MOFED devices: %w", err)
}
discoverers = append(discoverers, d)
}

if cfg.Features.IsEnabled(config.FeatureNVSWITCH, image) {
if image.Getenv("NVIDIA_NVSWITCH") == "enabled" {
d, err := discover.NewNvSwitchDiscoverer(logger, devRoot)
if err != nil {
return nil, fmt.Errorf("failed to construct discoverer for NVSWITCH devices: %w", err)
}
discoverers = append(discoverers, d)
}

if cfg.Features.IsEnabled(config.FeatureGDRCopy, image) {
if image.Getenv("NVIDIA_GDRCOPY") == "enabled" {
d, err := discover.NewGDRCopyDiscoverer(logger, devRoot)
if err != nil {
return nil, fmt.Errorf("failed to construct discoverer for GDRCopy devices: %w", err)
Expand Down

0 comments on commit ac6f785

Please sign in to comment.