Repository navigation
Expand file tree
/
Copy pathDockerfile.vulkan
More file actions
139 lines (126 loc) · 6.47 KB
/
Copy pathDockerfile.vulkan
File metadata and controls
139 lines (126 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Build environment for voxtype Vulkan binary
# Uses Ubuntu 22.04 to ensure no AVX-512/GFNI instructions leak from toolchain
#
# NOTE: This build can take 30+ minutes due to Kompute shader compilation.
# If it hangs, the issue is likely glslang/shaderc compatibility.
#
# Usage:
# docker build -f Dockerfile.vulkan -t voxtype-vulkan-builder .
# docker run --rm -v $(pwd)/releases:/output voxtype-vulkan-builder
#
FROM ubuntu:24.04
ARG VERSION=0.6.1
ARG DEBIAN_FRONTEND=noninteractive
# Make VERSION available at runtime
ENV VERSION=${VERSION}
# Retry apt. Acquire::Retries covers connection errors; the loop covers a 404
# or a size mismatch while an Ubuntu mirror is mid-sync.
RUN printf 'Acquire::Retries "5";\nAcquire::http::Timeout "30";\n' \
> /etc/apt/apt.conf.d/80-voxtype-retries
# Install build dependencies including Vulkan SDK (24.04 has glslc in repos)
RUN for attempt in 1 2 3 4; do apt-get update && apt-get install -y \
curl \
build-essential \
clang \
cmake \
pkg-config \
libasound2-dev \
libx11-dev \
libxi-dev \
libxtst-dev \
libgtk-3-dev \
libglib2.0-dev \
libappindicator3-dev \
git \
binutils \
libvulkan-dev \
vulkan-tools \
glslang-tools \
spirv-tools \
libshaderc-dev \
glslc \
&& break; \
[ "$attempt" = 4 ] && exit 1; \
echo "apt failed (attempt $attempt), mirror may be syncing; retrying in 90s"; \
if [ "$attempt" = 2 ]; then echo "switching apt to azure.archive.ubuntu.com"; sed -i -E 's#https?://(archive|security)\.ubuntu\.com#http://azure.archive.ubuntu.com#g' /etc/apt/sources.list /etc/apt/sources.list.d/*.sources 2>/dev/null || true; fi; \
rm -rf /var/lib/apt/lists/*; sleep 90; \
done && rm -rf /var/lib/apt/lists/*
# Install Rust via rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Set working directory
WORKDIR /build
# Copy source code
COPY . .
# Force single-threaded builds to prevent cmake deadlocks
ENV CARGO_BUILD_JOBS=1
ENV CMAKE_BUILD_PARALLEL_LEVEL=1
ENV MAKEFLAGS="-j1"
# Build flags: bound the ISA floor at Haswell so the binary runs on every
# x86_64-v3 CPU (Kaby Lake, Zen 2/3, etc.). target-cpu=native was safe when
# this built on a pre-AVX-512 host (i9-9900K, Coffee Lake), but the GitHub
# Actions ubuntu-24.04 runner is Zen 3 with SHA Extensions / VAES / AES-NI,
# and those instructions SIGILL on Kaby Lake — see issue #393.
# Disable LTO to prevent linking hangs.
ENV RUSTFLAGS="-C target-cpu=haswell -C target-feature=-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl,-gfni,-sse4a,-avxvnni -C lto=off -C codegen-units=8"
# whisper.cpp/ggml flags: match Dockerfile.build's Haswell bound. NATIVE=ON
# inherits -march=native from CMake's host detection, which on a Zen 3 runner
# emits the same forbidden instructions the SIGILL handler ends up catching.
ENV GGML_NATIVE=OFF
ENV GGML_AVX512=OFF
ENV GGML_AVX_VNNI=OFF
ENV GGML_AVX512_VNNI=OFF
ENV CMAKE_C_FLAGS="-mno-avx512f -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-gfni -mno-avxvnni -mno-sha -mno-vaes -mno-vpclmulqdq"
ENV CMAKE_CXX_FLAGS="-mno-avx512f -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-gfni -mno-avxvnni -mno-sha -mno-vaes -mno-vpclmulqdq"
# Build Vulkan binary (verbose to show progress)
# Override Cargo.toml's LTO settings to prevent linking hangs
RUN cargo build --release --features gpu-vulkan \
--config 'profile.release.lto=false' \
--config 'profile.release.codegen-units=8' \
-vv 2>&1 | tee /tmp/build.log \
&& cp target/release/voxtype /tmp/voxtype-vulkan \
&& cargo build --release -p voxtype-gguf-worker --features vulkan \
--config 'profile.release.lto=false' \
--config 'profile.release.codegen-units=8' \
&& cp target/release/voxtype-gguf-worker /tmp/voxtype-gguf-worker
# Verify no out-of-floor instructions leaked in. The ISA floor is x86_64-v3
# (Haswell): AVX2 + BMI1/2 + FMA, no AVX-512, no GFNI, no AVX-VNNI, and no
# SSE4a (AMD-only — would SIGILL on Intel). NOTE: SHA-NI / VAES (ymm) /
# VPCLMULQDQ (ymm) are deliberately NOT checked here — those instructions
# appear in every binary as part of the sha2/aes crates' cpufeatures-dispatched
# runtime paths, and are guarded by CPUID checks at the library level. Adding
# them to this gate would produce false positives. Instead we constrain the
# Rust compiler's own emission via target-cpu=haswell + target-feature
# disables above, which is what stops issue-#393-style leaks.
RUN echo "=== Verifying Vulkan binary ISA floor (x86_64-v3 / Haswell, no SSE4a) ===" \
&& DUMP=$(objdump -d /tmp/voxtype-vulkan; objdump -d /tmp/voxtype-gguf-worker) \
&& zmm_count=$(echo "$DUMP" | grep -c zmm || true) \
&& avx512_count=$(echo "$DUMP" | grep -cE 'vpternlog|vpermt2|vpermi2|vpblendm|valign[dq]|vpcompress|vpexpand' || true) \
&& broadcast_count=$(echo "$DUMP" | grep -c '{1to' || true) \
&& gfni_count=$(echo "$DUMP" | grep -cE '\b(vgf2p8|gf2p8)' || true) \
&& sse4a_count=$(echo "$DUMP" | grep -cE '\b(insertq|extrq)\b' || true) \
&& avxvnni_count=$(echo "$DUMP" | grep -cE '\bvpdpbus(d|ds)|vpdpwss(d|ds)' || true) \
&& echo " zmm registers: $zmm_count" \
&& echo " AVX-512 EVEX: $avx512_count" \
&& echo " AVX-512 broadcast: $broadcast_count" \
&& echo " GFNI: $gfni_count" \
&& echo " SSE4a (AMD-only): $sse4a_count" \
&& echo " AVX-VNNI: $avxvnni_count" \
&& if [ "${zmm_count:-0}" -gt 0 ] || [ "${avx512_count:-0}" -gt 0 ] \
|| [ "${broadcast_count:-0}" -gt 0 ] || [ "${gfni_count:-0}" -gt 0 ] \
|| [ "${sse4a_count:-0}" -gt 0 ] || [ "${avxvnni_count:-0}" -gt 0 ]; then \
echo "ERROR: Vulkan binary contains out-of-floor instructions — will SIGILL on Intel Kaby Lake, Zen 1, etc." \
&& exit 1; \
fi \
&& echo "✓ Vulkan binary is clean"
# gpu-vulkan implies the GGUF client features; prove the shipped pair agrees.
RUN scripts/verify-gguf-companion.sh --vulkan --haswell-floor --run \
/tmp/voxtype-vulkan /tmp/voxtype-gguf-worker
# Output stage - copy binary to /output volume
CMD mkdir -p /output \
&& cp /tmp/voxtype-vulkan /output/voxtype-${VERSION}-linux-x86_64-vulkan \
&& cp /tmp/voxtype-gguf-worker /output/voxtype-${VERSION}-linux-x86_64-vulkan.gguf-worker \
&& chmod 755 /output/voxtype-${VERSION}-linux-x86_64-vulkan \
&& chmod 755 /output/voxtype-${VERSION}-linux-x86_64-vulkan.gguf-worker \
&& echo "Binary copied to /output:" \
&& ls -la /output/voxtype-*-vulkan