Skip to content

Commit 044539b

Browse files
amccaskeyboschmitt
authored andcommitted
Initial commit. Hello world!
Signed-off-by: boschmitt <[email protected]>
0 parents  commit 044539b

File tree

248 files changed

+25336
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+25336
-0
lines changed

.clang-format

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BasedOnStyle: LLVM
2+
AlwaysBreakTemplateDeclarations: Yes
3+
IncludeCategories:
4+
- Regex: '^<'
5+
Priority: 4
6+
- Regex: '^"(llvm|llvm-c|clang|clang-c|mlir|mlir-c)/'
7+
Priority: 3
8+
- Regex: '^"(qoda|\.\.)/'
9+
Priority: 2
10+
- Regex: '.*'
11+
Priority: 1

.cudaq_version

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"cudaq": {
3+
"repository": "NVIDIA/cuda-quantum",
4+
"ref": "d63dc8d93b4f9c95677aad2ddad2f9020cde45d0"
5+
},
6+
"cuquantum": {
7+
"url": "https://developer.download.nvidia.com/compute/cuquantum/redist/cuquantum/linux-x86_64/",
8+
"pattern": "cuquantum-linux-x86_64-24.11.0.21_cuda12-archive.tar.xz"
9+
}
10+
}
11+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build a CUDAQX library
2+
3+
inputs:
4+
lib:
5+
description: 'Library name to build. (e.g, all, qec or solvers)'
6+
required: true
7+
pr-number:
8+
description: 'Unique pull request identifier.'
9+
default: ''
10+
required: false
11+
save-ccache:
12+
description: 'Indicates whether to save the compilation cache'
13+
default: 'false'
14+
required: false
15+
outputs:
16+
build-dir:
17+
description: 'Build dir.'
18+
value: ${{ steps.build-lib.outputs.build_dir }}
19+
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Install requirements
25+
run: |
26+
apt update
27+
apt install -y --no-install-recommends ccache
28+
python3 -m pip install cmake --user
29+
echo "$HOME/.local/bin:$PATH" >> $GITHUB_PATH
30+
shell: bash
31+
32+
- name: Compilation cache key
33+
id: ccache-key
34+
run: |
35+
echo "main=ccache-${{ inputs.lib }}-cu12.0-gcc11" >> $GITHUB_OUTPUT
36+
if [[ -n "${{ inputs.pr-number }}" ]]; then
37+
echo "pr=-pr${{ inputs.pr-number }}" >> $GITHUB_OUTPUT
38+
fi
39+
shell: bash
40+
41+
- name: Try to restoring previous compilation cache
42+
id: restore-ccache
43+
uses: actions/cache/restore@v4
44+
with:
45+
fail-on-cache-miss: false
46+
path: /ccache-${{ inputs.lib }}
47+
key: ${{ steps.ccache-key.outputs.main }}${{ steps.ccache-key.outputs.pr }}
48+
restore-keys: |
49+
${{ steps.ccache-key.outputs.main }}
50+
51+
- name: Build library
52+
id: build-lib
53+
env:
54+
CCACHE_DIR: /ccache-${{ inputs.lib }}
55+
run: |
56+
build_dir=build_${{ inputs.lib }}
57+
.github/actions/build-lib/build_${{ inputs.lib }}.sh $build_dir
58+
echo "build_dir=$build_dir" >> $GITHUB_OUTPUT
59+
shell: bash
60+
61+
# We need to delete previous cache entry otherwise the new one won't be stored
62+
- name: Delete previous main compilation cache
63+
if: steps.restore-ccache.outputs.cache-hit == 'true' && inputs.save-ccache == 'true'
64+
env:
65+
GH_TOKEN: ${{ github.token }}
66+
run: |
67+
bash .github/workflows/scripts/install_git_cli.sh
68+
gh cache delete \
69+
${{ steps.ccache-key.outputs.main }}${{ steps.ccache-key.outputs.pr }} \
70+
--repo ${{ github.repository }}
71+
shell: bash
72+
73+
- name: Store compilation cache
74+
if: inputs.save-ccache == 'true'
75+
uses: actions/cache/save@v4
76+
continue-on-error: true
77+
with:
78+
path: /ccache-${{ inputs.lib }}
79+
key: ${{ steps.ccache-key.outputs.main }}${{ steps.ccache-key.outputs.pr }}
80+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
cmake -S . -B "$1" \
4+
-DCMAKE_BUILD_TYPE=Release \
5+
-DCMAKE_C_COMPILER=gcc-11 \
6+
-DCMAKE_CXX_COMPILER=g++-11 \
7+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
8+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
9+
-DCUDAQ_DIR=/cudaq-install/lib/cmake/cudaq/ \
10+
-DCUDAQX_ENABLE_LIBS="all" \
11+
-DCUDAQX_INCLUDE_TESTS=ON \
12+
-DCUDAQX_BINDINGS_PYTHON=ON
13+
14+
cmake --build "$1" --target install
15+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
cmake -S libs/qec -B "$1" \
4+
-DCMAKE_BUILD_TYPE=Release \
5+
-DCMAKE_C_COMPILER=gcc-11 \
6+
-DCMAKE_CXX_COMPILER=g++-11 \
7+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
8+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
9+
-DCUDAQ_DIR=/cudaq-install/lib/cmake/cudaq/ \
10+
-DCUDAQX_INCLUDE_TESTS=ON \
11+
-DCUDAQX_BINDINGS_PYTHON=ON
12+
13+
cmake --build "$1" --target install
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
cmake -S libs/solvers -B "$1" \
4+
-DCMAKE_BUILD_TYPE=Release \
5+
-DCMAKE_C_COMPILER=gcc-11 \
6+
-DCMAKE_CXX_COMPILER=g++-11 \
7+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
8+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
9+
-DCUDAQ_DIR=/cudaq-install/lib/cmake/cudaq/ \
10+
-DCUDAQX_INCLUDE_TESTS=ON \
11+
-DCUDAQX_BINDINGS_PYTHON=ON
12+
13+
cmake --build "$1" --target install
14+
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: Get CUDAQ build
2+
description: 'Either restore CUDAQ from cache or build it'
3+
4+
inputs:
5+
repo:
6+
description: 'CUDAQ repository.'
7+
required: true
8+
ref:
9+
description: 'The branch, tag or SHA to checkout.'
10+
required: true
11+
token:
12+
description: 'CUDAQ repository access token.'
13+
default: ''
14+
required: false
15+
pr-number:
16+
description: 'Unique pull request identifier.'
17+
default: ''
18+
required: false
19+
save-build:
20+
description: 'Indicates whether to save the build'
21+
default: 'false'
22+
required: false
23+
save-ccache:
24+
description: 'Indicates whether to save the compilation cache'
25+
default: 'false'
26+
required: false
27+
lookup-only:
28+
description: 'Check if a cache entry exists without downloading the cache'
29+
default: 'false'
30+
required: false
31+
outputs:
32+
found-cache:
33+
description: 'A boolean value to indicate that a cache entry was found.'
34+
value: ${{ steps.check-cache.outputs.valid }}
35+
36+
runs:
37+
using: "composite"
38+
steps:
39+
# ==========================================================================
40+
# Try to restore from cache
41+
# ==========================================================================
42+
43+
- name: Create CUDAQ build cache key
44+
id: cudaq-build-key
45+
env:
46+
# This are a list of files that when changed should require a new cudaq build
47+
to_hash: |
48+
.github/actions/get-cudaq-build/**
49+
.cudaq_version
50+
run: |
51+
hash=${{ hashFiles(format('{0}', env.to_hash)) }}
52+
echo "main=cudaq-${{ inputs.ref }}-$hash" >> $GITHUB_OUTPUT
53+
if [[ -n "${{ inputs.pr-number }}" ]]; then
54+
echo "pr=-pr${{ inputs.pr-number }}" >> $GITHUB_OUTPUT
55+
fi
56+
shell: bash --noprofile --norc -euo pipefail {0}
57+
58+
- name: Try to restoring CUDAQ from cache
59+
id: restore-cudaq-build
60+
uses: actions/cache/restore@v4
61+
with:
62+
fail-on-cache-miss: false
63+
path: /cudaq-install
64+
key: ${{ steps.cudaq-build-key.outputs.main }}${{ steps.cudaq-build-key.outputs.pr }}
65+
restore-keys: ${{ steps.cudaq-build-key.outputs.main }}
66+
lookup-only: ${{ inputs.lookup-only }}
67+
68+
# The restore action could find a partial match using the `restore-keys`. In such cases
69+
# it would still report `cache-hit` as false, but would load the cache from the partial
70+
# one. Thus, we need to check whether the cache is valid by other means.
71+
- name: Check if cache is valid
72+
id: check-cache
73+
run: |
74+
if [[ "${{ steps.restore-cudaq-build.outputs.cache-matched-key }}" == "" ]]; then
75+
echo "valid=false" >> $GITHUB_OUTPUT
76+
else
77+
echo "valid=true" >> $GITHUB_OUTPUT
78+
fi
79+
shell: bash --noprofile --norc -euo pipefail {0}
80+
81+
# ==========================================================================
82+
# Get cuQuantum
83+
# ==========================================================================
84+
85+
- name: Download assets
86+
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
87+
env:
88+
GITHUB_TOKEN: ${{ inputs.token }}
89+
CUQUANTUM_INSTALL_PREFIX: /cudaq-install
90+
run: |
91+
bash .github/workflows/scripts/install_git_cli.sh
92+
mkdir -p ${CUQUANTUM_INSTALL_PREFIX}
93+
python3 .github/actions/get-cudaq-build/get_assets.py
94+
cuquantum_archive=$(jq -r '.cuquantum.pattern' .cudaq_version)
95+
tar xf "${cuquantum_archive}" --strip-components 1 -C "${CUQUANTUM_INSTALL_PREFIX}"
96+
shell: bash --noprofile --norc -euo pipefail {0}
97+
98+
# ==========================================================================
99+
# Build CUDAQ
100+
# ==========================================================================
101+
102+
- name: Get CUDAQ code
103+
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
104+
uses: actions/checkout@v4
105+
with:
106+
repository: ${{ inputs.repo }}
107+
ref: ${{ inputs.ref }}
108+
path: cudaq
109+
set-safe-directory: true
110+
111+
- name: Try to restoring CUDAQ compilation cache
112+
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
113+
id: restore-ccache
114+
uses: actions/cache/restore@v4
115+
with:
116+
fail-on-cache-miss: false
117+
path: /cudaq-ccache
118+
key: ccache-cudaq
119+
120+
- name: Install CUDAQ build requirements
121+
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
122+
run: |
123+
bash .github/workflows/scripts/install_git_cli.sh
124+
apt install -y --no-install-recommends ccache
125+
shell: bash --noprofile --norc -euo pipefail {0}
126+
127+
- name: Build CUDAQ
128+
if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false'
129+
env:
130+
CCACHE_DIR: /cudaq-ccache
131+
cudaq-build-script: .github/actions/get-cudaq-build/build_cudaq.sh
132+
CUQUANTUM_INSTALL_PREFIX: /cudaq-install
133+
CUTENSOR_INSTALL_PREFIX: /cudaq-install
134+
CUDAQ_INSTALL_PREFIX: /cudaq-install
135+
run: bash ${{ env.cudaq-build-script }} Release ccache gcc-11 g++-11
136+
shell: bash --noprofile --norc -euo pipefail {0}
137+
138+
# ==========================================================================
139+
# Store CUDAQ compilation cache
140+
# ==========================================================================
141+
142+
# We need to delete previous cache entry otherwise the new one won't be stored
143+
- name: Delete previous compilation cache
144+
if: steps.restore-ccache.outputs.cache-hit == 'true' && inputs.save-ccache == 'true'
145+
env:
146+
GH_TOKEN: ${{ github.token }}
147+
run: |
148+
gh cache delete ccache-cudaq --repo ${{ github.repository }}
149+
shell: bash --noprofile --norc -euo pipefail {0}
150+
151+
- name: Store compilation (CCache)
152+
if: steps.check-cache.outputs.valid == 'false' && inputs.save-ccache == 'true' && inputs.lookup-only == 'false'
153+
uses: actions/cache/save@v4
154+
with:
155+
path: /cudaq-ccache
156+
key: ccache-cudaq
157+
158+
159+
# ==========================================================================
160+
# Store CUDAQ build cache
161+
# ==========================================================================
162+
163+
- name: Store CUDAQ build in the cache
164+
if: steps.check-cache.outputs.valid == 'false' && inputs.save-build == 'true' && inputs.lookup-only == 'false'
165+
uses: actions/cache/save@v4
166+
with:
167+
path: /cudaq-install
168+
key: ${{ steps.cudaq-build-key.outputs.main }}${{ steps.cudaq-build-key.outputs.pr }}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# ============================================================================ #
4+
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
5+
# All rights reserved. #
6+
# #
7+
# This source code and the accompanying materials are made available under #
8+
# the terms of the Apache License 2.0 which accompanies this distribution. #
9+
# ============================================================================ #
10+
11+
BUILD_TYPE=${1:-"Release"}
12+
LAUNCHER=${2:-""}
13+
CC=${3:-"gcc"}
14+
CXX=${4:-"g++"}
15+
16+
LLVM_INSTALL_PREFIX=/usr/local/llvm
17+
CUTENSOR_INSTALL_PREFIX=/opt/nvidia/cutensor
18+
19+
cd cudaq
20+
21+
# Determine linker and linker flags
22+
if [ -x "$(command -v "$LLVM_INSTALL_PREFIX/bin/ld.lld")" ]; then
23+
echo "Configuring nvq++ to use the lld linker by default."
24+
NVQPP_LD_PATH="$LLVM_INSTALL_PREFIX/bin/ld.lld"
25+
fi
26+
27+
28+
# Determine CUDA flags
29+
cuda_driver=${CUDACXX:-${CUDA_HOME:-/usr/local/cuda}/bin/nvcc}
30+
31+
if [ -z "$CUDAHOSTCXX" ] && [ -z "$CUDAFLAGS" ]; then
32+
CUDAFLAGS='-allow-unsupported-compiler'
33+
if [ -x "$CXX" ] && [ -n "$("$CXX" --version | grep -i clang)" ]; then
34+
CUDAFLAGS+=" --compiler-options --stdlib=libstdc++"
35+
fi
36+
if [ -d "$GCC_TOOLCHAIN" ]; then
37+
# e.g. GCC_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/
38+
CUDAFLAGS+=" --compiler-options --gcc-toolchain=\"$GCC_TOOLCHAIN\""
39+
fi
40+
fi
41+
42+
# Determine OpenMP flags
43+
if [ -n "$(find "$LLVM_INSTALL_PREFIX" -name 'libomp.so')" ]; then
44+
OMP_LIBRARY=${OMP_LIBRARY:-libomp}
45+
OpenMP_libomp_LIBRARY=${OMP_LIBRARY#lib}
46+
OpenMP_FLAGS="${OpenMP_FLAGS:-'-fopenmp'}"
47+
fi
48+
49+
echo "Preparing CUDA-Q build with LLVM installation in $LLVM_INSTALL_PREFIX..."
50+
cmake_args="-G Ninja \
51+
-DCMAKE_INSTALL_PREFIX='"$CUDAQ_INSTALL_PREFIX"' \
52+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
53+
-DCMAKE_C_COMPILER=$CC \
54+
-DCMAKE_CXX_COMPILER=$CXX \
55+
-DCMAKE_C_COMPILER_LAUNCHER=$LAUNCHER \
56+
-DCMAKE_CXX_COMPILER_LAUNCHER=$LAUNCHER \
57+
-DNVQPP_LD_PATH='"$NVQPP_LD_PATH"' \
58+
-DCMAKE_CUDA_COMPILER='"$cuda_driver"' \
59+
-DCMAKE_CUDA_FLAGS='"$CUDAFLAGS"' \
60+
-DCMAKE_CUDA_HOST_COMPILER='"${CUDAHOSTCXX:-$CXX}"' \
61+
${OpenMP_libomp_LIBRARY:+-DOpenMP_C_LIB_NAMES=lib$OpenMP_libomp_LIBRARY} \
62+
${OpenMP_libomp_LIBRARY:+-DOpenMP_CXX_LIB_NAMES=lib$OpenMP_libomp_LIBRARY} \
63+
${OpenMP_libomp_LIBRARY:+-DOpenMP_libomp_LIBRARY=$OpenMP_libomp_LIBRARY} \
64+
${OpenMP_FLAGS:+"-DOpenMP_C_FLAGS='"$OpenMP_FLAGS"'"} \
65+
${OpenMP_FLAGS:+"-DOpenMP_CXX_FLAGS='"$OpenMP_FLAGS"'"} \
66+
-DCUDAQ_REQUIRE_OPENMP=TRUE \
67+
-DCUDAQ_ENABLE_PYTHON=TRUE \
68+
-DCUDAQ_BUILD_TESTS=FALSE \
69+
-DCUDAQ_TEST_MOCK_SERVERS=FALSE \
70+
-DCMAKE_COMPILE_WARNING_AS_ERROR=OFF"
71+
72+
echo $cmake_args | xargs cmake -S . -B "build"
73+
74+
cmake --build "build" --target install
75+

0 commit comments

Comments
 (0)