Work around Ubuntu 22.04 kernel compiler version problem.

Before this CL (extraneous whitespace trimmed):

```
Verifying archive integrity... OK
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 550.90.07..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
WARNING: The nvidia-drm module will not be installed. As a result, DRM-KMS will not function with this installation of the NVIDIA driver.
ERROR: An error occurred while performing the step: "Building kernel modules". See /var/log/nvidia-installer.log for details.
ERROR: An error occurred while performing the step: "Checking to see whether the nvidia kernel module was successfully built". See /var/log/nvidia-installer.log for details.
ERROR: The nvidia kernel module was not created.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.
...
[nvidia-installer]:    warning: the compiler differs from the one used to build the kernel
[nvidia-installer]:      The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
[nvidia-installer]:      You are using:           cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
[nvidia-installer]:
[nvidia-installer]:    Warning: Compiler version check failed:
[nvidia-installer]:
[nvidia-installer]:    The major and minor number of the compiler used to
[nvidia-installer]:    compile the kernel:
[nvidia-installer]:
[nvidia-installer]:    x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38
[nvidia-installer]:
[nvidia-installer]:    does not match the compiler used here:
[nvidia-installer]:
[nvidia-installer]:    cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
[nvidia-installer]:    Copyright (C) 2021 Free Software Foundation, Inc.
[nvidia-installer]:    This is free software; see the source for copying conditions.  There is NO
[nvidia-installer]:    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[nvidia-installer]:
[nvidia-installer]:
[nvidia-installer]:    It is recommended to set the CC environment variable
[nvidia-installer]:    to the compiler that was used to compile the kernel.
[nvidia-installer]:
[nvidia-installer]:    To skip the test and silence this warning message, set
[nvidia-installer]:    the IGNORE_CC_MISMATCH environment variable to "1".
[nvidia-installer]:    However, mixing compiler versions between the kernel
[nvidia-installer]:    and kernel modules can result in subtle bugs that are
[nvidia-installer]:    difficult to diagnose.
[nvidia-installer]:
[nvidia-installer]:    *** Failed CC version check. ***
...
[nvidia-installer]:    cc: error: unrecognized command-line option '-ftrivial-auto-var-init=zero'
[nvidia-installer]:    make[4]: *** [scripts/Makefile.build:243: /tmp/selfgz40736/NVIDIA-Linux-x86_64-550.90.07/kernel/nvidia/nv.o] Error 1
```

After this CL:

```
I1025 19:39:00.337553   62025 install_driver.go:325] getOSRelease() = map[BUG_REPORT_URL:https://bugs.launchpad.net/ubuntu/ HOME_URL:https://www.ubuntu.com/ ID:ubuntu ID_LIKE:debian NAME:Ubuntu PRETTY_NAME:Ubuntu 22.04.5 LTS PRIVACY_POLICY_URL:https://www.ubuntu.com/legal/terms-and-policies/privacy-policy SUPPORT_URL:https://help.ubuntu.com/ UBUNTU_CODENAME:jammy VERSION:22.04.5 LTS (Jammy Jellyfish) VERSION_CODENAME:jammy VERSION_ID:22.04]
I1025 19:39:00.337657   62025 install_driver.go:281] Forcing gcc-12
Verifying archive integrity... OK
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 550.90.07..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
WARNING: The nvidia-drm module will not be installed. As a result, DRM-KMS will not function with this installation of the NVIDIA driver.
WARNING: nvidia-installer was forced to guess the X library path '/usr/lib' and X module path '/usr/lib/xorg/modules'; these paths were not queryable from the system.  If X fails to find the NVIDIA X driver module, please install the `pkg-config` utility and the X.Org SDK/development package for your distribution and reinstall the driver.
WARNING: This NVIDIA driver package includes Vulkan components, but no Vulkan ICD loader was detected on this system. The NVIDIA Vulkan ICD will not function without the loader. Most distributions package the Vulkan loader; try installing the "vulkan-loader", "vulkan-icd-loader", or "libvulkan1" package.

Fri Oct 25 19:42:46 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.90.07              Driver Version: 550.90.07      CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  Tesla T4                       Off |   00000000:00:04.0 Off |                    0 |
| N/A   76C    P0             31W /   70W |       1MiB /  15360MiB |      8%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
I1025 19:42:46.758261   62025 install_driver.go:125] Installation Complete!
```

PiperOrigin-RevId: 692271389
This commit is contained in:
Jamie Liu
2024-11-01 13:18:16 -07:00
committed by gVisor bot
parent e514af1bae
commit 0608f803c8
+31
View File
@@ -273,6 +273,13 @@ func installDriver(driverPath string) error {
cmd := exec.Command(driverPath, driverArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if osIsUbuntu2204() {
// As of this writing (2024), current Ubuntu 22.04 kernels are built
// with gcc-12, but Ubuntu 22.04 defaults to gcc-11, so unless we force
// the former, building the kernel driver will fail with
// `cc: error: unrecognized command-line option '-ftrivial-auto-var-init=zero'`.
cmd.Env = append(cmd.Environ(), "CC=/usr/bin/gcc-12")
}
if err := cmd.Run(); err != nil {
tryToPrintFailureLogs()
return fmt.Errorf("failed to run nvidia-install: %w out: %s", err, string(out))
@@ -307,3 +314,27 @@ func tryToPrintFailureLogs() {
fmt.Printf("[nvidia-installer]: %s\n", line)
}
}
func osIsUbuntu2204() bool {
m, err := getOSRelease()
if err != nil {
log.Warningf("Failed to determine Linux distribution: %v", err)
return false
}
return m["ID"] == "ubuntu" && m["VERSION_ID"] == "22.04"
}
func getOSRelease() (map[string]string, error) {
const path = "/etc/os-release"
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read %s: %v", path, err)
}
m := make(map[string]string)
for _, line := range strings.Split(string(data), "\n") {
if kv := strings.SplitN(line, "=", 2); len(kv) == 2 {
m[kv[0]] = strings.Trim(kv[1], "\"")
}
}
return m, nil
}