Skip to content
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

[ci] Add workflows #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/actions/build-cudaq/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: 'Build CUDA Quantum'
description: 'Build CUDA Quantum using CCache'

inputs:
cc:
description: 'C compiler executable'
required: true
cxx:
description: 'C++ compiler executable'
required: true
build-type:
description: 'Build type (e.g., Debug, Release)'
required: true
llvm-prefix:
description: 'LLVM installation prefix'
required: true

runs:
using: "composite"
steps:
- name: CCache key
id: ccache-key
run: |
echo "base_key=cudaq-${{ runner.os }}-${{ matrix.compiler.cc }}-${{ matrix.compiler.build-type }}" >> $GITHUB_OUTPUT
if [ ${{ github.ref }} != 'refs/heads/main' ]; then
echo "pr_key=-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Apt-get update
run: apt-get update
shell: bash

- name: Set up CCache
uses: hendrikmuhs/[email protected]
with:
append-timestamp: false
key: ${{ steps.ccache-key.outputs.base_key }}${{ steps.ccache-key.outputs.pr_key }}
restore-keys: ${{ steps.ccache-key.outputs.base_key }}

- name: Build
run: .github/actions/build-cudaq/build_cudaq.sh ${{ inputs.llvm-prefix }} ${{ inputs.build-type }} ${{ inputs.cc }} ${{ inputs.cxx }} ccache
shell: bash

