Skip to content

Commit

Permalink
Build CUDA-Q wheels from source (needed to test CUDA-QX wheels)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Howe <[email protected]>
  • Loading branch information
bmhowe23 committed Jan 18, 2025
1 parent a39f31c commit 7d43a3b
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 12 deletions.
12 changes: 7 additions & 5 deletions .github/actions/get-cudaq-version/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ runs:

- name: Install jq
run: |
if [ -x "$(command -v apt-get)" ]; then
apt-get update
apt-get install -y --no-install-recommends jq
elif [ -x "$(command -v dnf)" ]; then
dnf install -y --nobest --setopt=install_weak_deps=False jq
if [ ! -x "$(command -v jq)" ]; then
if [ -x "$(command -v apt-get)" ]; then
apt-get update
apt-get install -y --no-install-recommends jq
elif [ -x "$(command -v dnf)" ]; then
dnf install -y --nobest --setopt=install_weak_deps=False jq
fi
fi
shell: bash
Expand Down
163 changes: 163 additions & 0 deletions .github/actions/get-cudaq-wheels/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: Get CUDAQ wheels
description: 'Either restore CUDAQ wheels from cache or build them'

inputs:
repo:
description: 'CUDAQ repository.'
required: true
ref:
description: 'The branch, tag or SHA to checkout.'
required: true
token:
description: 'CUDAQ repository access token.'
default: ''
required: false
pr-number:
description: 'Unique pull request identifier.'
default: ''
required: false
save-build:
description: 'Indicates whether to save the build'
default: 'false'
required: false
lookup-only:
description: 'Check if a cache entry exists without downloading the cache'
default: 'false'
required: false
platform:
description: 'Platform (amd64 or arm64)'
default: ''
required: true
outputs:
found-cache:
description: 'A boolean value to indicate that a cache entry was found.'
value: ${{ steps.check-cache.outputs.valid }}

runs:
using: "composite"
steps:
# ==========================================================================
# Try to restore from cache
# ==========================================================================

