Skip to content

Commit 6c2676e

Browse files
authored
Work around CUDA 12 GCC 12 BF16 headers in realtime builds (#705)
CUDA-QX builds CUDA-Q's realtime library from the revision pinned in .cudaq_version. A CUDA-Q devcontainer update started honoring its GCC 12 CXX selection through CUDAHOSTCXX. CUDA 12.6 nvcc then fails while parsing GCC 12's AVX-512 BF16 intrinsic headers, before compiling CUDA-Q realtime's host dispatcher. Keep the compatibility workaround in CUDA-QX, which orchestrates these dependency builds. Add a small shared helper that appends the two GCC BF16 header guards only when nvcc is CUDA 12, the host is x86-64, and the selected C++ compiler is GCC 12. CUDA-Q realtime does not use those intrinsics, so this prevents nvcc from parsing unsupported builtin declarations without changing CUDA-Q source or replacing the selected host compiler. Use that helper for the QEC CI dependency build, the All Libs release artifact build, and the documented realtime rebuild script used by the CUDA-Q build action and install helper. Include the helper in the CUDA-Q build-cache key so a compatibility change cannot reuse a stale realtime build. The release Dockerfile only overlays those artifacts, so covering the release build makes the published CUDA 12.6 image complete; normal CUDA-QX source builds in that image use the bundled realtime installation and do not rebuild it. Verified with shell syntax checks and a container test of all helper gates. The exact CUDA-Q revision pinned by CUDA-QX fails with nine BF16 builtin errors under CUDA 12.6/GCC 12.4 without the definitions and compiles with them. A full CMake configure remains unavailable in PR695 because it has CMake 3.28 while the pinned CUDA-Q revision requires CMake 4. --------- Signed-off-by: Melody Ren <melodyr@nvidia.com>
1 parent 7c012df commit 6c2676e

6 files changed

Lines changed: 33 additions & 1 deletion

File tree

.github/actions/build-lib/build_qec.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -e
33

44
. "$(dirname "$0")/setup_custabilizer.sh"
5+
. "$(dirname "$0")/../../../scripts/cudaq_realtime_cmake_flags.sh"
56

67
build_dir=$1
78
install_prefix=$2
@@ -100,7 +101,9 @@ if [ -z "$CUDAQ_REALTIME_ROOT" ]; then
100101
# which produces libcudaq-realtime-bridge-hololink.so needed by the bridge.
101102
cd /tmp/cudaq-realtime-src/realtime
102103
mkdir -p build && cd build
104+
103105
cmake -G Ninja -DCMAKE_INSTALL_PREFIX="$CUDAQ_REALTIME_ROOT" \
106+
-DCMAKE_CUDA_FLAGS="$(cudaq_realtime_cmake_cuda_flags)" \
104107
-DCUDAQ_REALTIME_ENABLE_HOLOLINK_TOOLS=ON \
105108
-DHOLOSCAN_SENSOR_BRIDGE_SOURCE_DIR=$HSB_ROOT \
106109
-DHOLOSCAN_SENSOR_BRIDGE_BUILD_DIR=$HSB_BUILD \

.github/actions/get-cudaq-build/action.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ runs:
5151
to_hash: |
5252
.github/actions/get-cudaq-build/**
5353
scripts/build_cudaq_with_realtime.sh
54+
scripts/cudaq_realtime_cmake_flags.sh
5455
.cudaq_version
5556
run: |
5657
hash=${{ hashFiles(format('{0}', env.to_hash)) }}

.github/workflows/all_libs_release.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108

109109
- name: Build cuda-quantum realtime
110110
run: |
111+
source "$GITHUB_WORKSPACE/scripts/cudaq_realtime_cmake_flags.sh"
111112
CUDAQ_REPO="${{ steps.get-cudaq-version.outputs.repo }}"
112113
CUDAQ_REF="${{ steps.get-cudaq-version.outputs.ref }}"
113114
CUDAQ_REALTIME_ROOT=/tmp/cudaq-realtime
@@ -119,7 +120,9 @@ jobs:
119120
git sparse-checkout set realtime cmake
120121
git checkout "$CUDAQ_REF"
121122
cd realtime && mkdir -p build && cd build
122-
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$CUDAQ_REALTIME_ROOT ..
123+
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$CUDAQ_REALTIME_ROOT \
124+
-DCMAKE_CUDA_FLAGS="$(cudaq_realtime_cmake_cuda_flags)" \
125+
..
123126
ninja && ninja install
124127
echo "CUDAQ_REALTIME_ROOT=$CUDAQ_REALTIME_ROOT" >> $GITHUB_ENV
125128
shell: bash

docker/build_env/cudaqx.dev.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RUN apt-get update && CUDA_DASH=$(echo $cuda_version | tr '.' '-') \
2323

2424
COPY .cudaq_version /cudaq_version
2525
COPY scripts/build_cudaq_with_realtime.sh /usr/local/bin/build_cudaq_with_realtime.sh
26+
COPY scripts/cudaq_realtime_cmake_flags.sh /usr/local/bin/cudaq_realtime_cmake_flags.sh
2627

2728
ENV CUDAQ_INSTALL_PREFIX=/usr/local/cudaq
2829

scripts/build_cudaq_with_realtime.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ set -euo pipefail
2323

2424
log() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
2525

26+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
27+
. "$script_dir/cudaq_realtime_cmake_flags.sh"
28+
2629
BUILD_TYPE=${1:-"Release"}
2730
CC=${2:-${CC:-"gcc"}}
2831
CXX=${3:-${CXX:-"g++"}}
@@ -39,6 +42,7 @@ log "Building cudaq-realtime from $CUDAQ_SRC/realtime"
3942
cmake -G Ninja -S "$CUDAQ_SRC/realtime" -B "$CUDAQ_SRC/realtime/build" \
4043
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
4144
-DCMAKE_INSTALL_PREFIX="$CUDAQ_INSTALL_PREFIX" \
45+
-DCMAKE_CUDA_FLAGS="$(cudaq_realtime_cmake_cuda_flags)" \
4246
-DCUDAQ_REALTIME_BUILD_TESTS=OFF \
4347
-DCUDAQ_REALTIME_BUILD_EXAMPLES=OFF \
4448
-DCUDAQ_REALTIME_ENABLE_HOLOLINK_TOOLS=OFF
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
# CMake flags required when CUDA-QX builds CUDA-Q's realtime dependency.
4+
cudaq_realtime_cmake_cuda_flags() {
5+
_cudaq_realtime_cuda_flags="${CMAKE_CUDA_FLAGS:-}"
6+
_cudaq_realtime_host_cxx="${CXX:-c++}"
7+
_cudaq_realtime_host_cxx_major=$("$_cudaq_realtime_host_cxx" -dumpversion 2>/dev/null | cut -d. -f1)
8+
_cudaq_realtime_cuda_major=$(nvcc --version 2>/dev/null |
9+
sed -n 's/^.*release \([0-9][0-9]*\)\..*$/\1/p')
10+
11+
# CUDA 12's nvcc frontend cannot parse GCC 12's AVX-512 BF16 intrinsic
12+
# headers. CUDA-Q realtime does not use those intrinsics, so defining the
13+
# headers' include guards keeps them out of the nvcc parse.
14+
if [ "$(uname -m)" = x86_64 ] && [ "$_cudaq_realtime_cuda_major" = 12 ] && \
15+
[ "$_cudaq_realtime_host_cxx_major" = 12 ]; then
16+
_cudaq_realtime_cuda_flags="${_cudaq_realtime_cuda_flags} -D_AVX512BF16INTRIN_H_INCLUDED -D_AVX512BF16VLINTRIN_H_INCLUDED"
17+
fi
18+
19+
printf '%s' "$_cudaq_realtime_cuda_flags"
20+
}

0 commit comments

Comments
 (0)