Skip to content

Commit

Permalink
Initial commit. Hello world!
Browse files Browse the repository at this point in the history
Signed-off-by: boschmitt <[email protected]>
  • Loading branch information
amccaskey authored and boschmitt committed Nov 18, 2024
0 parents commit 044539b
Show file tree
Hide file tree
Showing 248 changed files with 25,336 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BasedOnStyle: LLVM
AlwaysBreakTemplateDeclarations: Yes
IncludeCategories:
- Regex: '^<'
Priority: 4
- Regex: '^"(llvm|llvm-c|clang|clang-c|mlir|mlir-c)/'
Priority: 3
- Regex: '^"(qoda|\.\.)/'
Priority: 2
- Regex: '.*'
Priority: 1
11 changes: 11 additions & 0 deletions .cudaq_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"cudaq": {
"repository": "NVIDIA/cuda-quantum",
"ref": "d63dc8d93b4f9c95677aad2ddad2f9020cde45d0"
},
"cuquantum": {
"url": "https://developer.download.nvidia.com/compute/cuquantum/redist/cuquantum/linux-x86_64/",
"pattern": "cuquantum-linux-x86_64-24.11.0.21_cuda12-archive.tar.xz"
}
}

80 changes: 80 additions & 0 deletions .github/actions/build-lib/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build a CUDAQX library

inputs:
lib:
description: 'Library name to build. (e.g, all, qec or solvers)'
required: true
pr-number:
description: 'Unique pull request identifier.'
default: ''
required: false
save-ccache:
description: 'Indicates whether to save the compilation cache'
default: 'false'
required: false
outputs:
build-dir:
description: 'Build dir.'
value: ${{ steps.build-lib.outputs.build_dir }}


runs:
using: "composite"
steps:
- name: Install requirements
run: |
apt update
apt install -y --no-install-recommends ccache
python3 -m pip install cmake --user
echo "$HOME/.local/bin:$PATH" >> $GITHUB_PATH
shell: bash

- name: Compilation cache key
id: ccache-key
run: |
echo "main=ccache-${{ inputs.lib }}-cu12.0-gcc11" >> $GITHUB_OUTPUT
if [[ -n "${{ inputs.pr-number }}" ]]; then
echo "pr=-pr${{ inputs.pr-number }}" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Try to restoring previous compilation cache
id: restore-ccache
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: false
path: /ccache-${{ inputs.lib }}
key: ${{ steps.ccache-key.outputs.main }}${{ steps.ccache-key.outputs.pr }}
restore-keys: |
${{ steps.ccache-key.outputs.main }}
- name: Build library
id: build-lib
env:
CCACHE_DIR: /ccache-${{ inputs.lib }}
run: |
build_dir=build_${{ inputs.lib }}
.github/actions/build-lib/build_${{ inputs.lib }}.sh $build_dir
echo "build_dir=$build_dir" >> $GITHUB_OUTPUT
shell: bash

# We need to delete previous cache entry otherwise the new one won't be stored
- name: Delete previous main compilation cache
if: steps.restore-ccache.outputs.cache-hit == 'true' && inputs.save-ccache == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
bash .github/workflows/scripts/install_git_cli.sh
gh cache delete \
${{ steps.ccache-key.outputs.main }}${{ steps.ccache-key.outputs.pr }} \
--repo ${{ github.repository }}
shell: bash

- name: Store compilation cache
if: inputs.save-ccache == 'true'
uses: actions/cache/save@v4
continue-on-error: true
with:
path: /ccache-${{ inputs.lib }}
key: ${{ steps.ccache-key.outputs.main }}${{ steps.ccache-key.outputs.pr }}

15 changes: 15 additions & 0 deletions .github/actions/build-lib/build_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

cmake -S . -B "$1" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc-11 \
-DCMAKE_CXX_COMPILER=g++-11 \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCUDAQ_DIR=/cudaq-install/lib/cmake/cudaq/ \
-DCUDAQX_ENABLE_LIBS="all" \
-DCUDAQX_INCLUDE_TESTS=ON \
-DCUDAQX_BINDINGS_PYTHON=ON

cmake --build "$1" --target install

