Skip to content

Commit

Permalink
[nvidia] On Ubuntu22, install the NVIDIA driver using the gcc version…
Browse files Browse the repository at this point in the history
… used to compile the kernel.

This is required because, NVIDIA driver must be compiled with the same gcc version used by the kernel.
If this is not the case, the NVIDIA driver installation would fail a compiler version check.
On newer version of Ubuntu22.04 (kernel 6.8+), the kernel is compiled with gcc-12, however gcc-11 is installed as default version by build-essentials, making this change necessary.

Signed-off-by: Giacomo Marciani <[email protected]>
  • Loading branch information
gmarciani committed Dec 11, 2024
1 parent f3219fb commit dc3f41b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and limitations under the License.

provides :nvidia_driver, platform: 'ubuntu' do |node|
node['platform_version'].to_i >= 20
node['platform_version'].to_i == 20
end

use 'partial/_nvidia_driver_common.rb'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

# Copyright:: 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "LICENSE.txt" file accompanying this file.
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.

provides :nvidia_driver, platform: 'ubuntu' do |node|
node['platform_version'].to_i == 22
end

use 'partial/_nvidia_driver_common.rb'

def rebuild_initramfs?
true
end

def compiler_path
gcc_major_version = gcc_major_version_used_by_kernel

# If the gcc version used to compile the kernel cannot be detected,
# empty string is returned, meaning that the NVIDIA driver will be compiled
# using the system default compiler.
return "" if gcc_major_version.nil?

"CC=/usr/bin/gcc-#{gcc_major_version}"
end
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@
end

# Install driver
# TODO remove --no-cc-version-check when we can update ubuntu 22 images
bash 'nvidia.run advanced' do
user 'root'
group 'root'
cwd '/tmp'
code <<-NVIDIA
set -e
#{compiler_path} ./nvidia.run --silent --dkms --disable-nouveau --no-cc-version-check -m=#{nvidia_kernel_module}
#{compiler_path} ./nvidia.run --silent --dkms --disable-nouveau -m=#{nvidia_kernel_module}
rm -f /tmp/nvidia.run
NVIDIA
creates '/usr/bin/nvidia-smi'
Expand Down
13 changes: 13 additions & 0 deletions cookbooks/aws-parallelcluster-shared/libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,16 @@ def wait_sync_file(path)
timeout 5
end
end

def gcc_major_version_used_by_kernel
# Detects the gcc major version used to compile the kernel, e.g. 12.
# If the version cannot be detected, nil is returned.
begin
gcc_major_version = shell_out("awk '{print $8}' /proc/version | tr -d ',' | cut -d '.' -f 1").stdout.strip
rescue => error
Chef::Log.error("Cannot detect gcc version used to compile the kernel: #{error}")
return nil
end
Chef::Log.info("Detected version of gcc used to compile the kernel is: #{gcc_major_version}")
gcc_major_version
end

0 comments on commit dc3f41b

Please sign in to comment.