Skip to content

Commit 82a0140

Browse files
committed
make mini-ctk creator a standalone action
1 parent 791aefc commit 82a0140

File tree

5 files changed

+145
-123
lines changed

5 files changed

+145
-123
lines changed

.github/actions/build/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@ inputs:
1313
host-platform:
1414
required: true
1515
type: string
16+
cuda-version:
17+
required: true
18+
type: string
1619
upload-enabled:
1720
required: true
1821
type: boolean
1922

2023
runs:
2124
using: composite
2225
steps:
26+
- name: Set up mini CTK
27+
uses: ./.github/actions/fetch_ctk
28+
continue-on-error: false
29+
with:
30+
host-platform: ${{ inputs.host-platform }}
31+
cuda-version: ${{ inputs.cuda-version }}
32+
fail-on-ctk-cache-miss: false
33+
2334
- name: Build cuda.core wheel
2435
uses: pypa/[email protected]
2536
env:

.github/actions/fetch_ctk/action.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
fail-on-ctk-cache-miss:
13+
required: true
14+
type: boolean
15+
16+
runs:
17+
using: composite
18+
steps:
19+
- name: Set up CTK cache variable
20+
shell: bash --noprofile --norc -xeuo pipefail {0}
21+
run: |
22+
echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}" >> $GITHUB_ENV
23+
echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}.tar.gz" >> $GITHUB_ENV
24+
25+
- name: Download CTK cache
26+
id: ctk-get-cache
27+
uses: actions/cache/restore@v4
28+
continue-on-error: true
29+
with:
30+
key: ${{ env.CTK_CACHE_KEY }}
31+
path: ./${{ env.CTK_CACHE_FILENAME }}
32+
fail-on-cache-miss: ${{ inputs.fail-on-ctk-cache-miss }}
33+
34+
- name: Get CUDA components
35+
if: ${{ steps.ctk-get-cache.outputs.cache-hit != 'true' }}
36+
shell: bash --noprofile --norc -xeuo pipefail {0}
37+
run: |
38+
CUDA_PATH="$(pwd)/cuda_toolkit"
39+
mkdir $CUDA_PATH
40+
41+
# The binary archives (redist) are guaranteed to be updated as part of the release posting.
42+
CTK_BASE_URL="https://developer.download.nvidia.com/compute/cuda/redist/"
43+
CTK_JSON_URL="$CTK_BASE_URL/redistrib_${{ inputs.cuda-version }}.json"
44+
if [[ "${{ inputs.host-platform }}" == linux* ]]; then
45+
if [[ "${{ inputs.host-platform }}" == "linux-x64" ]]; then
46+
CTK_SUBDIR="linux-x86_64"
47+
elif [[ "${{ inputs.host-platform }}" == "linux-aarch64" ]]; then
48+
CTK_SUBDIR="linux-sbsa"
49+
fi
50+
function extract() {
51+
tar -xvf $1 -C $CUDA_PATH --strip-components=1
52+
}
53+
elif [[ "${{ inputs.host-platform }}" == "win-x64" ]]; then
54+
CTK_SUBDIR="windows-x86_64"
55+
function extract() {
56+
_TEMP_DIR_=$(mktemp -d)
57+
unzip $1 -d $_TEMP_DIR_
58+
cp -r $_TEMP_DIR_/*/* $CUDA_PATH
59+
rm -rf $_TEMP_DIR_
60+
}
61+
fi
62+
function populate_cuda_path() {
63+
# take the component name as a argument
64+
function download() {
65+
curl -kLSs $1 -o $2
66+
}
67+
CTK_COMPONENT=$1
68+
CTK_COMPONENT_REL_PATH="$(curl -s $CTK_JSON_URL |
69+
python -c "import sys, json; print(json.load(sys.stdin)['${CTK_COMPONENT}']['${CTK_SUBDIR}']['relative_path'])")"
70+
CTK_COMPONENT_URL="${CTK_BASE_URL}/${CTK_COMPONENT_REL_PATH}"
71+
CTK_COMPONENT_COMPONENT_FILENAME="$(basename $CTK_COMPONENT_REL_PATH)"
72+
download $CTK_COMPONENT_URL $CTK_COMPONENT_COMPONENT_FILENAME
73+
extract $CTK_COMPONENT_COMPONENT_FILENAME
74+
rm $CTK_COMPONENT_COMPONENT_FILENAME
75+
}
76+
77+
# Get headers and shared libraries in place
78+
# Note: the existing artifact would need to be manually deleted (ex: through web UI)
79+
# if this list is changed, as the artifact actions do not offer any option for us to
80+
# invalidate the artifact.
81+
populate_cuda_path cuda_nvcc
82+
populate_cuda_path cuda_cudart
83+
populate_cuda_path cuda_nvrtc
84+
populate_cuda_path cuda_profiler_api
85+
populate_cuda_path libnvjitlink
86+
ls -l $CUDA_PATH
87+
88+
# Prepare the cache
89+
# Note: try to escape | and > ...
90+
tar -czvf ${CTK_CACHE_FILENAME} ${CUDA_PATH}
91+
92+
# Note: the headers will be copied into the cibuildwheel manylinux container,
93+
# so setting the CUDA_PATH env var here is meaningless.
94+
95+
- name: Upload CTK cache
96+
if: ${{ always() &&
97+
steps.ctk-get-cache.outputs.cache-hit != 'true' }}
98+
uses: actions/cache/save@v4
99+
with:
100+
key: ${{ env.CTK_CACHE_KEY }}
101+
path: ./${{ env.CTK_CACHE_FILENAME }}
102+
103+
- name: Restore CTK cache
104+
if: ${{ steps.ctk-get-cache.outputs.cache-hit == 'true' }}
105+
shell: bash --noprofile --norc -xeuo pipefail {0}
106+
run: |
107+
ls -l
108+
CUDA_PATH="$(pwd)/cuda_toolkit"
109+
tar -xzvf $CTK_CACHE_FILENAME
110+
ls -l $CUDA_PATH
111+
if [ ! -d "$CUDA_PATH/include" ]; then
112+
exit 1
113+
fi
114+
115+
echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV
116+
echo "PATH=${PATH:-}:${CUDA_PATH}/bin" >> $GITHUB_ENV
117+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${CUDA_PATH}/lib" >> $GITHUB_ENV

.github/actions/setup/action.yml

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -47,101 +47,6 @@ runs:
4747
run: |
4848
env
4949
50-
- name: Set up CTK cache variable
51-
shell: bash --noprofile --norc -xeuo pipefail {0}
52-
run: |
53-
echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}" >> $GITHUB_ENV
54-
echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}.tar.gz" >> $GITHUB_ENV
55-
56-
- name: Download CTK cache
57-
id: ctk-get-cache
58-
uses: actions/cache/restore@v4
59-
continue-on-error: true
60-
with:
61-
key: ${{ env.CTK_CACHE_KEY }}
62-
path: ./${{ env.CTK_CACHE_FILENAME }}
63-
64-
- name: Get CUDA components
65-
if: ${{ steps.ctk-get-cache.outputs.cache-hit != 'true' }}
66-
shell: bash --noprofile --norc -xeuo pipefail {0}
67-
run: |
68-
CUDA_PATH="./cuda_toolkit"
69-
mkdir $CUDA_PATH
70-
71-
# The binary archives (redist) are guaranteed to be updated as part of the release posting.
72-
CTK_BASE_URL="https://developer.download.nvidia.com/compute/cuda/redist/"
73-
CTK_JSON_URL="$CTK_BASE_URL/redistrib_${{ inputs.cuda-version }}.json"
74-
if [[ "${{ inputs.host-platform }}" == linux* ]]; then
75-
if [[ "${{ inputs.host-platform }}" == "linux-x64" ]]; then
76-
CTK_SUBDIR="linux-x86_64"
77-
elif [[ "${{ inputs.host-platform }}" == "linux-aarch64" ]]; then
78-
CTK_SUBDIR="linux-sbsa"
79-
fi
80-
function extract() {
81-
tar -xvf $1 -C $CUDA_PATH --strip-components=1
82-
}
83-
elif [[ "${{ inputs.host-platform }}" == "win-x64" ]]; then
84-
CTK_SUBDIR="windows-x86_64"
85-
function extract() {
86-
_TEMP_DIR_=$(mktemp -d)
87-
unzip $1 -d $_TEMP_DIR_
88-
cp -r $_TEMP_DIR_/*/* $CUDA_PATH
89-
rm -rf $_TEMP_DIR_
90-
}
91-
fi
92-
function populate_cuda_path() {
93-
# take the component name as a argument
94-
function download() {
95-
curl -kLSs $1 -o $2
96-
}
97-
CTK_COMPONENT=$1
98-
CTK_COMPONENT_REL_PATH="$(curl -s $CTK_JSON_URL |
99-
python -c "import sys, json; print(json.load(sys.stdin)['${CTK_COMPONENT}']['${CTK_SUBDIR}']['relative_path'])")"
100-
CTK_COMPONENT_URL="${CTK_BASE_URL}/${CTK_COMPONENT_REL_PATH}"
101-
CTK_COMPONENT_COMPONENT_FILENAME="$(basename $CTK_COMPONENT_REL_PATH)"
102-
download $CTK_COMPONENT_URL $CTK_COMPONENT_COMPONENT_FILENAME
103-
extract $CTK_COMPONENT_COMPONENT_FILENAME
104-
rm $CTK_COMPONENT_COMPONENT_FILENAME
105-
}
106-
107-
# Get headers and shared libraries in place
108-
# Note: the existing artifact would need to be manually deleted (ex: through web UI)
109-
# if this list is changed, as the artifact actions do not offer any option for us to
110-
# invalidate the artifact.
111-
populate_cuda_path cuda_nvcc
112-
populate_cuda_path cuda_cudart
113-
populate_cuda_path cuda_nvrtc
114-
populate_cuda_path cuda_profiler_api
115-
populate_cuda_path libnvjitlink
116-
ls -l $CUDA_PATH
117-
118-
# Prepare the cache
119-
# Note: try to escape | and > ...
120-
tar -czvf ${CTK_CACHE_FILENAME} ${CUDA_PATH}
121-
122-
# Note: the headers will be copied into the cibuildwheel manylinux container,
123-
# so setting the CUDA_PATH env var here is meaningless.
124-
125-
- name: Upload CTK cache
126-
if: ${{ always() &&
127-
steps.ctk-get-cache.outputs.cache-hit != 'true' }}
128-
uses: actions/cache/save@v4
129-
with:
130-
key: ${{ env.CTK_CACHE_KEY }}
131-
path: ./${{ env.CTK_CACHE_FILENAME }}
132-
133-
- name: Restore CTK cache
134-
if: ${{ steps.ctk-get-cache.outputs.cache-hit == 'true' }}
135-
shell: bash --noprofile --norc -xeuo pipefail {0}
136-
run: |
137-
ls -l
138-
CUDA_PATH="./cuda_toolkit"
139-
tar -xzvf $CTK_CACHE_FILENAME
140-
ls -l $CUDA_PATH
141-
if [ ! -d "$CUDA_PATH/include" ]; then
142-
exit 1
143-
fi
144-
14550
- name: Set environment variables
14651
shell: bash --noprofile --norc -xeuo pipefail {0}
14752
run: |

