-
Notifications
You must be signed in to change notification settings - Fork 0
354 lines (315 loc) · 14.7 KB
/
Copy pathruntime-build.yml
File metadata and controls
354 lines (315 loc) · 14.7 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
name: runtime-build
on:
push:
paths:
- 'ntt/**'
- '.github/workflows/runtime-build.yml'
pull_request:
paths:
- 'ntt/**'
- '.github/workflows/runtime-build.yml'
schedule:
- cron: '0 16 * * *'
workflow_dispatch:
concurrency:
group: runtime-build-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/heads/release/') }}
jobs:
build-native-runtime:
if: ${{ github.event_name != 'schedule' }}
name: build-runtime-${{matrix.config.name}}
runs-on: ${{matrix.config.os}}
strategy:
fail-fast: false
matrix:
config:
- { name: aarch64-macos, os: macos-14, buildType: Release, coverage: false, profile: aarch64-macos, arch: arm64, toolchainPrefix: '', toolchainFile: '' }
- { name: x86_64-linux, os: ubuntu-24.04, buildType: Release, coverage: false, profile: x86_64-linux, arch: x64, toolchainPrefix: '', toolchainFile: '' }
# - { name: x86_64-windows, os: windows-latest, arch: x64, buildType: Release }
steps: &native_runtime_steps
- uses: actions/checkout@v3
- uses: seanmiddleditch/gha-setup-ninja@master
- name: Cleanup runner
uses: ./.github/actions/cleanup-runner
if: runner.os == 'Linux'
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 16
if: runner.os == 'Linux'
- name: Set up build environment (Windows, Visual Studio)
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{matrix.config.arch}}
if: runner.os == 'Windows'
- name: Set up build environment (Linux)
run: |
echo "CC=gcc-14" >> $GITHUB_ENV
echo "CXX=g++-14" >> $GITHUB_ENV
if: runner.os == 'Linux'
- name: Install coverage tools (Linux)
if: runner.os == 'Linux' && matrix.config.coverage == true
run: |
sudo apt-get update
sudo apt-get install -y lcov
- name: Install coverage tools (macOS)
if: runner.os == 'macOS' && matrix.config.coverage == true
run: |
brew install lcov
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Conan
run: |
pip install conan==2.6.0
pip install cmake==3.30.3
conan remote add sunnycase https://conan.sunnycase.moe --index 0
conan remote update conancenter --url "https://center2.conan.io"
- name: Configure
shell: bash
env:
COVERAGE: ${{ matrix.config.coverage }}
run: |
conan install . --build=missing -s build_type=${{matrix.config.buildType}} -pr:a=toolchains/${{matrix.config.profile}}.profile.jinja -o "&:runtime=True" -o "&:python=True" -o "&:tests=True"
if [ "$COVERAGE" = "true" ]; then
if [ "$RUNNER_OS" = "macOS" ]; then
cmake --preset conan-runtime-release \
"-DCMAKE_C_FLAGS=-fprofile-instr-generate -fcoverage-mapping" \
"-DCMAKE_CXX_FLAGS=-fprofile-instr-generate -fcoverage-mapping" \
"-DCMAKE_EXE_LINKER_FLAGS=-fprofile-instr-generate" \
"-DCMAKE_SHARED_LINKER_FLAGS=-fprofile-instr-generate"
else
cmake --preset conan-runtime-release \
-DCMAKE_C_FLAGS=--coverage \
-DCMAKE_CXX_FLAGS=--coverage \
-DCMAKE_EXE_LINKER_FLAGS=--coverage
fi
else
cmake --preset conan-runtime-release
fi
- name: Build & Install
run: |
cmake --build build/${{matrix.config.buildType}} --config ${{matrix.config.buildType}}
cmake --install build/${{matrix.config.buildType}} --prefix install
- name: Test
env:
COVERAGE: ${{ matrix.config.coverage }}
run: |
BUILD_DIR="build/${{matrix.config.buildType}}"
if [ "$COVERAGE" = "true" ] && [ "$RUNNER_OS" = "macOS" ]; then
WORKSPACE=$(pwd)
PROFILE_DIR="$BUILD_DIR/coverage"
mkdir -p "$WORKSPACE/$PROFILE_DIR"
export LLVM_PROFILE_FILE="$WORKSPACE/$PROFILE_DIR/%p.profraw"
fi
cd "$BUILD_DIR"
ctest -C ${{matrix.config.buildType}} --test-dir ntt/test/ctest --output-on-failure -j4
if: runner.os != 'Windows'
- name: Capture runtime coverage
if: matrix.config.coverage == true
run: |
BUILD_DIR="build/${{ matrix.config.buildType }}"
COVERAGE_RAW="$BUILD_DIR/runtime.coverage.raw.info"
COVERAGE_INFO="$BUILD_DIR/runtime.coverage.info"
if [ "$RUNNER_OS" = "macOS" ]; then
PROFILE_DIR="$BUILD_DIR/coverage"
if [ ! -d "$PROFILE_DIR" ]; then
echo "Profile directory $PROFILE_DIR not found" >&2
exit 1
fi
shopt -s nullglob
PROFRAW_FILES=("$PROFILE_DIR"/*.profraw)
shopt -u nullglob
if [ ${#PROFRAW_FILES[@]} -eq 0 ]; then
echo "No .profraw files captured" >&2
exit 1
fi
MERGED_PROFILE="$BUILD_DIR/runtime.coverage.profdata"
xcrun llvm-profdata merge -sparse "${PROFRAW_FILES[@]}" -o "$MERGED_PROFILE"
OBJECTS=$(find "$BUILD_DIR" -type f \
\( -perm -111 -o -name '*.dylib' -o -name '*.a' \))
if [ -z "$OBJECTS" ]; then
echo "No binaries found for llvm-cov export" >&2
exit 1
fi
xcrun llvm-cov export -format=lcov \
-instr-profile="$MERGED_PROFILE" \
--ignore-filename-regex='^/usr/|/Applications/Xcode/' \
$OBJECTS > "$COVERAGE_INFO"
xcrun llvm-cov report \
-instr-profile="$MERGED_PROFILE" \
--ignore-filename-regex='^/usr/|/Applications/Xcode/' \
$OBJECTS
else
GCOV_TOOL="${{ matrix.config.gcovTool }}"
if [ -z "$GCOV_TOOL" ] && [ -n "${{ matrix.config.toolchainPrefix }}" ]; then
GCOV_TOOL="$GITHUB_WORKSPACE/${{ matrix.config.toolchainFile }}/bin/${{ matrix.config.toolchainPrefix }}gcov"
fi
if [ -n "$GCOV_TOOL" ]; then
if [[ "$GCOV_TOOL" != /* ]] && [ -f "$GITHUB_WORKSPACE/$GCOV_TOOL" ]; then
GCOV_TOOL="$GITHUB_WORKSPACE/$GCOV_TOOL"
fi
GCOV_ARG="--gcov-tool $GCOV_TOOL"
fi
LCOV_IGNORE_LIST="mismatch,inconsistent,format,unsupported,unused,corrupt,negative"
LCOV_IGNORE="--ignore-errors $LCOV_IGNORE_LIST"
lcov ${GCOV_ARG:-} $LCOV_IGNORE --capture --directory "$BUILD_DIR" --output-file "$COVERAGE_RAW"
lcov $LCOV_IGNORE --remove "$COVERAGE_RAW" '/usr/*' 'ntt/test/*' '/opt/hostedtoolcache/*' '*/.conan2/*' --output-file "$COVERAGE_INFO"
# Emit a short summary without requiring the original source tree on the runner
lcov $LCOV_IGNORE --summary "$COVERAGE_INFO"
fi
- name: Upload runtime coverage to Codecov
if: matrix.config.coverage == true
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/${{ matrix.config.buildType }}/runtime.coverage.info
flags: runtime-${{ matrix.config.name }}
fail_ci_if_error: false
#- name: Benchmark
# run: |
# ${{github.workspace}}/install/bin/benchnncase > benchnncase.log
# cat benchnncase.log
- name: Upload nncaseruntime Build Artifact
uses: actions/upload-artifact@v4
with:
name: nncaseruntime-${{matrix.config.name}}
path: ${{github.workspace}}/install
if-no-files-found: error
#- name: Upload nncaseruntime Benchmark
# uses: actions/upload-artifact@v4
# with:
# name: nncaseruntime-benchmark-${{matrix.config.name}}
# path: ${{github.workspace}}/benchnncase.log
# if-no-files-found: error
build-native-runtime-coverage:
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
name: build-runtime-${{matrix.config.name}}
runs-on: ${{matrix.config.os}}
strategy:
fail-fast: false
matrix:
config:
- { name: aarch64-macos-coverage, os: macos-14, buildType: Release, coverage: true, profile: aarch64-macos, arch: arm64, toolchainPrefix: '', toolchainFile: '', gcovTool: llvm-gcov.sh }
- { name: x86_64-linux-coverage, os: ubuntu-24.04, buildType: Release, coverage: true, profile: x86_64-linux, arch: x64, toolchainPrefix: '', toolchainFile: '', gcovTool: gcov-14 }
steps: *native_runtime_steps
build-cross-linux-runtime:
if: ${{ github.event_name != 'schedule' }}
name: build-runtime-${{matrix.config.name}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config:
- { name: riscv64-k230-linux, profile: riscv64-linux, toolchainPrefix: riscv64-unknown-linux-gnu-, toolchainFile: riscv64-unknown-linux_gnu_14.2.0, qemu: qemu-riscv64, loaderArgs: '-cpu;rv64,v=true,Zfh=true,zvfh=true,vlen=128,elen=64,vext_spec=v1.0;-L', conanInstallArgs: '-o "&:k230_runtime=True"', buildType: Release, coverage: false }
steps: &cross_runtime_steps
- uses: actions/checkout@v3
- uses: seanmiddleditch/gha-setup-ninja@master
- name: Cleanup runner
uses: ./.github/actions/cleanup-runner
if: runner.os == 'Linux'
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 16
if: runner.os == 'Linux'
- name: Install coverage tools
if: matrix.config.coverage == true
run: |
sudo apt-get update
sudo apt-get install -y lcov
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install toolchain and QEMU
shell: bash
run: |
wget https://dav.sunnycase.moe/d/ci/nncase/${{matrix.config.toolchainFile}}.tar.zst -O toolchain.tar.zst
sudo apt install zstd
sudo tar -I zstd -xf toolchain.tar.zst -C $GITHUB_WORKSPACE
wget https://dav.sunnycase.moe/d/ci/nncase/${{matrix.config.qemu}}.tgz -O qemu.tgz
sudo tar xf qemu.tgz -C /usr/local/bin
sudo chmod a+x /usr/local/bin/${{matrix.config.qemu}}
echo "TESTS_EXECUTABLE_LOADER=${{matrix.config.qemu}}" >> $GITHUB_ENV
echo "TESTS_EXECUTABLE_LOADER_ARGUMENTS=${{matrix.config.loaderArgs}};$GITHUB_WORKSPACE/${{matrix.config.toolchainFile}}/sysroot" >> $GITHUB_ENV
echo "CC=$GITHUB_WORKSPACE/${{matrix.config.toolchainFile}}/bin/${{matrix.config.toolchainPrefix}}gcc" >> $GITHUB_ENV
echo "CXX=$GITHUB_WORKSPACE/${{matrix.config.toolchainFile}}/bin/${{matrix.config.toolchainPrefix}}g++" >> $GITHUB_ENV
- name: Install Conan
run: |
pip install conan==2.6.0
pip install cmake==3.30.3
conan remote add sunnycase https://conan.sunnycase.moe --index 0
conan remote update conancenter --url "https://center2.conan.io"
- name: Configure
shell: bash
env:
COVERAGE: ${{ matrix.config.coverage }}
run: |
conan install . --build=missing -s build_type=${{matrix.config.buildType}} -pr:h=toolchains/${{matrix.config.profile}}.profile.jinja -pr:b=toolchains/x86_64-linux.profile.jinja -o "&:runtime=True" -o "&:python=True" -o "&:tests=True" ${{matrix.config.conanInstallArgs}}
if [ "$COVERAGE" = "true" ]; then
cmake --preset conan-runtime-release \
-DCMAKE_C_FLAGS=--coverage \
-DCMAKE_CXX_FLAGS=--coverage \
-DCMAKE_EXE_LINKER_FLAGS=--coverage
else
cmake --preset conan-runtime-release
fi
- name: Build & Install
run: |
cmake --build build/${{matrix.config.buildType}} --config ${{matrix.config.buildType}}
cmake --install build/${{matrix.config.buildType}} --prefix install
- name: Test
shell: bash
run: |
cd build/${{matrix.config.buildType}}
ctest -C ${{matrix.config.buildType}} --test-dir ntt/test/ctest --output-on-failure -j4
- name: Capture runtime coverage
if: matrix.config.coverage == true
run: |
BUILD_DIR="build/${{ matrix.config.buildType }}"
COVERAGE_RAW="$BUILD_DIR/runtime.coverage.raw.info"
COVERAGE_INFO="$BUILD_DIR/runtime.coverage.info"
GCOV_TOOL="${{ matrix.config.gcovTool }}"
if [ -z "$GCOV_TOOL" ] && [ -n "${{ matrix.config.toolchainPrefix }}" ]; then
GCOV_TOOL="$GITHUB_WORKSPACE/${{ matrix.config.toolchainFile }}/bin/${{ matrix.config.toolchainPrefix }}gcov"
fi
if [ -n "$GCOV_TOOL" ]; then
if [[ "$GCOV_TOOL" != /* ]] && [ -f "$GITHUB_WORKSPACE/$GCOV_TOOL" ]; then
GCOV_TOOL="$GITHUB_WORKSPACE/$GCOV_TOOL"
fi
GCOV_ARG="--gcov-tool $GCOV_TOOL"
fi
LCOV_IGNORE_LIST="mismatch,inconsistent,format,unsupported,unused,corrupt,negative"
if [ "$RUNNER_OS" = "macOS" ]; then
LCOV_IGNORE_LIST="$LCOV_IGNORE_LIST,range"
fi
LCOV_IGNORE="--ignore-errors $LCOV_IGNORE_LIST"
lcov ${GCOV_ARG:-} $LCOV_IGNORE --capture --directory "$BUILD_DIR" --output-file "$COVERAGE_RAW"
lcov $LCOV_IGNORE --remove "$COVERAGE_RAW" '/usr/*' 'ntt/test/*' '/opt/hostedtoolcache/*' '*/.conan2/*' --output-file "$COVERAGE_INFO"
lcov $LCOV_IGNORE --summary "$COVERAGE_INFO"
- name: Upload nncaseruntime Build Artifact
uses: actions/upload-artifact@v4
with:
name: nncaseruntime-${{matrix.config.name}}
path: ${{github.workspace}}/install
if-no-files-found: error
- name: Upload runtime coverage to Codecov
if: matrix.config.coverage == true
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/${{ matrix.config.buildType }}/runtime.coverage.info
flags: runtime-${{ matrix.config.name }}
fail_ci_if_error: false
build-cross-linux-runtime-coverage:
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
name: build-runtime-${{matrix.config.name}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config:
- { name: riscv64-k230-linux-coverage, profile: riscv64-linux, toolchainPrefix: riscv64-unknown-linux-gnu-, toolchainFile: riscv64-unknown-linux_gnu_14.2.0, qemu: qemu-riscv64, loaderArgs: '-cpu;rv64,v=true,Zfh=true,zvfh=true,vlen=128,elen=64,vext_spec=v1.0;-L', conanInstallArgs: '-o "&:k230_runtime=True"', buildType: Release, coverage: true }
steps: *cross_runtime_steps