- name: Create CUDAQ wheel cache key
id: cudaq-wheels-key
env:
# This are a list of files that when changed should require a new cudaq build
to_hash: |
.github/actions/get-cudaq-wheels/**
.cudaq_version
run: |
hash=${{ hashFiles(format('{0}', env.to_hash)) }}
echo "main=cudaq-wheels-${{ inputs.platform }}-${{ inputs.ref }}-$hash" >> $GITHUB_OUTPUT
if [[ -n "${{ inputs.pr-number }}" ]]; then
echo "pr=-pr${{ inputs.pr-number }}" >> $GITHUB_OUTPUT
fi
sudo mkdir /cudaq-wheels && sudo chmod 777 /cudaq-wheels
shell: bash --noprofile --norc -euo pipefail {0}

- name: Try to restoring CUDAQ wheels from cache
id: restore-cudaq-wheels
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: false
path: /cudaq-wheels
key: ${{ steps.cudaq-wheels-key.outputs.main }}${{ steps.cudaq-wheels-key.outputs.pr }}
restore-keys: ${{ steps.cudaq-wheels-key.outputs.main }}
lookup-only: ${{ inputs.lookup-only }}

# The restore action could find a partial match using the `restore-keys`. In such cases
# it would still report `cache-hit` as false, but would load the cache from the partial
# one. Thus, we need to check whether the cache is valid by other means.
- name: Check if cache is valid
id: check-cache
run: |
if [[ "${{ steps.restore-cudaq-wheels.outputs.cache-matched-key }}" == "" ]]; then
echo "valid=false" >> $GITHUB_OUTPUT
else
echo "valid=true" >> $GITHUB_OUTPUT
fi
shell: bash --noprofile --norc -euo pipefail {0}

# ==========================================================================
# Build CUDAQ wheels
# ==========================================================================

- name: Login to GitHub CR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Get CUDAQ code
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
uses: actions/checkout@v4
with:
repository: ${{ inputs.repo }}
ref: ${{ inputs.ref }}
path: cudaq
set-safe-directory: true

- name: Set up context for buildx
run: |
docker context create builder_context
shell: bash --noprofile --norc -euo pipefail {0}

- name: Set up buildx runner
uses: docker/setup-buildx-action@v3
with:
endpoint: builder_context
driver-opts: network=host

- name: Build 3.10 wheel
uses: docker/build-push-action@v5
with:
context: cudaq
file: ./cudaq/docker/release/cudaq.wheel.Dockerfile
build-args: |
base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-${{ inputs.platform }}-cu12.0-gcc11-main
release_version=0.99.99
python_version=3.10
outputs: /cudaq-wheels

- name: Build 3.11 wheel
uses: docker/build-push-action@v5
with:
context: cudaq
file: ./cudaq/docker/release/cudaq.wheel.Dockerfile
build-args: |
base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-${{ inputs.platform }}-cu12.0-gcc11-main
release_version=0.99.99
python_version=3.11
outputs: /cudaq-wheels

- name: Build 3.12 wheel
uses: docker/build-push-action@v5
with:
context: cudaq
file: ./cudaq/docker/release/cudaq.wheel.Dockerfile
build-args: |
base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-${{ inputs.platform }}-cu12.0-gcc11-main
release_version=0.99.99
python_version=3.12
outputs: /cudaq-wheels

- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: cudaq-wheels-${{ inputs.platform }}
path: /cudaq-wheels
retention-days: 10
if-no-files-found: error

# ==========================================================================
# Store CUDAQ wheels cache
# ==========================================================================

- name: Store CUDAQ wheels in the cache
if: steps.check-cache.outputs.valid == 'false' && inputs.save-build == 'true' && inputs.lookup-only == 'false'
uses: actions/cache/save@v4
with:
path: /cudaq-wheels
key: ${{ steps.cudaq-wheels-key.outputs.main }}${{ steps.cudaq-wheels-key.outputs.pr }}
68 changes: 61 additions & 7 deletions .github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ concurrency:
cancel-in-progress: true

jobs:
linux-build:
name: Linux build
build-cudaqx-wheels:
name: Build CUDA-QX wheels
runs-on: linux-${{ matrix.platform }}-cpu8
# CUDAQ requires a highly specialized environment to build. Thus, it is much
# easier to rely on their's devdeps images to do the building.
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Build CUDAQ toolchain
if: ${{ !inputs.artifacts_from_run }}
run: |
.github/workflows/scripts/build_cudaq.sh ${{ matrix.python }}
.github/workflows/scripts/build_cudaq.sh ${{ matrix.python }}
- name: Build wheels
if: ${{ !inputs.artifacts_from_run }}
Expand All @@ -84,9 +84,49 @@ jobs:
name: wheels-py${{ matrix.python }}-${{ matrix.platform }}
path: /wheels/**

# Building the CUDA-Q wheels must be done outside of a container context, so
# this is a separate job.
build-cudaq-wheels:
name: Build CUDA-Q wheels
strategy:
fail-fast: false
matrix:
platform: ['amd64', 'arm64']
runs-on: ${{ startsWith(github.repository, 'NVIDIA/cudaqx') && format('linux-{0}-cpu32', matrix.platform) || 'ubuntu-latest' }}
permissions:
actions: write
contents: read
pull-requests: read
steps:
- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Get required CUDAQ version
id: get-cudaq-version
uses: ./.github/actions/get-cudaq-version

- name: Get CUDAQ wheels
uses: ./.github/actions/get-cudaq-wheels
with:
repo: ${{ steps.get-cudaq-version.outputs.repo }}
ref: ${{ steps.get-cudaq-version.outputs.ref }}
token: ${{ secrets.CUDAQ_ACCESS_TOKEN }}
save-build: true
platform: ${{ matrix.platform }}

- name: Upload CUDAQ wheels
uses: actions/upload-artifact@v4
with:
name: cudaq-wheels-${{ matrix.platform }}
path: /cudaq-wheels
retention-days: 10
if-no-files-found: error

test-cudaqx-wheels:
name: Test CUDA-QX wheels (CPU)
needs: linux-build
needs: [build-cudaqx-wheels, build-cudaq-wheels]
runs-on: linux-${{ matrix.platform }}-cpu4
container: ubuntu:22.04
permissions:
Expand Down Expand Up @@ -114,7 +154,14 @@ jobs:
bash .github/workflows/scripts/install_git_cli.sh
apt install -y --no-install-recommends libgfortran5 unzip
- name: Download CUDAQX wheels
- name: Download CUDA-Q wheels
uses: actions/download-artifact@v4
with:
name: cudaq-wheels-${{ matrix.platform }}
path: /cudaq-wheels
run-id: ${{ inputs.artifacts_from_run || github.run_id }}

- name: Download CUDA-QX wheels
uses: actions/download-artifact@v4
with:
name: wheels-py${{ matrix.python }}-${{ matrix.platform }}
Expand All @@ -128,7 +175,7 @@ jobs:
test-wheels-gpu:
name: Test CUDA-QX wheels (GPU)
needs: linux-build
needs: [build-cudaqx-wheels, build-cudaq-wheels]
runs-on: linux-${{ matrix.runner.arch }}-gpu-${{ matrix.runner.gpu }}-latest-1
container:
image: nvidia/cuda:12.0.0-base-ubuntu22.04
Expand Down Expand Up @@ -168,7 +215,14 @@ jobs:
#echo "Running cat /proc/sys/kernel/core_pattern"
#cat /proc/sys/kernel/core_pattern
- name: Download CUDAQX wheels
- name: Download CUDA-Q wheels
uses: actions/download-artifact@v4
with:
name: cudaq-wheels-${{ matrix.platform }}
path: /cudaq-wheels
run-id: ${{ inputs.artifacts_from_run || github.run_id }}

- name: Download CUDA-QX wheels
uses: actions/download-artifact@v4
with:
name: wheels-py${{ matrix.python }}-${{ matrix.runner.arch }}
Expand Down

0 comments on commit 7d43a3b

Please sign in to comment.