@@ -177,25 +177,30 @@ func (m command) getContainerForwardCompatDir(containerRoot containerRoot, o *op
177177}
178178
179179func (m command ) useCompatLibraries (libcudaCompatPath string , hostDriverVersion string , hostCUDAVersion string ) (bool , error ) {
180- driverMajor , err := extractMajorVersion ( hostDriverVersion )
181- if err != nil {
182- return false , fmt . Errorf ( "failed to extract major version from %q: %v" , hostDriverVersion , err )
183- }
184-
185- // First check the ELF header. If this is present, we use the ELF header to
186- // determine whether the CUDA compat libraries in the container should be
187- // used.
188- cudaCompatHeader , _ := GetCUDACompatElfHeader ( libcudaCompatPath )
189- if cudaCompatHeader != nil {
190- return cudaCompatHeader . UseCompat ( driverMajor , hostCUDAVersion ) , nil
180+ // If the host CUDA version is specified, we need to inspect the ELF header
181+ // of the compat libraries in the container to determine whether these
182+ // should be used.
183+ if hostCUDAVersion != "" {
184+ cudaCompatHeader , _ := GetCUDACompatElfHeader ( libcudaCompatPath )
185+ if cudaCompatHeader != nil {
186+ return cudaCompatHeader . UseCompat ( hostCUDAVersion ), nil
187+ }
188+ // If we were unable to read the CUDA header, we do not use the compat
189+ // libraries.
190+ return false , nil
191191 }
192192
193- // If no CUDA Compat ELF header is available, and NO host driver version
194- // was specified, we don't use the CUDA compat libraries in the container.
193+ // If neither a host driver version nor a host CUDA version is specified,
194+ // we don't use the CUDA compat libraries in the container.
195195 if hostDriverVersion == "" {
196196 return false , nil
197197 }
198198
199+ driverMajor , err := extractMajorVersion (hostDriverVersion )
200+ if err != nil {
201+ return false , fmt .Errorf ("failed to extract major version from %q: %v" , hostDriverVersion , err )
202+ }
203+
199204 compatDriverVersion := strings .TrimPrefix (filepath .Base (libcudaCompatPath ), "libcuda.so." )
200205 compatMajor , err := extractMajorVersion (compatDriverVersion )
201206 if err != nil {
0 commit comments