# We need to remove any previous cache entry so that CCache can write a new
# cache entry for this build
- name: Cleanup cache
if: ${{ github.ref == 'refs/heads/main' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
apt-get install -y --no-install-recommends gh
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
BRANCH=${{ github.ref }}
KEYS=$(gh actions-cache list --key ccache-${{ steps.ccache-key.outputs.base_key }} -R $REPO -B $BRANCH | cut -f 1 )

for key in $KEYS
do
gh actions-cache delete $key -R ${{ github.repository }} -B $BRANCH --confirm
done
shell: bash
37 changes: 37 additions & 0 deletions .github/actions/build-cudaq/build_cudaq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

# This script is intended to be called from the github workflows.

LLVM_INSTALL_PREFIX=${1}
BUILD_TYPE=${2}
CC=${3}
CXX=${4}
LAUNCHER=${5}

mkdir build
cd build

cmake .. \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=../install \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_C_COMPILER_LAUNCHER=$LAUNCHER \
-DCMAKE_CXX_COMPILER_LAUNCHER=$LAUNCHER \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DMLIR_DIR=$LLVM_INSTALL_PREFIX/lib/cmake/mlir \
-DLLVM_DIR=$LLVM_INSTALL_PREFIX/lib/cmake/llvm \
-DLLVM_EXTERNAL_LIT=$(which lit) \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCUDAQ_ENABLE_PYTHON=ON

cmake --build . --target install
61 changes: 61 additions & 0 deletions .github/actions/check-formatting/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 'Check formatting'

inputs:
llvm-prefix:
description: 'LLVM installation prefix'
required: false
default: /opt/llvm

runs:
using: "composite"
steps:
# Choose the commit to diff against for linting. This workflow is
# triggered on both pushes and pull requests to main. Hence, we have to
# find out if the pull request target branch is set---it will only be on
# the PR triggered flow). If it's not, then compare against the last commit.
- name: Choose base commit
env:
BASE_REF: ${{ github.base_ref }}
run: |
if [ -z "$BASE_REF" ]; then
DIFF_COMMIT_NAME="HEAD^"
else
DIFF_COMMIT_NAME="$BASE_REF"
fi
echo "DIFF_COMMIT_NAME=$DIFF_COMMIT_NAME" >> $GITHUB_ENV
shell: sh

# We did a shallow clone, and thus we need to make sure to fetch the base
# commit.
- name: Fetch base commit
run: |
if echo "$DIFF_COMMIT_NAME" | grep -q HEAD; then
DIFF_COMMIT_SHA=$(git rev-parse $DIFF_COMMIT_NAME)
else
git fetch --recurse-submodules=no origin $DIFF_COMMIT_NAME
DIFF_COMMIT_SHA=$(git rev-parse origin/$DIFF_COMMIT_NAME)
fi
echo "DIFF_COMMIT_SHA=$DIFF_COMMIT_SHA" >> $GITHUB_ENV
shell: sh

- name: clang-format
run: |
cp ${{ inputs.llvm-prefix }}/bin/git-clang-format /usr/bin/
git config clangFormat.binary ${{ inputs.llvm-prefix }}/bin/clang-format
if ! git clang-format $DIFF_COMMIT_SHA -- ':!:tpls/*' ':!:test'; then
git diff --ignore-submodules > clang-format.patch
echo "::error::Clang-format found formatting problems." \
"Check the uploaded artifact."
exit 1
fi
echo "Clang-format found no formatting problems"
exit 0
shell: sh

- name: Upload format patches
uses: actions/upload-artifact@v3
continue-on-error: true
if: ${{ failure() }}
with:
name: clang-format-patch
path: clang-*.patch
36 changes: 36 additions & 0 deletions .github/actions/get-llvm-build-id/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Get LLVM build identifier'

inputs:
toolchain:
description: 'Toolchain name and version (e.g., gcc-11 and clang-15)'
required: true

outputs:
id:
description: 'LLVM build unique identifier'
value: ${{ steps.llvm-build-cache-key.outputs.key }}

runs:
using: "composite"
steps:
- name: Get LLVM commit SHA
id: llvm-commit-sha
run: echo "sha=$(git rev-parse @:./tpls/llvm)" >> $GITHUB_OUTPUT
shell: bash

- name: Get LLVM configuration hash
id: llvm-config-hash
env:
llvm-build-script: .github/actions/get-llvm-build/build_llvm.sh
run: |
if [[ ${{ runner.os }} == 'Linux' ]]; then
echo "hash=$(md5sum ${{ env.llvm-build-script }} | awk '{print $1}')" >> $GITHUB_OUTPUT
elif [[ ${{ runner.os }} == 'macOS' ]]; then
echo "hash=$(md5 ${{ env.llvm-build-script }} | awk '{print $4}')" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Create LLVM build cache key
id: llvm-build-cache-key
run: echo "key=llvm-${{ runner.os }}-${{ steps.llvm-commit-sha.outputs.sha }}-${{ steps.llvm-config-hash.outputs.hash }}-${{ inputs.toolchain }}" >> $GITHUB_OUTPUT
shell: bash
64 changes: 64 additions & 0 deletions .github/actions/get-llvm-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Get LLVM build'
description: 'Either restore LLVM from cache or build it'

inputs:
toolchain:
description: 'Toolchain name and version (e.g., gcc-11 and clang-15)'
required: true
cc:
description: 'C compiler executable'
required: true
cxx:
description: 'C++ compiler executable'
required: true
only-restore:
description: 'Indicates whether LLVM should be built if a cache entry is not found'
default: 'true'
required: false

runs:
using: "composite"
steps:
- name: Get LLVM build identifier
id: get-llvm-build-id
uses: ./.github/actions/get-llvm-build-id
with:
toolchain: ${{ inputs.toolchain }}

- name: Try to restoring LLVM from cache
id: restore-llvm-cache
uses: actions/cache/restore@v3
with:
fail-on-cache-miss: ${{ inputs.only-restore == 'true' }}
path: tpls/llvm/install/llvm/
key: ${{ steps.get-llvm-build-id.outputs.id }}

- name: Set up CCache
if: steps.restore-llvm-cache.outputs.cache-hit != 'true'
uses: hendrikmuhs/[email protected]
with:
max-size: 500M
variant: sccache
append-timestamp: false
key: llvm-${{ runner.os }}-${{ inputs.toolchain }}
save: ${{ github.ref == 'refs/heads/main' }}

- name: Build LLVM
if: steps.restore-llvm-cache.outputs.cache-hit != 'true'
env:
llvm-build-script: .github/actions/get-llvm-build/build_llvm.sh
run: bash ${{ env.llvm-build-script }} Release ${{ inputs.cc }} ${{ inputs.cxx }} sccache
shell: bash

- name: Store cache key
if: steps.restore-llvm-cache.outputs.cache-hit != 'true'
run: echo "${{ steps.restore-llvm-cache.outputs.cache-primary-key }}" > tpls/llvm/install/llvm/cache-key
shell: bash

- name: Store LLVM build in the cache
if: steps.restore-llvm-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: tpls/llvm/install/llvm/
key: ${{ steps.restore-llvm-cache.outputs.cache-primary-key }}

64 changes: 64 additions & 0 deletions .github/actions/get-llvm-build/build_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

# This script is intended to be called from the github workflows.

BUILD_TYPE=${1:-"Release"}
CC=${2:-"clang"}
CXX=${3:-"clang++"}
LAUNCHER=${4:-""}

LLVM_PROJECTS="clang;mlir"

# LLVM library components
LLVM_COMPONENTS="cmake-exports;llvm-headers;llvm-libraries"

# Clang library components
LLVM_COMPONENTS+=";clang-cmake-exports;clang-headers;clang-libraries;clang-resource-headers"

# MLIR library components
LLVM_COMPONENTS+=";mlir-cmake-exports;mlir-headers;mlir-libraries"

# Tools / Utils
LLVM_COMPONENTS+=";llvm-config;clang-format;llc;clang;mlir-tblgen;FileCheck;count;not"

# Clone LLVM fast
LLVM_SHA=$(git rev-parse @:./tpls/llvm)
cd tpls/llvm
git init
git remote add origin https://github.com/llvm/llvm-project
git fetch --depth=1 origin $LLVM_SHA
git reset --hard FETCH_HEAD

mkdir build
mkdir -p install/llvm

# Configure and build
cd build
cmake ../llvm \
-G Ninja \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_C_COMPILER_LAUNCHER=$LAUNCHER \
-DCMAKE_CXX_COMPILER_LAUNCHER=$LAUNCHER \
-DCMAKE_INSTALL_PREFIX=../install/llvm \
-DLLVM_ENABLE_PROJECTS=$LLVM_PROJECTS \
-DLLVM_DISTRIBUTION_COMPONENTS=$LLVM_COMPONENTS \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_LLD=ON \
-DLLVM_ENABLE_OCAMLDOC=OFF \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_TARGETS_TO_BUILD="host"

cmake --build . --target install-distribution-stripped
Loading