|
1 | | -# frozen_string_literal: true |
2 | | - |
3 | | -# |
4 | | -# Cookbook:: aws-parallelcluster |
5 | | -# Recipe:: cuda |
6 | | -# |
7 | | -# Copyright:: 2013-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
8 | | -# |
9 | | -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the |
10 | | -# License. A copy of the License is located at |
11 | | -# |
12 | | -# http://aws.amazon.com/apache2.0/ |
13 | | -# |
14 | | -# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES |
15 | | -# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and |
16 | | -# limitations under the License. |
17 | | - |
18 | | -return unless nvidia_enabled? |
19 | | - |
20 | | -# Cuda installer from https://developer.nvidia.com/cuda-toolkit-archive |
21 | | -# Cuda installer naming: cuda_11.8.0_520.61.05_linux |
22 | | - |
23 | | -cuda_full_version = node['cluster']['nvidia']['cuda']['version'] |
24 | | -cuda_parts = cuda_full_version.split('.') |
25 | | -cuda_version = "#{cuda_parts[0]}.#{cuda_parts[1]}" |
26 | | -cuda_version_suffix = node['cluster']['nvidia']['cuda']['driver_version_suffix'] |
27 | | -cuda_samples_version = cuda_version |
28 | | -cuda_arch = arm_instance? ? 'linux_sbsa' : 'linux' |
29 | | -cuda_url = "#{node['cluster']['nvidia']['cuda']['base_url']}/cuda_#{cuda_full_version}_#{cuda_version_suffix}_#{cuda_arch}.run" |
30 | | -cuda_samples_url = "#{node['cluster']['nvidia']['cuda']['samples_base_url']}/v#{cuda_samples_version}.tar.gz" |
31 | | -tmp_cuda_run = '/tmp/cuda.run' |
32 | | -tmp_cuda_sample_archive = '/tmp/cuda-sample.tar.gz' |
33 | | - |
34 | | -# Save resolved CUDA versions to .default so InSpec/build-image tests which run during ParallelClusterTestComponent see them (mirrors Nvidia driver). |
35 | | -node.default['cluster']['nvidia']['cuda']['version'] = cuda_full_version |
36 | | -node.default['cluster']['nvidia']['cuda_samples_version'] = cuda_samples_version |
37 | | -node_attributes 'Save cuda and cuda samples versions for InSpec tests' |
38 | | - |
39 | | -# Get CUDA run file |
40 | | -remote_file tmp_cuda_run do |
41 | | - source cuda_url |
42 | | - mode '0755' |
43 | | - retries 3 |
44 | | - retry_delay 5 |
45 | | - not_if { ::File.exist?("/usr/local/cuda-#{cuda_version}") } |
46 | | -end |
47 | | - |
48 | | -# Install CUDA driver |
49 | | -bash 'cuda.run advanced' do |
50 | | - user 'root' |
51 | | - group 'root' |
52 | | - cwd '/tmp' |
53 | | - code <<-CUDA |
54 | | - set -e |
55 | | - mkdir /cuda-install |
56 | | - ./cuda.run --silent --toolkit --samples --tmpdir=/cuda-install |
57 | | - rm -rf /cuda-install |
58 | | - rm -f /tmp/cuda.run |
59 | | - CUDA |
60 | | - creates "/usr/local/cuda-#{cuda_version}" |
61 | | -end |
62 | | - |
63 | | -# Get CUDA Sample Files |
64 | | -remote_file tmp_cuda_sample_archive do |
65 | | - source cuda_samples_url |
66 | | - mode '0644' |
67 | | - retries 3 |
68 | | - retry_delay 5 |
69 | | - not_if { ::File.exist?("/usr/local/cuda-#{cuda_version}/samples") } |
70 | | -end |
71 | | - |
72 | | -# Unpack CUDA Samples |
73 | | -bash 'cuda.sample install' do |
74 | | - user 'root' |
75 | | - group 'root' |
76 | | - cwd '/tmp' |
77 | | - code <<-CUDA |
78 | | - set -e |
79 | | - tar xf "/tmp/cuda-sample.tar.gz" --directory "/usr/local/" |
80 | | - rm -f "/tmp/cuda-sample.tar.gz" |
81 | | - CUDA |
82 | | - creates "/usr/local/cuda-#{cuda_version}/samples" |
83 | | -end |
0 commit comments