.github/actions/test/action.yml

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: test
33
description: Run tests in specified project
44

55
inputs:
6+
host-platform:
7+
required: true
8+
type: string
9+
cuda-version:
10+
required: true
11+
type: string
612
test-options:
713
required: true
814
type: string
@@ -50,39 +56,19 @@ runs:
5056
with:
5157
python-version: ${{ env.PYTHON_VERSION }}
5258

53-
- name: Set up CTK cache variable
54-
shell: bash --noprofile --norc -xeuo pipefail {0}
55-
run: |
56-
echo "CTK_CACHE_KEY=mini-ctk-${CTK_BUILD_VER}-${HOST_PLATFORM}" >> $GITHUB_ENV
57-
echo "CTK_CACHE_FILENAME=mini-ctk-${CTK_BUILD_VER}-${HOST_PLATFORM}.tar.gz" >> $GITHUB_ENV
58-
59-
- name: Download CTK cache
60-
id: ctk-get-cache
61-
uses: actions/cache/restore@v4
62-
continue-on-error: true
59+
- name: Set up mini CTK
60+
uses: ./.github/actions/fetch_ctk
61+
continue-on-error: false
6362
with:
64-
key: ${{ env.CTK_CACHE_KEY }}
65-
path: ./${{ env.CTK_CACHE_FILENAME }}
66-
fail-on-cache-miss: true
67-
68-
- name: Restore CTK cache
69-
shell: bash --noprofile --norc -xeuo pipefail {0}
70-
run: |
71-
ls -l
72-
CUDA_PATH="$(pwd)/cuda_toolkit"
73-
tar -xzvf $CTK_CACHE_FILENAME
74-
ls -l $CUDA_PATH
75-
if [ ! -d "$CUDA_PATH/include" ]; then
76-
exit 1
77-
fi
78-
79-
echo "CUDA_PATH=$CUDA_PATH" >> $GITHUB_ENV
80-
echo "PATH=$PATH:$CUDA_PATH/bin" >> $GITHUB_ENV
81-
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_PATH/lib" >> $GITHUB_ENV
63+
host-platform: ${{ inputs.host-platform }}
64+
cuda-version: ${{ inputs.cuda-version }}
65+
fail-on-ctk-cache-miss: true
8266

