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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
name: release
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
version:
description: "Impact"
required: true
default: 'patch'
type: choice
options:
- minor
- patch
dry_run:
description: "Dry run"
required: false
default: false
type: boolean
permissions:
contents: write
jobs:
linux:
if: ${{ github.ref_name != 'master' && startsWith(github.ref_name, 'v') && endsWith(github.ref_name, '.x') }}
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: |
set -euxo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
ccache \
clang \
clang-tidy \
clang-tools \
libopenblas-dev \
pkg-config \
valgrind
cc --version | sed -n '1,2p'
clang --version | sed -n '1,2p'
clang-tidy --version | sed -n '1,2p'
- name: Cache ccache
uses: actions/cache@v4
with:
path: ~/.cache/ccache
key: ccache-${{ runner.os }}-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
ccache-${{ runner.os }}-${{ github.ref_name }}-
ccache-${{ runner.os }}-
- name: Configure ccache
run: |
set -euxo pipefail
ccache --set-config=cache_dir="$HOME/.cache/ccache"
ccache --set-config=max_size=1G
ccache --zero-stats
- name: Run tests
env:
CC: ccache gcc
run: make test
- name: Compute build version
run: |
set -euxo pipefail
git fetch --all --tags
REF_NAME="${GITHUB_REF_NAME:-}"
MAJOR="$(echo "$REF_NAME" | sed -nE 's/^v([0-9]+)\.x$/\1/p')"
if [[ -z "$MAJOR" ]]; then
echo "Invalid branch name format (expected vX.x)" >&2
exit 1
fi
next_version () {
local current impact minor patch
impact="${1:-patch}"
current="$(
git tag \
| grep "^v${MAJOR}\.[0-9]*\.[0-9]*$" \
| sort -t "." -k1,1nr -k2,2nr -k3,3nr \
| cut -c2- \
| head -1
)" || true
if [[ -z "$current" ]]; then
if [[ "$MAJOR" -eq 0 ]]; then
echo "0.0.1"
else
echo "$MAJOR.0.0"
fi
return
fi
IFS='.' read -r _ minor patch <<< "$current"
case "$impact" in
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
*)
echo "Invalid impact: $impact" >&2
exit 1
;;
esac
echo "$MAJOR.$minor.$patch"
}
BUILD_VERSION="$(next_version "${{ inputs.version }}")"
TAG_NAME="v${BUILD_VERSION}"
echo "BUILD_VERSION=$BUILD_VERSION" >> "$GITHUB_ENV"
echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_ENV"
echo "BUILD_VERSION=$BUILD_VERSION"
echo "TAG_NAME=$TAG_NAME"
- name: Install CUDA toolkit
uses: Jimver/cuda-toolkit@v0.2.35
with:
cuda: '12.8.0'
# cuDNN headers for the fused-attention path (libffwd/cuda_sdpa.cu). Only
# the headers are needed: libcudnn is dlopen'd at runtime. The pip wheel is
# the most reliable cross-runner source for them.
- name: Install cuDNN headers
run: |
python3 -m pip install --user nvidia-cudnn-cu12
CUDNN_INC="$(python3 -c 'import os, nvidia.cudnn; print(os.path.join(nvidia.cudnn.__path__[0], "include"))')"
test -f "$CUDNN_INC/cudnn.h"
echo "CUDNN_INC=$CUDNN_INC" >> "$GITHUB_ENV"
- name: Build release artifacts
env:
CC: ccache gcc
run: |
set -euxo pipefail
rm -rf tmp
mkdir -p tmp
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="x86_64" ;;
aarch64) ARCH="aarch64" ;;
*) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
NAME="ffwd-${BUILD_VERSION}-linux-${ARCH}"
NAME_CUDA="${NAME}-cuda"
make cpu \
ARCH_FLAGS="-march=x86-64" \
VERSION="$BUILD_VERSION" \
BUILD_COMMIT="$GITHUB_SHA" \
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" \
BUILD_OS="linux" \
BUILD_ARCH="$ARCH"
mkdir -p "tmp/$NAME"
cp ffwd-cli ffwd-server LICENSE "tmp/$NAME/"
tar -C tmp -czf "tmp/${NAME}.tar.gz" "$NAME"
make gpu \
ARCH_FLAGS="-march=x86-64" \
CUDAFLAGS="-O3 -std=c++17 -gencode arch=compute_89,code=sm_89 -gencode arch=compute_100,code=sm_100 -gencode arch=compute_120,code=sm_120 -Xcompiler -fPIC,-fvisibility=hidden" \
VERSION="$BUILD_VERSION" \
BUILD_COMMIT="$GITHUB_SHA" \
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" \
BUILD_OS="linux" \
BUILD_ARCH="$ARCH"
mkdir -p "tmp/$NAME_CUDA"
cp ffwd-cli ffwd-server LICENSE "tmp/$NAME_CUDA/"
tar -C tmp -czf "tmp/${NAME_CUDA}.tar.gz" "$NAME_CUDA"
cd tmp
sha256sum *.tar.gz > SHA256SUMS
- name: Upload artifacts (dry run)
if: ${{ inputs.dry_run }}
uses: actions/upload-artifact@v4
with:
name: release-artifacts
path: tmp/
- name: Release
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euxo pipefail
if [[ -z "${TAG_NAME:-}" ]]; then
echo "No tag name computed; refusing to release" >&2
exit 1
fi
commit="$(git rev-parse HEAD)"
if git tag --points-at "$commit" | grep -q "^${TAG_NAME}$"; then
echo "Commit already has tag $TAG_NAME, skipping release"
exit 0
fi
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists, refusing to overwrite" >&2
exit 1
fi
git config user.name github-actions
git config user.email github-actions@github.com
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
gh release create "$TAG_NAME" \
tmp/ffwd-$BUILD_VERSION-linux-*.tar.gz \
tmp/SHA256SUMS \
--title "$TAG_NAME" \
--generate-notes
- name: Show ccache stats
if: always()
run: ccache --show-stats || true
|