@@ -56,6 +56,8 @@ type nvcdilib struct {
5656
5757 mergedDeviceOptions []transform.MergedDeviceOption
5858
59+ featureFlags map [FeatureFlag ]bool
60+
5961 disabledHooks disabledHooks
6062 hookCreator discover.HookCreator
6163}
@@ -64,6 +66,7 @@ type nvcdilib struct {
6466func New (opts ... Option ) (Interface , error ) {
6567 l := & nvcdilib {
6668 disabledHooks : make (disabledHooks ),
69+ featureFlags : make (map [FeatureFlag ]bool ),
6770 }
6871 for _ , opt := range opts {
6972 opt (l )
@@ -108,24 +111,7 @@ func New(opts ...Option) (Interface, error) {
108111 }
109112 l .nvmllib = nvml .New (nvmlOpts ... )
110113 }
111- // TODO: Repeated calls to nvsandboxutils.Init and Shutdown are causing
112- // segmentation violations. Here we disabled nvsandbox utils unless explicitly
113- // specified.
114- // This will be reenabled as soon as we have more visibility into why this is
115- // happening and a mechanism to detect and disable this if required.
116- // if l.nvsandboxutilslib == nil {
117- // var nvsandboxutilsOpts []nvsandboxutils.LibraryOption
118- // // Set the library path for libnvidia-sandboxutils
119- // candidates, err := l.driver.Libraries().Locate("libnvidia-sandboxutils.so.1")
120- // if err != nil {
121- // l.logger.Warningf("Ignoring error in locating libnvidia-sandboxutils.so.1: %v", err)
122- // } else {
123- // libNvidiaSandboxutilsPath := candidates[0]
124- // l.logger.Infof("Using %v", libNvidiaSandboxutilsPath)
125- // nvsandboxutilsOpts = append(nvsandboxutilsOpts, nvsandboxutils.WithLibraryPath(libNvidiaSandboxutilsPath))
126- // }
127- // l.nvsandboxutilslib = nvsandboxutils.New(nvsandboxutilsOpts...)
128- // }
114+ l .nvsandboxutilslib = l .getNvsandboxUtilsLib ()
129115 if l .devicelib == nil {
130116 l .devicelib = device .New (l .nvmllib )
131117 }
@@ -231,3 +217,26 @@ func (l *nvcdilib) getCudaVersionNvsandboxutils() (string, error) {
231217 }
232218 return version , nil
233219}
220+
221+ // getNvsandboxUtilsLib returns the nvsandboxutilslib to use for CDI spec
222+ // generation.
223+ func (l * nvcdilib ) getNvsandboxUtilsLib () nvsandboxutils.Interface {
224+ if l .featureFlags [FeatureDisableNvsandboxUtils ] {
225+ return nil
226+ }
227+ if l .nvsandboxutilslib != nil {
228+ return l .nvsandboxutilslib
229+ }
230+
231+ var nvsandboxutilsOpts []nvsandboxutils.LibraryOption
232+ // Set the library path for libnvidia-sandboxutils
233+ candidates , err := l .driver .Libraries ().Locate ("libnvidia-sandboxutils.so.1" )
234+ if err != nil {
235+ l .logger .Warningf ("Ignoring error in locating libnvidia-sandboxutils.so.1: %v" , err )
236+ } else {
237+ libNvidiaSandboxutilsPath := candidates [0 ]
238+ l .logger .Infof ("Using %v" , libNvidiaSandboxutilsPath )
239+ nvsandboxutilsOpts = append (nvsandboxutilsOpts , nvsandboxutils .WithLibraryPath (libNvidiaSandboxutilsPath ))
240+ }
241+ return nvsandboxutils .New (nvsandboxutilsOpts ... )
242+ }
0 commit comments