8367
- name: Run test / analysis
8468
shell: bash --noprofile --norc -xeuo pipefail {0}
8569
run: |
70+
ls $CUDA_PATH
71+
8672
REPO_DIR=$(pwd)
8773
8874
cd "${CUDA_BINDINGS_ARTIFACTS_DIR}"

.github/workflows/gh-build-and-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
build-type: ${{ inputs.build-type }}
6464
target-device: "${{ inputs.target-device }}"
6565
host-platform: ${{ inputs.host-platform }}
66+
cuda-version: ${{ inputs.cuda-version }}
6667
upload-enabled: ${{ inputs.upload-enabled }}
6768

6869
- name: Pass environment variables
@@ -116,6 +117,8 @@ jobs:
116117
uses: ./.github/actions/test
117118
with:
118119
test-options: ${{ inputs.build-type }}
120+
host-platform: ${{ inputs.host-platform }}
121+
cuda-version: ${{ inputs.cuda-version }}
119122
env:
120123
CUDA_CORE_ARTIFACT_NAME: ${{ needs.build.outputs.CUDA_CORE_ARTIFACT_NAME }}
121124
CUDA_CORE_ARTIFACTS_DIR: ${{ needs.build.outputs.CUDA_CORE_ARTIFACTS_DIR }}

0 commit comments

Comments
 (0)