-
Notifications
You must be signed in to change notification settings - Fork 121
282 lines (257 loc) · 12.2 KB
/
Copy pathspacemit3.6-build-and-test.yml
File metadata and controls
282 lines (257 loc) · 12.2 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: Spacemit3.6-Build-And-Test
# SpaceMiT RISC-V 后端 CI (root-triton plugin)。
#
# 执行环境: self-hosted runner (label spacemit3.6)。
# RPC 执行: jdsk-qemu v10.0.2 用户态模拟 (-cpu max,vlen=1024,elen=64,vext_spec=v1.0)
# 跑 spine-rpc-server, host triton 交叉编译 kernel 后通过 TCP 9999 发给 QEMU 执行。
# LLVM / spine-mlir / spine-runtime / rpc-runtime / toolchain / jdsk-qemu 从
# zuoweixia497/spacemit-ci-assets GitHub release (及 archive.spacemit.com) 下载并缓存。
# 更新包: 修改 third_party/spacemit/spacemit-ci.env 里的 URL+MD5 即可。
on:
workflow_dispatch:
push:
branches: [ "main", "triton_v3.6.x" ]
pull_request:
branches: [ "main", "triton_v3.6.x" ]
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: false
jobs:
spacemit36x-unit-test:
runs-on: spacemit3.6
env:
MAX_JOBS: 4
RPC_PORT: "9999"
steps:
- name: Smart Checkout
uses: flagos-ai/FlagTree/.github/actions/smart-checkout@main
with:
checkout_version: 'v6'
- name: Check if backend-relevant files changed
id: check_backend
uses: flagos-ai/FlagTree/.github/actions/check-backend-changed@main
with:
backend: spacemit
- name: Load CI variables
if: steps.check_backend.outputs.should_skip != 'true'
run: grep -v '^\s*#' third_party/spacemit/spacemit-ci.env | grep -v '^\s*$' >> $GITHUB_ENV
- name: Cache RV toolchain
if: steps.check_backend.outputs.should_skip != 'true'
id: cache-rv-toolchain
uses: actions/cache@v6
with:
path: toolchain
key: rv-toolchain-${{ env.RISCV_TOOLCHAIN_MD5 }}
- name: Download and extract RV toolchain
if: steps.check_backend.outputs.should_skip != 'true' && steps.cache-rv-toolchain.outputs.cache-hit != 'true'
run: |
curl -k -L --retry 5 --retry-delay 5 --retry-all-errors -o spacemit-toolchain.tar.xz "$RISCV_TOOLCHAIN_URL"
mkdir -p toolchain
tar -xf spacemit-toolchain.tar.xz -C toolchain --strip-components=1
rm spacemit-toolchain.tar.xz
- name: Cache LLVM
if: steps.check_backend.outputs.should_skip != 'true'
id: cache-llvm
uses: actions/cache@v6
with:
path: llvm_installed
key: llvm-${{ env.LLVM_MD5 }}
- name: Download and extract LLVM
if: steps.check_backend.outputs.should_skip != 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
run: |
curl -k -L --retry 5 --retry-delay 5 --retry-all-errors -o llvm.tar.gz "$LLVM_URL"
mkdir -p llvm_installed
tar -xf llvm.tar.gz -C llvm_installed --strip-components=1
rm llvm.tar.gz
- name: Cache spine-mlir
if: steps.check_backend.outputs.should_skip != 'true'
id: cache-spine-mlir
uses: actions/cache@v6
with:
path: spine_mlir_installed
key: spine-mlir-${{ env.SPINE_MLIR_MD5 }}
- name: Download and extract spine-mlir
if: steps.check_backend.outputs.should_skip != 'true' && steps.cache-spine-mlir.outputs.cache-hit != 'true'
run: |
curl -k -L --retry 5 --retry-delay 5 --retry-all-errors -o spine-mlir.tar.gz "$SPINE_MLIR_URL"
mkdir -p spine_mlir_installed
tar -xf spine-mlir.tar.gz -C spine_mlir_installed --strip-components=1
rm spine-mlir.tar.gz
- name: Cache spine-runtime
if: steps.check_backend.outputs.should_skip != 'true'
id: cache-spine-runtime
uses: actions/cache@v6
with:
path: spine_runtime_installed
key: spine-runtime-${{ env.SPINE_RUNTIME_MD5 }}
- name: Download and extract spine-runtime
if: steps.check_backend.outputs.should_skip != 'true' && steps.cache-spine-runtime.outputs.cache-hit != 'true'
run: |
curl -k -L --retry 5 --retry-delay 5 --retry-all-errors -o spine-runtime.tar.gz "$SPINE_RUNTIME_URL"
mkdir -p spine_runtime_installed
tar -xf spine-runtime.tar.gz -C spine_runtime_installed --strip-components=1
rm spine-runtime.tar.gz
- name: Cache RPC runtime
if: steps.check_backend.outputs.should_skip != 'true'
id: cache-rpc-runtime
uses: actions/cache@v6
with:
path: rpc_runtime_installed
key: rpc-runtime-${{ env.RPC_RUNTIME_MD5 }}
- name: Download and extract RPC runtime
if: steps.check_backend.outputs.should_skip != 'true' && steps.cache-rpc-runtime.outputs.cache-hit != 'true'
run: |
curl -k -L --retry 5 --retry-delay 5 --retry-all-errors -o rpc-runtime.tar.gz "$RPC_RUNTIME_URL"
mkdir -p rpc_runtime_installed
tar -xf rpc-runtime.tar.gz -C rpc_runtime_installed --strip-components=1
rm rpc-runtime.tar.gz
- name: Cache jdsk-qemu
if: steps.check_backend.outputs.should_skip != 'true'
id: cache-qemu
uses: actions/cache@v6
with:
path: jdsk-qemu
key: jdsk-qemu-${{ env.JDSK_QEMU_MD5 }}
- name: Download and extract jdsk-qemu
if: steps.check_backend.outputs.should_skip != 'true' && steps.cache-qemu.outputs.cache-hit != 'true'
run: |
curl -k -L --retry 5 --retry-delay 5 --retry-all-errors -o jdsk-qemu.tar.gz "$JDSK_QEMU_URL"
tar -xf jdsk-qemu.tar.gz
rm jdsk-qemu.tar.gz
- name: Build (apply flagtree.patch + pip install)
if: steps.check_backend.outputs.should_skip != 'true'
run: |
set -euo pipefail
NEED=""
python3 -c 'import ensurepip' 2>/dev/null || NEED="$NEED python3.12-venv"
[ -e /usr/lib/x86_64-linux-gnu/libzstd.so ] || NEED="$NEED libzstd-dev"
if [ -n "$NEED" ]; then apt-get update -qq && apt-get install -y -qq $NEED; fi
python3 -m venv --system-site-packages .venv-ci
source .venv-ci/bin/activate
python -m pip install --quiet --upgrade pip cmake ninja pybind11 setuptools wheel
LLVM_SYSPATH="$(pwd)/llvm_installed" \
SPINE_MLIR_INSTALL_DIR="$(pwd)/spine_mlir_installed" \
SPINE_RUNTIME_INSTALL_DIR="$(pwd)/spine_runtime_installed" \
MAX_JOBS="${MAX_JOBS:-4}" PIP="python -m pip" \
bash third_party/spacemit/scripts/install_flagtree_plugin.sh
- name: Start QEMU RPC server (jdsk-qemu)
if: steps.check_backend.outputs.should_skip != 'true'
run: |
set -euo pipefail
QEMU_BIN="$(pwd)/jdsk-qemu/bin/qemu-riscv64"
SYSROOT="$(pwd)/toolchain/sysroot"
RPC_DIR="$(pwd)/rpc_runtime_installed"
chmod +x "$QEMU_BIN" 2>/dev/null || true
# sanity: confirm the rpc-server binary and qemu exist
test -f "$QEMU_BIN" || { echo "ERROR: qemu not found at $QEMU_BIN" >&2; exit 1; }
test -f "$RPC_DIR/bin/spine-rpc-server" || { echo "ERROR: rpc-server not found" >&2; exit 1; }
"$QEMU_BIN" --version
# launch spine-rpc-server under jdsk-qemu (RISC-V user-mode emulation on x86 runner)
setsid bash -c "
exec '$QEMU_BIN' -L '$SYSROOT' \
-cpu max,vlen=1024,elen=64,vext_spec=v1.0 \
-E LD_LIBRARY_PATH='$RPC_DIR/lib:$SYSROOT/lib:$SYSROOT/usr/lib' \
'$RPC_DIR/bin/spine-rpc-server' ${RPC_PORT}
" > /tmp/rpc.log 2>&1 &
echo $! > /tmp/rpc_server.pid
# wait for the port to accept connections
for i in $(seq 1 60); do
if python3 -c "import socket,sys; sys.exit(0 if socket.socket().connect_ex(('127.0.0.1',${RPC_PORT}))==0 else 1)" 2>/dev/null; then
echo "RPC server ready on 127.0.0.1:${RPC_PORT} (${i}s)"
exit 0
fi
# bail early if the server process died
if ! kill -0 $(cat /tmp/rpc_server.pid) 2>/dev/null; then
echo "ERROR: rpc-server process exited early" >&2
cat /tmp/rpc.log 2>/dev/null || true
exit 1
fi
sleep 1
done
echo "ERROR: RPC server did not come up on port ${RPC_PORT}" >&2
cat /tmp/rpc.log 2>/dev/null || true
exit 1
- name: Minimal smoke test (import + spacemit backend + QEMU RPC)
if: steps.check_backend.outputs.should_skip != 'true'
run: |
set -euo pipefail
source .venv-ci/bin/activate
export SPINE_TRITON_TARGET_ARCH=riscv64
export SPINE_TRITON_CROSS_TOOLCHAIN="$(pwd)/toolchain"
export SPACEMIT_EP_QEMU_SET_CORE_ARCH=0xA064
export GEMS_VENDOR=spacemit
export SPINE_TRITON_RPC_HOST=127.0.0.1
export SPINE_TRITON_RPC_PORT=${RPC_PORT}
python - <<'PY'
import os, socket, sys
def check(desc, cond, detail=""):
print(f"[{'OK ' if cond else 'FAIL'}] {desc}" + (f" ({detail})" if detail else ""))
return cond
ok = True
import triton
ok &= check("import triton", True, f"version={triton.__version__}")
from triton.backends import backends
names = sorted(backends.keys())
ok &= check("spacemit backend registered", "spacemit" in names, f"backends={names}")
b = backends["spacemit"]
ok &= check("compiler/driver",
b.compiler.__name__ == "CPUBackend" and b.driver.__name__ == "CPUDriver",
f"{b.compiler.__name__}/{b.driver.__name__}")
from triton._C.libtriton import ir, spacemit
pads = [x for x in dir(ir.PADDING_OPTION) if x.startswith("PAD")]
ok &= check("PADDING_OPTION adapt", {"PAD_NEG_INF","PAD_INF"} <= set(pads), f"pads={pads}")
sub = [a for a in dir(spacemit) if not a.startswith("__")]
ok &= check("spacemit C++ submod", {"load_dialects","tle_ir","xsmt_ir"} <= set(sub), f"sub={sub}")
host = os.environ.get("SPINE_TRITON_RPC_HOST","127.0.0.1")
port = int(os.environ.get("SPINE_TRITON_RPC_PORT","9999"))
s = socket.socket(); s.settimeout(5)
ok &= check("QEMU RPC reachable", s.connect_ex((host,port))==0, f"{host}:{port}")
print()
print("=== minimal smoke: " + ("ALL PASS" if ok else "FAILED") + " ===")
sys.exit(0 if ok else 1)
PY
- name: Test
# Run mm_block_ptr.py: host triton cross-compiles the kernel to riscv64,
# sends it to the QEMU RPC server for execution, and checks the result.
if: steps.check_backend.outputs.should_skip != 'true'
run: |
set -euo pipefail
source .venv-ci/bin/activate
python -m pip install --quiet pytest numpy scipy PyYAML
export SPINE_TRITON_TARGET_ARCH=riscv64
export SPINE_TRITON_CROSS_TOOLCHAIN="$(pwd)/toolchain"
export SPACEMIT_EP_QEMU_SET_CORE_ARCH=0xA064
export GEMS_VENDOR=spacemit
export SPINE_TRITON_RPC_HOST=127.0.0.1
export SPINE_TRITON_RPC_PORT=${RPC_PORT}
export SPINE_TRITON_DUMP_PATH="$(pwd)/triton_dump"
mkdir -p "$SPINE_TRITON_DUMP_PATH"
python third_party/spacemit/python/examples/mm_block_ptr.py
- name: Dump RPC server log + compiled IR (on failure)
if: failure() && steps.check_backend.outputs.should_skip != 'true'
run: |
echo "--- rpc-server process ---"
if [ -f /tmp/rpc_server.pid ]; then
ps -p "$(cat /tmp/rpc_server.pid)" 2>/dev/null || echo "process not running"
fi
echo "--- /tmp/rpc.log ---"
cat /tmp/rpc.log 2>/dev/null || true
echo "=== triton_dump dir ==="
ls -la triton_dump/ 2>/dev/null || true
echo "=== dump file contents ==="
for f in triton_dump/*; do
[ -f "$f" ] || continue
echo "--- $f ---"
head -200 "$f"
done
- name: Stop QEMU RPC server
if: always() && steps.check_backend.outputs.should_skip != 'true'
run: |
if [ -f /tmp/rpc_server.pid ]; then
kill "$(cat /tmp/rpc_server.pid)" 2>/dev/null || true
fi
pkill -f "spine-rpc-server" 2>/dev/null || true