14 changes: 14 additions & 0 deletions .github/actions/build-lib/build_qec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cmake -S libs/qec -B "$1" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc-11 \
-DCMAKE_CXX_COMPILER=g++-11 \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCUDAQ_DIR=/cudaq-install/lib/cmake/cudaq/ \
-DCUDAQX_INCLUDE_TESTS=ON \
-DCUDAQX_BINDINGS_PYTHON=ON

cmake --build "$1" --target install

14 changes: 14 additions & 0 deletions .github/actions/build-lib/build_solvers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cmake -S libs/solvers -B "$1" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc-11 \
-DCMAKE_CXX_COMPILER=g++-11 \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCUDAQ_DIR=/cudaq-install/lib/cmake/cudaq/ \
-DCUDAQX_INCLUDE_TESTS=ON \
-DCUDAQX_BINDINGS_PYTHON=ON

cmake --build "$1" --target install

168 changes: 168 additions & 0 deletions .github/actions/get-cudaq-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Get CUDAQ build
description: 'Either restore CUDAQ from cache or build it'

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
save-ccache:
description: 'Indicates whether to save the compilation cache'
default: 'false'
required: false
lookup-only:
description: 'Check if a cache entry exists without downloading the cache'
default: 'false'
required: false
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 build cache key
id: cudaq-build-key
env:
# This are a list of files that when changed should require a new cudaq build
to_hash: |
.github/actions/get-cudaq-build/**
.cudaq_version
run: |
hash=${{ hashFiles(format('{0}', env.to_hash)) }}
echo "main=cudaq-${{ inputs.ref }}-$hash" >> $GITHUB_OUTPUT
if [[ -n "${{ inputs.pr-number }}" ]]; then
echo "pr=-pr${{ inputs.pr-number }}" >> $GITHUB_OUTPUT
fi
shell: bash --noprofile --norc -euo pipefail {0}

- name: Try to restoring CUDAQ from cache
id: restore-cudaq-build
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: false
path: /cudaq-install
key: ${{ steps.cudaq-build-key.outputs.main }}${{ steps.cudaq-build-key.outputs.pr }}
restore-keys: ${{ steps.cudaq-build-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-build.outputs.cache-matched-key }}" == "" ]]; then
echo "valid=false" >> $GITHUB_OUTPUT
else
echo "valid=true" >> $GITHUB_OUTPUT
fi
shell: bash --noprofile --norc -euo pipefail {0}

# ==========================================================================
# Get cuQuantum
# ==========================================================================

- name: Download assets
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
env:
GITHUB_TOKEN: ${{ inputs.token }}
CUQUANTUM_INSTALL_PREFIX: /cudaq-install
run: |
bash .github/workflows/scripts/install_git_cli.sh
mkdir -p ${CUQUANTUM_INSTALL_PREFIX}
python3 .github/actions/get-cudaq-build/get_assets.py
cuquantum_archive=$(jq -r '.cuquantum.pattern' .cudaq_version)
tar xf "${cuquantum_archive}" --strip-components 1 -C "${CUQUANTUM_INSTALL_PREFIX}"
shell: bash --noprofile --norc -euo pipefail {0}

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

- 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: Try to restoring CUDAQ compilation cache
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
id: restore-ccache
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: false
path: /cudaq-ccache
key: ccache-cudaq

- name: Install CUDAQ build requirements
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
run: |
bash .github/workflows/scripts/install_git_cli.sh
apt install -y --no-install-recommends ccache
shell: bash --noprofile --norc -euo pipefail {0}

- name: Build CUDAQ
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
env:
CCACHE_DIR: /cudaq-ccache
cudaq-build-script: .github/actions/get-cudaq-build/build_cudaq.sh
CUQUANTUM_INSTALL_PREFIX: /cudaq-install
CUTENSOR_INSTALL_PREFIX: /cudaq-install
CUDAQ_INSTALL_PREFIX: /cudaq-install
run: bash ${{ env.cudaq-build-script }} Release ccache gcc-11 g++-11
shell: bash --noprofile --norc -euo pipefail {0}

# ==========================================================================
# Store CUDAQ compilation cache
# ==========================================================================

# We need to delete previous cache entry otherwise the new one won't be stored
- name: Delete previous compilation cache
if: steps.restore-ccache.outputs.cache-hit == 'true' && inputs.save-ccache == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh cache delete ccache-cudaq --repo ${{ github.repository }}
shell: bash --noprofile --norc -euo pipefail {0}

- name: Store compilation (CCache)
if: steps.check-cache.outputs.valid == 'false' && inputs.save-ccache == 'true' && inputs.lookup-only == 'false'
uses: actions/cache/save@v4
with:
path: /cudaq-ccache
key: ccache-cudaq


# ==========================================================================
# Store CUDAQ build cache
# ==========================================================================

- name: Store CUDAQ build 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-install
key: ${{ steps.cudaq-build-key.outputs.main }}${{ steps.cudaq-build-key.outputs.pr }}
75 changes: 75 additions & 0 deletions .github/actions/get-cudaq-build/build_cudaq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# ============================================================================ #
# Copyright (c) 2022 - 2024 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. #
# ============================================================================ #

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

LLVM_INSTALL_PREFIX=/usr/local/llvm
CUTENSOR_INSTALL_PREFIX=/opt/nvidia/cutensor

cd cudaq

# Determine linker and linker flags
if [ -x "$(command -v "$LLVM_INSTALL_PREFIX/bin/ld.lld")" ]; then
echo "Configuring nvq++ to use the lld linker by default."
NVQPP_LD_PATH="$LLVM_INSTALL_PREFIX/bin/ld.lld"
fi


# Determine CUDA flags
cuda_driver=${CUDACXX:-${CUDA_HOME:-/usr/local/cuda}/bin/nvcc}

if [ -z "$CUDAHOSTCXX" ] && [ -z "$CUDAFLAGS" ]; then
CUDAFLAGS='-allow-unsupported-compiler'
if [ -x "$CXX" ] && [ -n "$("$CXX" --version | grep -i clang)" ]; then
CUDAFLAGS+=" --compiler-options --stdlib=libstdc++"
fi
if [ -d "$GCC_TOOLCHAIN" ]; then
# e.g. GCC_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/
CUDAFLAGS+=" --compiler-options --gcc-toolchain=\"$GCC_TOOLCHAIN\""
fi
fi

# Determine OpenMP flags
if [ -n "$(find "$LLVM_INSTALL_PREFIX" -name 'libomp.so')" ]; then
OMP_LIBRARY=${OMP_LIBRARY:-libomp}
OpenMP_libomp_LIBRARY=${OMP_LIBRARY#lib}
OpenMP_FLAGS="${OpenMP_FLAGS:-'-fopenmp'}"
fi

echo "Preparing CUDA-Q build with LLVM installation in $LLVM_INSTALL_PREFIX..."
cmake_args="-G Ninja \
-DCMAKE_INSTALL_PREFIX='"$CUDAQ_INSTALL_PREFIX"' \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_C_COMPILER_LAUNCHER=$LAUNCHER \
-DCMAKE_CXX_COMPILER_LAUNCHER=$LAUNCHER \
-DNVQPP_LD_PATH='"$NVQPP_LD_PATH"' \
-DCMAKE_CUDA_COMPILER='"$cuda_driver"' \
-DCMAKE_CUDA_FLAGS='"$CUDAFLAGS"' \
-DCMAKE_CUDA_HOST_COMPILER='"${CUDAHOSTCXX:-$CXX}"' \
${OpenMP_libomp_LIBRARY:+-DOpenMP_C_LIB_NAMES=lib$OpenMP_libomp_LIBRARY} \
${OpenMP_libomp_LIBRARY:+-DOpenMP_CXX_LIB_NAMES=lib$OpenMP_libomp_LIBRARY} \
${OpenMP_libomp_LIBRARY:+-DOpenMP_libomp_LIBRARY=$OpenMP_libomp_LIBRARY} \
${OpenMP_FLAGS:+"-DOpenMP_C_FLAGS='"$OpenMP_FLAGS"'"} \
${OpenMP_FLAGS:+"-DOpenMP_CXX_FLAGS='"$OpenMP_FLAGS"'"} \
-DCUDAQ_REQUIRE_OPENMP=TRUE \
-DCUDAQ_ENABLE_PYTHON=TRUE \
-DCUDAQ_BUILD_TESTS=FALSE \
-DCUDAQ_TEST_MOCK_SERVERS=FALSE \
-DCMAKE_COMPILE_WARNING_AS_ERROR=OFF"

echo $cmake_args | xargs cmake -S . -B "build"

cmake --build "build" --target install

Loading

0 comments on commit 044539b

Please sign in to comment.