From 45b80baede205e4befe03aed367f4bdd98e8b8bf Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sun, 15 Dec 2024 06:10:52 +0000 Subject: [PATCH] make mini-ctk creator a standalone action --- .github/actions/build/action.yml | 13 ++- .github/actions/fetch_ctk/action.yml | 117 ++++++++++++++++++++++++ .github/actions/setup/action.yml | 95 ------------------- .github/actions/test/action.yml | 42 +++------ .github/workflows/gh-build-and-test.yml | 3 + 5 files changed, 146 insertions(+), 124 deletions(-) create mode 100644 .github/actions/fetch_ctk/action.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 6b90dbd5..560c0f15 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -13,6 +13,9 @@ inputs: host-platform: required: true type: string + cuda-version: + required: true + type: string upload-enabled: required: true type: boolean @@ -58,6 +61,14 @@ runs: if-no-files-found: error overwrite: 'true' + - name: Set up mini CTK + uses: ./.github/actions/fetch_ctk + continue-on-error: false + with: + host-platform: ${{ inputs.host-platform }} + cuda-version: ${{ inputs.cuda-version }} + fail-on-ctk-cache-miss: false + - name: Build cuda.bindings wheel uses: pypa/cibuildwheel@v2.22.0 env: @@ -65,7 +76,7 @@ runs: CIBW_ARCHS_LINUX: "native" CIBW_BUILD_VERBOSITY: 1 CIBW_ENVIRONMENT_LINUX: > - CUDA_PATH="$(realpath ./cuda_toolkit)" + CUDA_PATH=${{ env.CUDA_PATH }} PARALLEL_LEVEL=${{ env.PARALLEL_LEVEL }} CIBW_ENVIRONMENT_WINDOWS: > CUDA_HOME="$(cygpath -w $(realpath ./cuda_toolkit))" diff --git a/.github/actions/fetch_ctk/action.yml b/.github/actions/fetch_ctk/action.yml new file mode 100644 index 00000000..3c7f7a24 --- /dev/null +++ b/.github/actions/fetch_ctk/action.yml @@ -0,0 +1,117 @@ +name: Fetch mini CTK + +description: Fetch (or create) a mini CUDA Toolkit from cache + +inputs: + host-platform: + required: true + type: string + cuda-version: + required: true + type: string + fail-on-ctk-cache-miss: + required: true + type: boolean + +runs: + using: composite + steps: + - name: Set up CTK cache variable + shell: bash --noprofile --norc -xeuo pipefail {0} + run: | + echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}" >> $GITHUB_ENV + echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}.tar.gz" >> $GITHUB_ENV + + - name: Download CTK cache + id: ctk-get-cache + uses: actions/cache/restore@v4 + continue-on-error: true + with: + key: ${{ env.CTK_CACHE_KEY }} + path: ./${{ env.CTK_CACHE_FILENAME }} + fail-on-cache-miss: ${{ inputs.fail-on-ctk-cache-miss }} + + - name: Get CUDA components + if: ${{ steps.ctk-get-cache.outputs.cache-hit != 'true' }} + shell: bash --noprofile --norc -xeuo pipefail {0} + run: | + CUDA_PATH="$(pwd)/cuda_toolkit" + mkdir $CUDA_PATH + + # The binary archives (redist) are guaranteed to be updated as part of the release posting. + CTK_BASE_URL="https://developer.download.nvidia.com/compute/cuda/redist/" + CTK_JSON_URL="$CTK_BASE_URL/redistrib_${{ inputs.cuda-version }}.json" + if [[ "${{ inputs.host-platform }}" == linux* ]]; then + if [[ "${{ inputs.host-platform }}" == "linux-x64" ]]; then + CTK_SUBDIR="linux-x86_64" + elif [[ "${{ inputs.host-platform }}" == "linux-aarch64" ]]; then + CTK_SUBDIR="linux-sbsa" + fi + function extract() { + tar -xvf $1 -C $CUDA_PATH --strip-components=1 + } + elif [[ "${{ inputs.host-platform }}" == "win-x64" ]]; then + CTK_SUBDIR="windows-x86_64" + function extract() { + _TEMP_DIR_=$(mktemp -d) + unzip $1 -d $_TEMP_DIR_ + cp -r $_TEMP_DIR_/*/* $CUDA_PATH + rm -rf $_TEMP_DIR_ + } + fi + function populate_cuda_path() { + # take the component name as a argument + function download() { + curl -kLSs $1 -o $2 + } + CTK_COMPONENT=$1 + CTK_COMPONENT_REL_PATH="$(curl -s $CTK_JSON_URL | + python -c "import sys, json; print(json.load(sys.stdin)['${CTK_COMPONENT}']['${CTK_SUBDIR}']['relative_path'])")" + CTK_COMPONENT_URL="${CTK_BASE_URL}/${CTK_COMPONENT_REL_PATH}" + CTK_COMPONENT_COMPONENT_FILENAME="$(basename $CTK_COMPONENT_REL_PATH)" + download $CTK_COMPONENT_URL $CTK_COMPONENT_COMPONENT_FILENAME + extract $CTK_COMPONENT_COMPONENT_FILENAME + rm $CTK_COMPONENT_COMPONENT_FILENAME + } + + # Get headers and shared libraries in place + # Note: the existing artifact would need to be manually deleted (ex: through web UI) + # if this list is changed, as the artifact actions do not offer any option for us to + # invalidate the artifact. + populate_cuda_path cuda_nvcc + populate_cuda_path cuda_cudart + populate_cuda_path cuda_nvrtc + populate_cuda_path cuda_profiler_api + populate_cuda_path libnvjitlink + ls -l $CUDA_PATH + + # Prepare the cache + # Note: try to escape | and > ... + tar -czvf ${CTK_CACHE_FILENAME} ${CUDA_PATH} + + # Note: the headers will be copied into the cibuildwheel manylinux container, + # so setting the CUDA_PATH env var here is meaningless. + + - name: Upload CTK cache + if: ${{ always() && + steps.ctk-get-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@v4 + with: + key: ${{ env.CTK_CACHE_KEY }} + path: ./${{ env.CTK_CACHE_FILENAME }} + + - name: Restore CTK cache + if: ${{ steps.ctk-get-cache.outputs.cache-hit == 'true' }} + shell: bash --noprofile --norc -xeuo pipefail {0} + run: | + ls -l + CUDA_PATH="$(pwd)/cuda_toolkit" + tar -xzvf $CTK_CACHE_FILENAME + ls -l $CUDA_PATH + if [ ! -d "$CUDA_PATH/include" ]; then + exit 1 + fi + + echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV + echo "PATH=${PATH:-}:${CUDA_PATH}/bin" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${CUDA_PATH}/lib" >> $GITHUB_ENV diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 084f4c2f..9eddec5f 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -47,101 +47,6 @@ runs: run: | env - - name: Set up CTK cache variable - shell: bash --noprofile --norc -xeuo pipefail {0} - run: | - echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}" >> $GITHUB_ENV - echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}.tar.gz" >> $GITHUB_ENV - - - name: Download CTK cache - id: ctk-get-cache - uses: actions/cache/restore@v4 - continue-on-error: true - with: - key: ${{ env.CTK_CACHE_KEY }} - path: ./${{ env.CTK_CACHE_FILENAME }} - - - name: Get CUDA components - if: ${{ steps.ctk-get-cache.outputs.cache-hit != 'true' }} - shell: bash --noprofile --norc -xeuo pipefail {0} - run: | - CUDA_PATH="./cuda_toolkit" - mkdir $CUDA_PATH - - # The binary archives (redist) are guaranteed to be updated as part of the release posting. - CTK_BASE_URL="https://developer.download.nvidia.com/compute/cuda/redist/" - CTK_JSON_URL="$CTK_BASE_URL/redistrib_${{ inputs.cuda-version }}.json" - if [[ "${{ inputs.host-platform }}" == linux* ]]; then - if [[ "${{ inputs.host-platform }}" == "linux-x64" ]]; then - CTK_SUBDIR="linux-x86_64" - elif [[ "${{ inputs.host-platform }}" == "linux-aarch64" ]]; then - CTK_SUBDIR="linux-sbsa" - fi - function extract() { - tar -xvf $1 -C $CUDA_PATH --strip-components=1 - } - elif [[ "${{ inputs.host-platform }}" == "win-x64" ]]; then - CTK_SUBDIR="windows-x86_64" - function extract() { - _TEMP_DIR_=$(mktemp -d) - unzip $1 -d $_TEMP_DIR_ - cp -r $_TEMP_DIR_/*/* $CUDA_PATH - rm -rf $_TEMP_DIR_ - } - fi - function populate_cuda_path() { - # take the component name as a argument - function download() { - curl -kLSs $1 -o $2 - } - CTK_COMPONENT=$1 - CTK_COMPONENT_REL_PATH="$(curl -s $CTK_JSON_URL | - python -c "import sys, json; print(json.load(sys.stdin)['${CTK_COMPONENT}']['${CTK_SUBDIR}']['relative_path'])")" - CTK_COMPONENT_URL="${CTK_BASE_URL}/${CTK_COMPONENT_REL_PATH}" - CTK_COMPONENT_COMPONENT_FILENAME="$(basename $CTK_COMPONENT_REL_PATH)" - download $CTK_COMPONENT_URL $CTK_COMPONENT_COMPONENT_FILENAME - extract $CTK_COMPONENT_COMPONENT_FILENAME - rm $CTK_COMPONENT_COMPONENT_FILENAME - } - - # Get headers and shared libraries in place - # Note: the existing artifact would need to be manually deleted (ex: through web UI) - # if this list is changed, as the artifact actions do not offer any option for us to - # invalidate the artifact. - populate_cuda_path cuda_nvcc - populate_cuda_path cuda_cudart - populate_cuda_path cuda_nvrtc - populate_cuda_path cuda_profiler_api - populate_cuda_path libnvjitlink - ls -l $CUDA_PATH - - # Prepare the cache - # Note: try to escape | and > ... - tar -czvf ${CTK_CACHE_FILENAME} ${CUDA_PATH} - - # Note: the headers will be copied into the cibuildwheel manylinux container, - # so setting the CUDA_PATH env var here is meaningless. - - - name: Upload CTK cache - if: ${{ always() && - steps.ctk-get-cache.outputs.cache-hit != 'true' }} - uses: actions/cache/save@v4 - with: - key: ${{ env.CTK_CACHE_KEY }} - path: ./${{ env.CTK_CACHE_FILENAME }} - - - name: Restore CTK cache - if: ${{ steps.ctk-get-cache.outputs.cache-hit == 'true' }} - shell: bash --noprofile --norc -xeuo pipefail {0} - run: | - ls -l - CUDA_PATH="./cuda_toolkit" - tar -xzvf $CTK_CACHE_FILENAME - ls -l $CUDA_PATH - if [ ! -d "$CUDA_PATH/include" ]; then - exit 1 - fi - - name: Set environment variables shell: bash --noprofile --norc -xeuo pipefail {0} run: | diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 079dd039..d8748f7e 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -3,6 +3,12 @@ name: test description: Run tests in specified project inputs: + host-platform: + required: true + type: string + cuda-version: + required: true + type: string test-options: required: true type: string @@ -50,39 +56,19 @@ runs: with: python-version: ${{ env.PYTHON_VERSION }} - - name: Set up CTK cache variable - shell: bash --noprofile --norc -xeuo pipefail {0} - run: | - echo "CTK_CACHE_KEY=mini-ctk-${CTK_BUILD_VER}-${HOST_PLATFORM}" >> $GITHUB_ENV - echo "CTK_CACHE_FILENAME=mini-ctk-${CTK_BUILD_VER}-${HOST_PLATFORM}.tar.gz" >> $GITHUB_ENV - - - name: Download CTK cache - id: ctk-get-cache - uses: actions/cache/restore@v4 - continue-on-error: true + - name: Set up mini CTK + uses: ./.github/actions/fetch_ctk + continue-on-error: false with: - key: ${{ env.CTK_CACHE_KEY }} - path: ./${{ env.CTK_CACHE_FILENAME }} - fail-on-cache-miss: true - - - name: Restore CTK cache - shell: bash --noprofile --norc -xeuo pipefail {0} - run: | - ls -l - CUDA_PATH="$(pwd)/cuda_toolkit" - tar -xzvf $CTK_CACHE_FILENAME - ls -l $CUDA_PATH - if [ ! -d "$CUDA_PATH/include" ]; then - exit 1 - fi - - echo "CUDA_PATH=$CUDA_PATH" >> $GITHUB_ENV - echo "PATH=$PATH:$CUDA_PATH/bin" >> $GITHUB_ENV - echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_PATH/lib" >> $GITHUB_ENV + host-platform: ${{ inputs.host-platform }} + cuda-version: ${{ inputs.cuda-version }} + fail-on-ctk-cache-miss: true - name: Run test / analysis shell: bash --noprofile --norc -xeuo pipefail {0} run: | + ls $CUDA_PATH + REPO_DIR=$(pwd) cd "${CUDA_BINDINGS_ARTIFACTS_DIR}" diff --git a/.github/workflows/gh-build-and-test.yml b/.github/workflows/gh-build-and-test.yml index e92d1371..db19dbc5 100644 --- a/.github/workflows/gh-build-and-test.yml +++ b/.github/workflows/gh-build-and-test.yml @@ -63,6 +63,7 @@ jobs: build-type: ${{ inputs.build-type }} target-device: "${{ inputs.target-device }}" host-platform: ${{ inputs.host-platform }} + cuda-version: ${{ inputs.cuda-version }} upload-enabled: ${{ inputs.upload-enabled }} - name: Pass environment variables @@ -116,6 +117,8 @@ jobs: uses: ./.github/actions/test with: test-options: ${{ inputs.build-type }} + host-platform: ${{ inputs.host-platform }} + cuda-version: ${{ inputs.cuda-version }} env: CUDA_CORE_ARTIFACT_NAME: ${{ needs.build.outputs.CUDA_CORE_ARTIFACT_NAME }} CUDA_CORE_ARTIFACTS_DIR: ${{ needs.build.outputs.CUDA_CORE_ARTIFACTS_DIR }}