|
| 1 | +name: Fetch mini CTK |
| 2 | + |
| 3 | +description: Fetch (or create) a mini CUDA Toolkit from cache |
| 4 | + |
| 5 | +inputs: |
| 6 | + host-platform: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + cuda-version: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +runs: |
| 14 | + using: composite |
| 15 | + steps: |
| 16 | + - name: Set up CTK cache variable |
| 17 | + shell: bash --noprofile --norc -xeuo pipefail {0} |
| 18 | + run: | |
| 19 | + echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}" >> $GITHUB_ENV |
| 20 | + echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}.tar.gz" >> $GITHUB_ENV |
| 21 | +
|
| 22 | + - name: Install dependencies |
| 23 | + shell: bash --noprofile --norc -xeuo pipefail {0} |
| 24 | + run: | |
| 25 | + dependencies=(zstd curl xz-utils) |
| 26 | + dependent_exes=(zstd curl xz) |
| 27 | +
|
| 28 | + not_found=0 |
| 29 | + for dep in ${dependent_exes[@]}; do |
| 30 | + if ! (command -v curl 2>&1 >/dev/null); then |
| 31 | + not_found=1 |
| 32 | + break |
| 33 | + fi |
| 34 | + done |
| 35 | + if [[ $not_found == 0 ]]; then |
| 36 | + echo "All dependencies are found. Do nothing." |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | + if ! (command -v sudo 2>&1 >/dev/null); then |
| 40 | + if [[ $EUID == 0 ]]; then |
| 41 | + alias SUDO="" |
| 42 | + else |
| 43 | + echo "The following oprations require root access." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + else |
| 47 | + alias SUDO="sudo" |
| 48 | + fi |
| 49 | + shopt -s expand_aliases |
| 50 | + SUDO apt update |
| 51 | + SUDO apt install -y ${dependencies[@]} |
| 52 | +
|
| 53 | + - name: Download CTK cache |
| 54 | + id: ctk-get-cache |
| 55 | + uses: actions/cache/restore@v4 |
| 56 | + continue-on-error: true |
| 57 | + with: |
| 58 | + key: ${{ env.CTK_CACHE_KEY }} |
| 59 | + path: ./${{ env.CTK_CACHE_FILENAME }} |
| 60 | + fail-on-cache-miss: false |
| 61 | + |
| 62 | + - name: Get CUDA components |
| 63 | + if: ${{ steps.ctk-get-cache.outputs.cache-hit != 'true' }} |
| 64 | + shell: bash --noprofile --norc -xeuo pipefail {0} |
| 65 | + run: | |
| 66 | + CUDA_PATH="./cuda_toolkit" |
| 67 | + mkdir $CUDA_PATH |
| 68 | +
|
| 69 | + # The binary archives (redist) are guaranteed to be updated as part of the release posting. |
| 70 | + CTK_BASE_URL="https://developer.download.nvidia.com/compute/cuda/redist/" |
| 71 | + CTK_JSON_URL="$CTK_BASE_URL/redistrib_${{ inputs.cuda-version }}.json" |
| 72 | + if [[ "${{ inputs.host-platform }}" == linux* ]]; then |
| 73 | + if [[ "${{ inputs.host-platform }}" == "linux-64" ]]; then |
| 74 | + CTK_SUBDIR="linux-x86_64" |
| 75 | + elif [[ "${{ inputs.host-platform }}" == "linux-aarch64" ]]; then |
| 76 | + CTK_SUBDIR="linux-sbsa" |
| 77 | + fi |
| 78 | + function extract() { |
| 79 | + tar -xvf $1 -C $CUDA_PATH --strip-components=1 |
| 80 | + } |
| 81 | + elif [[ "${{ inputs.host-platform }}" == "win-64" ]]; then |
| 82 | + CTK_SUBDIR="windows-x86_64" |
| 83 | + function extract() { |
| 84 | + _TEMP_DIR_=$(mktemp -d) |
| 85 | + unzip $1 -d $_TEMP_DIR_ |
| 86 | + cp -r $_TEMP_DIR_/*/* $CUDA_PATH |
| 87 | + rm -rf $_TEMP_DIR_ |
| 88 | + chmod 644 $CUDA_PATH/LICENSE |
| 89 | + } |
| 90 | + fi |
| 91 | + function populate_cuda_path() { |
| 92 | + # take the component name as a argument |
| 93 | + function download() { |
| 94 | + curl -kLSs $1 -o $2 |
| 95 | + } |
| 96 | + CTK_COMPONENT=$1 |
| 97 | + CTK_COMPONENT_REL_PATH="$(curl -s $CTK_JSON_URL | |
| 98 | + python -c "import sys, json; print(json.load(sys.stdin)['${CTK_COMPONENT}']['${CTK_SUBDIR}']['relative_path'])")" |
| 99 | + CTK_COMPONENT_URL="${CTK_BASE_URL}/${CTK_COMPONENT_REL_PATH}" |
| 100 | + CTK_COMPONENT_COMPONENT_FILENAME="$(basename $CTK_COMPONENT_REL_PATH)" |
| 101 | + download $CTK_COMPONENT_URL $CTK_COMPONENT_COMPONENT_FILENAME |
| 102 | + extract $CTK_COMPONENT_COMPONENT_FILENAME |
| 103 | + rm $CTK_COMPONENT_COMPONENT_FILENAME |
| 104 | + } |
| 105 | +
|
| 106 | + # Get headers and shared libraries in place |
| 107 | + # Note: the existing artifact would need to be manually deleted (ex: through web UI) |
| 108 | + # if this list is changed, as the artifact actions do not offer any option for us to |
| 109 | + # invalidate the artifact. |
| 110 | + populate_cuda_path cuda_nvcc |
| 111 | + populate_cuda_path cuda_cudart |
| 112 | + populate_cuda_path cuda_nvrtc |
| 113 | + populate_cuda_path cuda_profiler_api |
| 114 | + populate_cuda_path cuda_cccl |
| 115 | + if [[ "$(cut -d '.' -f 1 <<< ${{ inputs.cuda-version }})" -ge 12 ]]; then |
| 116 | + populate_cuda_path libnvjitlink |
| 117 | + fi |
| 118 | + ls -l $CUDA_PATH |
| 119 | +
|
| 120 | + # Prepare the cache |
| 121 | + # Note: try to escape | and > ... |
| 122 | + tar -czvf ${CTK_CACHE_FILENAME} ${CUDA_PATH} |
| 123 | +
|
| 124 | + - name: Upload CTK cache |
| 125 | + if: ${{ always() && |
| 126 | + steps.ctk-get-cache.outputs.cache-hit != 'true' }} |
| 127 | + uses: actions/cache/save@v4 |
| 128 | + with: |
| 129 | + key: ${{ env.CTK_CACHE_KEY }} |
| 130 | + path: ./${{ env.CTK_CACHE_FILENAME }} |
| 131 | + |
| 132 | + - name: Restore CTK cache |
| 133 | + if: ${{ steps.ctk-get-cache.outputs.cache-hit == 'true' }} |
| 134 | + shell: bash --noprofile --norc -xeuo pipefail {0} |
| 135 | + run: | |
| 136 | + ls -l |
| 137 | + CUDA_PATH="./cuda_toolkit" |
| 138 | + tar -xzvf $CTK_CACHE_FILENAME |
| 139 | + ls -l $CUDA_PATH |
| 140 | + if [ ! -d "$CUDA_PATH/include" ]; then |
| 141 | + exit 1 |
| 142 | + fi |
| 143 | +
|
| 144 | + - name: Set output environment variables |
| 145 | + shell: bash --noprofile --norc -xeuo pipefail {0} |
| 146 | + run: | |
| 147 | + CUDA_PATH=$(realpath "./cuda_toolkit") |
| 148 | + echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV |
| 149 | + echo "${CUDA_PATH}/bin" >> $GITHUB_PATH |
| 150 | + echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${CUDA_PATH}/lib" >> $GITHUB_ENV |
0 commit comments