-
Notifications
You must be signed in to change notification settings - Fork 442
[STF] Add python bindings #5315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 250 commits
1457893
cf7753f
1f80e6a
1e29a51
fb5dddf
76c7bae
9e95107
8fe3c16
c9cee96
224eba1
3cbbdd5
f3ef1cd
34e7139
21ae4ec
e19673d
be2552b
3c77d25
0dc2d03
cbbcc2f
cb05626
49ddbe9
cab9f71
64d5848
486ca13
6ed1987
bb67603
7f72b99
dab73bd
11b8b8b
c0fd7d7
d547abc
3993bf4
689c531
93ecafd
17a2bf7
faf493b
c283065
829268f
6e857a9
2ae0272
7c5b72f
32ddf6d
d484e62
817bb50
947d0d2
f8b7fdd
5691af8
5f97c52
1e7c033
b3e6867
81ca39a
4492a10
e6965a9
4f2fb3c
04ec9ad
160396c
66aba5b
c71b509
98e3af5
c1f3eed
55f34c9
fae0627
9a54c5a
ee49ef6
0b5262d
cd232da
b5939a5
243062a
4459823
87ce7c8
438acb7
4e91f5d
12b4129
551d760
08ce080
2d00b94
2b6d021
cec4ac4
209e1f6
c4de5c5
ce80f97
327bc18
4e1d024
35c405d
e3c3316
ded36ad
545179b
14d7f81
f241555
364fee9
3fd17d3
0e014b7
ad7bb2e
b470925
294b486
8ea81e9
efbcad3
edb3c43
e42c596
efc47ce
89dc425
01f0bf4
10568d5
4fa8dc7
f353320
29ba25d
d96ced9
eb87418
d08b214
035a30a
6110331
49df167
a07cae1
bbddedc
dbee3d8
e65d392
849f388
a1575f5
6928491
eea8693
572eff3
6207eb7
1aee7be
10b4fb2
c238595
56818a9
908f59b
ca3c399
c71fa7e
13d88ee
75b2a8c
836a023
cd0f0c0
6f0ecf9
eabf767
2a15440
9af49af
3342fd1
a89c8b1
07d55cf
8d6cc27
685ab5b
82d20ce
c893ca9
37c960c
8c05e60
f18ac6c
40540d5
677c381
20f730b
384102b
5f3e210
59d8620
4b066f7
bd825ea
076fe32
e32d9f3
3fa91d2
50188fb
82194f3
687aefb
16ebcd5
2da1c87
d74bdd9
659a8e3
980a2e8
34188f6
44f8384
308ccc7
f6bba0c
b06e62d
4600142
ade7c92
e892da6
05d90f0
4f93f06
b48b384
7a729d6
1a08dde
bf1d107
e4d533d
0f40e7a
a4917ad
8cdae5e
f568c81
f2670d6
21d2ea7
5724d1a
11f2e8a
4c3c49d
9529906
5eddfed
de030ef
649efcf
e8aa706
6402287
6191f45
bf3f3cd
ee08ce0
2bf929e
60f9329
cd181aa
9a015d4
3f46ed3
3862573
a0bfbf7
f0f5504
79f8817
be563bf
b19c931
9a78a9f
82c264f
8ceb5bb
77b1239
9ee10c4
f136e94
c5add2b
5e2f4d5
8eca120
d10c312
dd39a9b
a773057
13ef970
f101d43
accc384
407e646
b9b1254
be61301
1b291c4
126896b
f32ff62
0bbdd60
1a7d3a4
2f41158
4610a32
e739557
61e7d3f
93918dc
cbceed3
b8ea935
23d1b57
9ef5687
64db026
3e8b3fa
a4032b0
8dc1432
4e3d6f4
60cd8e5
de7befe
c0b8626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Combined producer for the cuda.stf._experimental test lane. | ||
| # | ||
| # cuda-stf tests must run against the *current branch's* cuda-cccl as well as | ||
| # the current branch's cuda-stf. The workflow model lets a consumer job depend | ||
| # on only a single producer, so this one producer builds and uploads BOTH | ||
| # wheels under distinct artifact names (via get_wheel_artifact_name.sh): | ||
| # | ||
| # * cuda-cccl -> wheel-cccl-stf-<os>-<arch>-py<ver> (CCCL_WHEEL_KIND=cccl-stf) | ||
| # * cuda-stf -> wheel-stf-<os>-<arch>-py<ver> (CCCL_WHEEL_KIND=stf) | ||
| # | ||
| # The cuda-cccl wheel uses the dedicated 'cccl-stf' kind so it does NOT collide | ||
| # with the 'wheel-cccl-...' artifact produced by the regular build_py_wheel job | ||
| # (which also runs in project 'python' with the same py/os/arch). | ||
| # | ||
| # ci/test_cuda_stf_python.sh then downloads and installs both local wheels in a | ||
| # single resolver invocation. Build cuda-cccl first: the cuda-stf build leaves | ||
| # any co-located cuda_cccl wheel in wheelhouse/ untouched. | ||
|
|
||
| ci_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| usage="Usage: $0 -py-version <python_version> [additional options...]" | ||
|
|
||
| # shellcheck source=ci/util/python/common_arg_parser.sh | ||
| source "$ci_dir/util/python/common_arg_parser.sh" | ||
| parse_python_args "$@" | ||
| require_py_version "$usage" || exit 1 | ||
|
|
||
| echo "::group::⚒️ Building current-branch cuda-cccl wheel" | ||
| CCCL_WHEEL_KIND=cccl-stf "$ci_dir/build_cuda_cccl_python.sh" "$@" | ||
| echo "::endgroup::" | ||
|
|
||
| echo "::group::⚒️ Building current-branch cuda-stf wheel" | ||
| "$ci_dir/build_cuda_stf_python.sh" "$@" | ||
| echo "::endgroup::" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| ci_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| usage="Usage: $0 -py-version <python_version> [additional options...]" | ||
|
|
||
| # shellcheck source=ci/util/python/common_arg_parser.sh | ||
| source "$ci_dir/util/python/common_arg_parser.sh" | ||
| parse_python_args "$@" | ||
|
|
||
| # Check if py_version was provided (this script requires it) | ||
| require_py_version "$usage" || exit 1 | ||
|
|
||
| echo "Docker socket: " "$(ls /var/run/docker.sock)" | ||
|
|
||
| if [[ -n "${GITHUB_ACTIONS:-}" ]]; then | ||
| # Prepare mount points etc for getting artifacts in/out of the container. | ||
| # shellcheck source=ci/util/artifacts/common.sh | ||
| source "$ci_dir/util/artifacts/common.sh" | ||
| # Note that these mounts use the runner (not the devcontainer) filesystem for | ||
| # source directories because of docker-out-of-docker quirks. | ||
| # The workflow-job GH actions make sure that they exist before running any | ||
| # scripts. | ||
| action_mounts=( | ||
| --mount "type=bind,source=${ARTIFACT_ARCHIVES},target=${ARTIFACT_ARCHIVES}" | ||
| --mount "type=bind,source=${ARTIFACT_UPLOAD_STAGE},target=${ARTIFACT_UPLOAD_STAGE}" | ||
| ) | ||
| else | ||
| # If not running in GitHub Actions, we don't need to set up artifact mounts. | ||
| action_mounts=() | ||
| fi | ||
|
|
||
| # cuda_stf must be built in a container that can produce manylinux wheels, and | ||
| # has the CUDA toolkit installed. We use the rapidsai/ci-wheel image for this. | ||
| # We build separate wheels using separate containers for each CUDA version, | ||
| # then merge them into a single wheel. CUDASTF is Linux-only. | ||
|
|
||
| readonly cuda12_version=12.9.1 | ||
| readonly cuda13_version=13.1.1 | ||
| readonly devcontainer_version=26.04 | ||
| readonly devcontainer_distro=rockylinux8 | ||
| # Use a baseline Python tag for the rapidsai ci-wheel image. The requested | ||
| # py_version is installed inside the container by setup_python_env (uv). | ||
| readonly devcontainer_python_version=3.10 | ||
|
|
||
| if [[ "$(uname -m)" == "aarch64" ]]; then | ||
| cuda12_image="rapidsai/ci-wheel:${devcontainer_version}-cuda${cuda12_version}-${devcontainer_distro}-py${devcontainer_python_version}-arm64" | ||
| cuda13_image="rapidsai/ci-wheel:${devcontainer_version}-cuda${cuda13_version}-${devcontainer_distro}-py${devcontainer_python_version}-arm64" | ||
| else | ||
| cuda12_image="rapidsai/ci-wheel:${devcontainer_version}-cuda${cuda12_version}-${devcontainer_distro}-py${devcontainer_python_version}" | ||
| cuda13_image="rapidsai/ci-wheel:${devcontainer_version}-cuda${cuda13_version}-${devcontainer_distro}-py${devcontainer_python_version}" | ||
| fi | ||
| # shellcheck disable=SC2034 | ||
| readonly cuda12_image | ||
| # shellcheck disable=SC2034 | ||
| readonly cuda13_image | ||
|
|
||
| mkdir -p wheelhouse | ||
|
|
||
| # Clear stale STF wheels from a previous run so the per-CTK wheel selection | ||
| # below is unambiguous. Leave any co-located wheels (e.g. a cuda_cccl wheel | ||
| # staged by a combined producer job) untouched. | ||
| rm -f wheelhouse/cuda_stf-*.whl | ||
|
Comment on lines
+59
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win important: remove stale Sources: Path instructions, Learnings |
||
|
|
||
| # Shared caches across the cu12 + cu13 wheel builds. Both jobs compile an | ||
| # identical LLVM/clang tree (LLVM has no CUDA dep), so a shared ccache cuts | ||
| # the second build's LLVM phase substantially; a shared CPM source cache skips | ||
| # the second LLVM git clone entirely. | ||
| mkdir -p ./.ccache ./.cpm-cache | ||
| host_ccache_dir="${HOST_WORKSPACE:?}/.ccache" | ||
| host_cpm_cache_dir="${HOST_WORKSPACE:?}/.cpm-cache" | ||
|
|
||
| for ctk in 12 13; do | ||
| image="cuda${ctk}_image" | ||
| image="${!image}" | ||
| echo "::group::⚒️ Building CUDA $ctk cuda-stf wheel on $image" | ||
| ( | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| set -x | ||
| docker pull "$image" | ||
| docker run --rm -i \ | ||
| --workdir /workspace/python/cuda_stf \ | ||
| --mount "type=bind,source=${HOST_WORKSPACE:?},target=/workspace/" \ | ||
| --mount "type=bind,source=${host_ccache_dir},target=/root/.ccache" \ | ||
| --mount "type=bind,source=${host_cpm_cache_dir},target=/root/.cpm-cache" \ | ||
| "${action_mounts[@]}" \ | ||
| --env "py_version=${py_version}" \ | ||
| --env "GITHUB_ACTIONS=${GITHUB_ACTIONS:-}" \ | ||
| --env "GITHUB_RUN_ID=${GITHUB_RUN_ID:-}" \ | ||
| --env "JOB_ID=${JOB_ID:-}" \ | ||
| --env "CCACHE_DIR=/root/.ccache" \ | ||
| --env "CPM_SOURCE_CACHE=/root/.cpm-cache" \ | ||
| "$image" \ | ||
| /workspace/ci/build_cuda_stf_wheel.sh | ||
| # Prevent GHA runners from exhausting available storage with leftover images: | ||
| if [[ -n "${GITHUB_ACTIONS:-}" ]]; then | ||
| docker rmi -f "$image" | ||
| fi | ||
| ) | ||
| echo "::endgroup::" | ||
| done | ||
|
|
||
| echo "Merging CUDA wheels..." | ||
|
|
||
| # Set up a Python environment for the merge/repair steps. | ||
| source "$ci_dir/pyenv_helper.sh" | ||
| setup_python_env "${py_version}" | ||
|
|
||
| # Needed for unpacking and repacking wheels. | ||
| python -m pip install wheel | ||
|
|
||
| # Find the built wheels, requiring exactly one match per CUDA version so a | ||
| # stale or duplicate wheel cannot be silently merged. | ||
| require_single_wheel() { | ||
| local pattern="$1" desc="$2" | ||
| local matches=() | ||
| while IFS= read -r match; do | ||
| matches+=("$match") | ||
| done < <(find wheelhouse -maxdepth 1 -name "$pattern" | sort) | ||
| if [[ ${#matches[@]} -eq 0 ]]; then | ||
| echo "Error: no $desc cuda-stf wheel found in wheelhouse/ (pattern: $pattern)" >&2 | ||
| ls -la wheelhouse/ >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ${#matches[@]} -gt 1 ]]; then | ||
| echo "Error: expected exactly one $desc cuda-stf wheel, found ${#matches[@]}:" >&2 | ||
| printf ' %s\n' "${matches[@]}" >&2 | ||
| exit 1 | ||
| fi | ||
| printf '%s\n' "${matches[0]}" | ||
| } | ||
|
|
||
| cu12_wheel="$(require_single_wheel 'cuda_stf-*cu12*.whl' 'CUDA 12')" | ||
| cu13_wheel="$(require_single_wheel 'cuda_stf-*cu13*.whl' 'CUDA 13')" | ||
|
|
||
| echo "Found CUDA 12 wheel: $cu12_wheel" | ||
| echo "Found CUDA 13 wheel: $cu13_wheel" | ||
|
|
||
| # Merge the wheels | ||
| python python/cuda_stf/merge_cuda_wheels.py "$cu12_wheel" "$cu13_wheel" --output-dir wheelhouse_merged | ||
|
|
||
| # Install auditwheel and repair the merged wheel | ||
| python -m pip install patchelf auditwheel | ||
| for wheel in wheelhouse_merged/cuda_stf-*.whl; do | ||
| echo "Repairing merged wheel: $wheel" | ||
| python -m auditwheel repair \ | ||
| --exclude 'libnvrtc.so.12' \ | ||
| --exclude 'libnvrtc.so.13' \ | ||
| --exclude 'libnvJitLink.so.12' \ | ||
| --exclude 'libnvJitLink.so.13' \ | ||
| --exclude 'libcudart.so.12' \ | ||
| --exclude 'libcudart.so.13' \ | ||
| --exclude 'libcuda.so.1' \ | ||
| "$wheel" \ | ||
| --wheel-dir wheelhouse_final | ||
| done | ||
|
|
||
| # Drop only the per-CTK STF inputs we just merged; keep any unrelated wheels | ||
| # (e.g. a co-located cuda_cccl wheel) intact. | ||
| rm -f "$cu12_wheel" "$cu13_wheel" | ||
| mkdir -p wheelhouse | ||
|
|
||
| # Move only the final repaired merged wheel | ||
| if ls wheelhouse_final/cuda_stf-*.whl 1> /dev/null 2>&1; then | ||
| mv wheelhouse_final/cuda_stf-*.whl wheelhouse/ | ||
| echo "Final merged wheel moved to wheelhouse" | ||
| else | ||
| echo "No final repaired wheel found, moving unrepaired merged wheel" | ||
| mv wheelhouse_merged/cuda_stf-*.whl wheelhouse/ | ||
| fi | ||
|
|
||
| # Clean up temporary directories | ||
| rm -rf wheelhouse_merged wheelhouse_final | ||
|
|
||
| echo "Final wheels in wheelhouse:" | ||
| ls -la wheelhouse/ | ||
|
|
||
| if [[ -n "${GITHUB_ACTIONS:-}" ]]; then | ||
| # Upload under a distinct artifact name so it does not clobber the cuda-cccl | ||
| # wheel (both build jobs run in project 'python'). | ||
| wheel_artifact_name="$(CCCL_WHEEL_KIND=stf ci/util/workflow/get_wheel_artifact_name.sh)" | ||
| # Upload only the final STF wheel, not any co-located wheels in wheelhouse/. | ||
| ci/util/artifacts/upload.sh "$wheel_artifact_name" 'wheelhouse/cuda_stf-.*\.whl' | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Target script for `docker run` command in build_cuda_stf_python.sh | ||
| # The /workspace pathnames are hard-wired here. | ||
|
|
||
| # Install GCC 13 toolset (needed for the build) and ccache (shared between | ||
| # cu12 and cu13 builds via /root/.ccache bind-mount from the host). | ||
| /workspace/ci/util/retry.sh 5 30 dnf -y install \ | ||
| gcc-toolset-13-gcc gcc-toolset-13-gcc-c++ ccache | ||
|
|
||
| # When the caller bind-mounts a ccache dir, wire it through to CMake. This | ||
| # transparently caches every compile, so the second wheel build (cu13 after | ||
| # cu12, or vice versa) reuses the entire LLVM/clang object tree. | ||
| if [[ -n "${CCACHE_DIR:-}" ]]; then | ||
| export CMAKE_C_COMPILER_LAUNCHER=ccache | ||
| export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| export CMAKE_CUDA_COMPILER_LAUNCHER=ccache | ||
| echo "ccache enabled: CCACHE_DIR=${CCACHE_DIR}" | ||
| ccache --version 2>&1 | head -1 || true | ||
| ccache --show-stats 2>&1 | head -5 || true | ||
| fi | ||
| echo -e "#!/usr/bin/env bash\nsource /opt/rh/gcc-toolset-13/enable" >/etc/profile.d/enable_devtools.sh | ||
| # shellcheck disable=SC1091 | ||
| source /etc/profile.d/enable_devtools.sh | ||
|
|
||
| # Check what's available | ||
| command -v gcc | ||
| gcc --version | ||
| command -v nvcc | ||
| nvcc --version | ||
|
|
||
| # Set up Python environment | ||
| # shellcheck source=ci/pyenv_helper.sh | ||
| source /workspace/ci/pyenv_helper.sh | ||
| # shellcheck disable=SC2154 | ||
| setup_python_env "${py_version}" | ||
| command -v python | ||
| python --version | ||
| echo "Done setting up python env" | ||
|
|
||
| # Figure out the version to use for the package, we need repo history | ||
| if "$(git rev-parse --is-shallow-repository)"; then | ||
| git fetch --unshallow | ||
| fi | ||
| # Match the cuda-cccl version prefix so cuda-stf and cuda-cccl stay in lockstep. | ||
| export PACKAGE_VERSION_PREFIX="0.1." | ||
| package_version=$(/workspace/ci/generate_version.sh) | ||
| echo "Using package version ${package_version}" | ||
| # Override the version used by setuptools_scm to the custom version | ||
| export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CUDA_STF="${package_version}" | ||
|
|
||
| cd /workspace/python/cuda_stf | ||
|
|
||
| # Determine CUDA version from nvcc | ||
| cuda_version=$(nvcc --version | grep -oP 'release \K[0-9]+\.[0-9]+' | cut -d. -f1) | ||
| echo "Detected CUDA version: ${cuda_version}" | ||
|
|
||
| # Configure compilers: | ||
| CXX="$(command -v g++)" | ||
| export CXX | ||
| CUDACXX="$(command -v nvcc)" | ||
| export CUDACXX | ||
| CUDAHOSTCXX="$(command -v g++)" | ||
| export CUDAHOSTCXX | ||
|
|
||
| # Build the wheel | ||
| python -m pip wheel --no-deps --verbose --wheel-dir dist . | ||
|
|
||
| # Rename wheel to include CUDA version suffix | ||
| for wheel in dist/cuda_stf-*.whl; do | ||
| if [[ -f "$wheel" ]]; then | ||
| base_name=$(basename "$wheel" .whl) | ||
| new_name="${base_name}.cu${cuda_version}.whl" | ||
| mv "$wheel" "dist/${new_name}" | ||
| echo "Renamed wheel to: ${new_name}" | ||
| fi | ||
| done | ||
|
|
||
| # Move wheel to output directory | ||
| mkdir -p /workspace/wheelhouse | ||
| mv dist/cuda_stf-*.cu*.whl /workspace/wheelhouse/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of #9782